Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New model: Labor supply on intensive margin #509

Merged
merged 24 commits into from
Feb 26, 2020
Merged

New model: Labor supply on intensive margin #509

merged 24 commits into from
Feb 26, 2020

Conversation

mnwhite
Copy link
Contributor

@mnwhite mnwhite commented Feb 10, 2020

This PR provides a new model for HARK, in which agents make both a consumption-saving decisions and a (continuous) labor-leisure decision. Agents observe their permanent and transitory productivity shocks before deciding how much labor to supply each period, so TranShk is a second state variable. Utility function has a Cobb-Douglas-like aggregator for leisure and consumption under a single CRRA term.

Most model code was written by Tiphanie Magne in 2017, with some cleanup by me in 2019 and then a bit more by Jack Shiqi Li.

I could swear this was merged into master months ago, but apparently not.

mnwhite and others added 11 commits August 29, 2019 15:29
This commit is mostly a copy-paste of files that had been sitting in my student submission folder for literally two years.  Most of the programming here was done by Tiphanie Magne as a course project in spring/summer 2017, with some assistance from me. (TODO: Make sure she gets tagged/credited on the PR for this branch.)  I dropped in the files as they were on my computer, changed the HARK package names (the work predated that), and it ran successfully.

Still to do: Clean up some comments and documentation, add life cycle example, make sure simulation exists (and works), move example parameter dictionary into ConsumerParameters.py (from blahblahTM.py).
Added/edited various solver comments and changed a few variable names.  Also changed aXtraMax in parameters, which reveals that the "negative labor" problem is handled correctly in the solver... but it can still *extrapolate* to negative labor.
Did this work several days ago, forgot to commit.  Rest of comments and docstrings in file still need to be gone over.
Finished moving example parameters from ConsumerParametersTM.py into ConsumerParameters.py, and deleting ConsumerParametersTM.py.
Finished adding lifecycle example into main block (Just took the lifecycle example from ConsIndShockModel, as what I have interpreted).
Some attempts on fixing the simulation for the labor model, it works as it does simulate some results, but I do not know how to test whether it is correct or not.
…nderstand the getControls() method and the consumption function in the Labor model, but the plot seems to make sense, please review on this.

I am pretty certain that the ConsumerParameters.py file is fine.
…r intensive margin consumer.

But for some unknown reason, it does not allow me to set T_retire above 0.
If T_retire is set, then there is an IndexError at line 774 in interpolation.py.
After tracking of the error, I suspect that something is messed up in the process of passing bNrmGrid_rep into Interpolation.LinearInterp._eval0rder.
If I set T_retire = 0, the print of length of bNrmGrid_rep and x_list in _eval0rder is 200, 201, 200, 16.
If I set T_retire > 0, the print of length of bNrmGrid_rep and x_list in _eval0rder is 200, 201, 200, 1.
However, I cannot identify why T_retire > 0 gives such a result.
Will continue working on this.
…r a labor intensive margin consumer."

This reverts commit 5820958.
One problem: according to the model name 'endogenous labor', I assume that we should not set a specific retire period for the consumer, everything should be decide by the agent. Furthermore, if I do set a retirement period T_retire for the agent, then lifecycle example gives an IndexError.
After some investigation, I found that the problem reside in line 2328-2337 in ConsIndShockModel, where we handle the IncomeDstnRet if T_retire > 0.
I do not want to touch on that without instruction as it may have big influence.
Lifecycle figures for intensive margin labor model now plot across periods, using the median shock (more or less) rather than across shocks.  These plots now have "nice" xlim and ylim, but infinite horizon figs do not.  We can fix that later.
Adds consumption-saving model with labor supply choice (intensive margin).  Main code written by Tiphanie Magne in summer 2017; cleaned up and prepared for master HARK by Shiqi Li and me.
@sbenthall
Copy link
Contributor

What if, for new Models, rather than putting all the test and demo code into the __main__ method in the model class file, rather:

This has two benefits:

  • the demonstration code would then be available to be ingested into ReadTheDocs
  • the test code would serve as further confirmation of the robustness of the more basic functionality, which would make the library more robust to refactoring, etc.

@mnwhite
Copy link
Contributor Author

mnwhite commented Feb 10, 2020

Yes, that's a better structure. I'll move the code.

Adopted new style of default parameters.
Following new style in Mridul's refactoring PR, moved all of the main block code for ConsLaborModel into a new example file in the appropriate directory.  Also did a bunch of cleanup on simulation methods for the labor model, which were incorrect.
@mnwhite
Copy link
Contributor Author

mnwhite commented Feb 13, 2020

Ok, the main block code has been moved to a new examples file, and tested in place. This revealed a bunch of problems with the code (now fixed), so it was a very good idea.

@sbenthall sbenthall self-assigned this Feb 16, 2020
Copy link
Contributor

@sbenthall sbenthall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See one docstring error.
I see that the example code has moved. I don't see any automated tests.
While that seems standard for HARK, in general when doing code reviews I point out that automated tests are best done when a feature is first committed.


def getControls(self):
'''
Calculates consumption for each consumer of this type using the consumption functions.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this docstring is incorrect. There are more controls than just consumption in this model

@MridulS
Copy link
Member

MridulS commented Feb 16, 2020

for the unit tests in #455 I use ideas from the example and then create incremental unit test. Example: testing one function checkMarkovInputs of MarkovConsumerType https://github.com/econ-ark/HARK/blob/2b99308daabea1dc4c6109509793ddfbbb269068/HARK/ConsumptionSaving/tests/test_ConsMarkovModel.py

rkcah and others added 3 commits February 16, 2020 20:48
updateLbrCost method didn't work as intended, as LbrCost was an array, not a list; added call to tolist().  Fixed documentation error in a simulation method that someone else flagged.

Also added two line getStates method, which isn't strictly necessary.  Inherited method calculates mNrm "prematurely", which is then overwritten by a later sim method in this model.  New getStates method simply "erases" that premature calculation.
@mnwhite
Copy link
Contributor Author

mnwhite commented Feb 16, 2020

I fixed that docstring error just now (thanks). I've never made automated tests before; I'll try to get around to figuring out how to do that and put them in here.

@sbenthall
Copy link
Contributor

@mnwhite I'd be happy to do a quick call with you some time about automated tests!
we could even pair code it (remote) if you had the time for it.

mnwhite and others added 2 commits February 18, 2020 14:23
Changed some division symbols to correctly use integer division, and adjusted lifecycle example dictionary.
@sbenthall
Copy link
Contributor

Shall I merge this in? It's better if there are tests, but there is no such general policy requiring tests on PRs at this point, as far as I know.
If this feature is needed downstream, might as well merge it.
My offer to walk you through automated testing stands, any time you've got time.

@sbenthall sbenthall merged commit 3d3dbfe into master Feb 26, 2020
@mnwhite
Copy link
Contributor Author

mnwhite commented Feb 26, 2020 via email

@mnwhite mnwhite deleted the LaborIntMarg branch March 5, 2020 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants