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

Adding HARK-SSJ-notebook [WIP] #1424

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Adding HARK-SSJ-notebook [WIP] #1424

wants to merge 4 commits into from

Conversation

wdu9
Copy link
Collaborator

@wdu9 wdu9 commented May 7, 2024

Please ensure your pull request adheres to the following guidelines:

  • Tests for new functionality/models or Tests to reproduce the bug-fix in code.
  • Updated documentation of features that add new functionality.
  • Update CHANGELOG.md with major/minor changes.

The notebook "KS-HARK-presentation-notebook.ipynb" in the folder that was added to examples does not work with any version of HARK that can be pip installed.

The notebook instead calls on the a local version of HARK that is closest to econ-ark==0.13.0

With econ-ark==0.13.0, the notebook will not produce any errors but there will be a bug in the computation in the Jacobians as well as the steady state values of aggregate consumption.

@wdu9 wdu9 changed the title Adding HARK-SSJ-notebook Adding HARK-SSJ-notebook [WIP] May 7, 2024
@llorracc
Copy link
Collaborator

@mnwhite can you help Will get this over the finish line?

@mnwhite
Copy link
Contributor

mnwhite commented May 16, 2024

I'm very confused about what this PR represents. There is one commit, which adds 113,000 lines of code across 111 files. The original post doesn't say what it does or what it's supposed to do, just refers to one added notebook that doesn't work with HARK. I can work with Will, but I don't know what this is, what the goal is, what changes were made to the local version of HARK (and why), etc.

@wdu9
Copy link
Collaborator Author

wdu9 commented May 16, 2024

@mnwhite I was instructed to make a pull request that adds a notebook I created over a year ago that had demonstrated how HARK can be connected to SSJ. The original notebook was intended for expositional purposes and I had altered my local version of HARK to allow it to solve a simple HANK model.

The notebook is 'KS-HARK-presentation-notebook.ipynb' can be found in a folder named 'HARK-SSJ-Example' in the 'examples' module. It runs on an altered version of the ConsIndShockModel named 'ConsIndShockModel_HANK.py'.

From what I can recall, 'ConsIndShockModel_HANK.py' differs from the standard ConsIndShockModel.py by adding new distribution engines that multiplies the income shock process by a function that takes in inputs that can later be shocked with the calc_jacobian method. To clarify, income is now y_{it} = p_{it} \theta_{it} func(X) where X could be equal to a tuple (wage,tax) and func(X) = (1-tax)*wage. You can specify this func(X) in the code and it will then allow for the computation of jacobians to the wage or to taxes.

The current issue is that the notebook can run perfectly only with the local version of HARK in the 'HARK-SSJ-Example' folder.

The notebook can be run with HARK 0.13.0 but it will produce the wrong results. For all other versions of HARK, the notebook does not run.

Alan's best guess is that the local version of HARK in the 'HARK-SSJ-Example' folder for which it works is somewhere between 0.13.0 and 0.14.0.

Whatever the bug is is causing the transition matrix simulation of aggregate consumption to be off by 1e-1 which is also causing the Jacobians to be incorrect. My guess is that maybe the formulation of distribution engines has changed? Or

If the transition matrix code or calc_jacobian method is the problem then that would have showed up on the checks.

@wdu9
Copy link
Collaborator Author

wdu9 commented May 16, 2024

@mnwhite Actually I think the bug for why HARK 0.13.0 has to do the with specification of how much wealth is given to newborns. I will look into this issue this weekend.

No matter that bug, the notebook still does not run with HARK 0.14.0 . Not sure if you have any thoughts on that end.

@mnwhite
Copy link
Contributor

mnwhite commented May 16, 2024 via email

@llorracc
Copy link
Collaborator

llorracc commented May 16, 2024 via email

@wdu9
Copy link
Collaborator Author

wdu9 commented May 16, 2024

Yes that is correct. I know that the function 'gen_tran_matrix_1D' in the utilities.py file has a slight difference and I believe this may be causing the bug when running the notebook with HARK 0.13.0, but it would not explain why the notebook breaks with HARK 0.14.0

I don't think much else of the local HARK folder has been altered (but I don't recall perfectly). That is why I defined the new ConsIndShockModel_HANK.py, to try to keep the changes self contained in that file.

@mnwhite
Copy link
Contributor

mnwhite commented May 16, 2024

I agree with Chris. We need to figure out what you did. Did you do the work for this in your own fork of HARK, making commits as you went?

@wdu9
Copy link
Collaborator Author

wdu9 commented May 16, 2024

So, when it worked for Haruki and the students in my class, that was because they had pulled in an entire proprietary WDu version of HARK?

Yes. Although, I think I figured out what is causing the bug in 0.13.0 and will get back to you on this by Monday.

I agree with Chris. We need to figure out what you did. Did you do the work for this in your own fork of HARK, making commits as you went?

No, I did this all locally. It was quickly put together with some tools I had locally.

@mnwhite
Copy link
Contributor

mnwhite commented May 17, 2024

That's going to make this significantly harder. The calc_jacobian function was already a source of headaches while updating HARK. I eventually tracked down what was going on, and you / whoever wrote it did something very unexpected. If there are additional changes on top of that, and there's no record of the change or known starting point, it's going to be difficult to figure out what's going on.

@wdu9
Copy link
Collaborator Author

wdu9 commented May 18, 2024

@llorracc @mnwhite Fixed a major bug in the notebook.
The HARK-SSJ notebook now runs with 0.13.0 with the answers being 98% correct. I deleted the local HARK file in the folder so that is not relevant anymore.

The Jacobians look great, the impulse responses look great, the goods market clears to a magnitude of 1e-5 in the impulse responses however the goods market in steady state is off by 2.5% (goods_mkt is 2.5e-2 instead of 1e-9).

The reason why is because I assume newborns receive no wealth whatsoever and this is not accounted for in the difference equations in the notebook. This assumption is convenient for purposes I will explain to Chris in my next meeting with him.

To fix this bug, it is a one line change in the notebook somewhere.

Chris, I'll discuss with you on the this tiny issue Friday.

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.

None yet

4 participants