PSLmodels / OG-Core

An overlapping generations model framework for evaluating fiscal policies.
https://pslmodels.github.io/OG-Core/
Creative Commons Zero v1.0 Universal
68 stars 119 forks source link

Parameterize adjustments to baseline spending levels in reform policy #987

Closed jdebacker closed 1 month ago

jdebacker commented 2 months ago

This PR adds three new parameters to apply a proportional change to the baseline spending levels for non-pension transfers, government consumption expenditures, and infrastructure spending. These parameters are alpha_bs_T, alpha_bs_G, and alpha_bs_I, respectively.

Note that government consumption expenditures are only held at a level relative to the baseline level up until the time period the long run budget closure rule kicks in. At that point onward, government consumption expenditures are determined by the closure rule.

Addresses Issue #983.

codecov-commenter commented 2 months ago

Codecov Report

Attention: Patch coverage is 52.63158% with 18 lines in your changes missing coverage. Please review.

Project coverage is 70.12%. Comparing base (4b32ef3) to head (4137152). Report is 30 commits behind head on master.

Files with missing lines Patch % Lines
ogcore/SS.py 52.63% 9 Missing :warning:
ogcore/TPI.py 0.00% 8 Missing :warning:
ogcore/fiscal.py 90.00% 1 Missing :warning:
Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/PSLmodels/OG-Core/pull/987/graphs/tree.svg?width=650&height=150&src=pr&token=98mQCVhspd&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PSLmodels)](https://app.codecov.io/gh/PSLmodels/OG-Core/pull/987?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PSLmodels) ```diff @@ Coverage Diff @@ ## master #987 +/- ## ========================================== - Coverage 70.14% 70.12% -0.03% ========================================== Files 20 20 Lines 5038 5047 +9 ========================================== + Hits 3534 3539 +5 - Misses 1504 1508 +4 ``` | [Flag](https://app.codecov.io/gh/PSLmodels/OG-Core/pull/987/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PSLmodels) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/PSLmodels/OG-Core/pull/987/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PSLmodels) | `70.12% <52.63%> (-0.03%)` | :arrow_down: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PSLmodels#carryforward-flags-in-the-pull-request-comment) to find out more. | [Files with missing lines](https://app.codecov.io/gh/PSLmodels/OG-Core/pull/987?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PSLmodels) | Coverage Δ | | |---|---|---| | [ogcore/\_\_init\_\_.py](https://app.codecov.io/gh/PSLmodels/OG-Core/pull/987?src=pr&el=tree&filepath=ogcore%2F__init__.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PSLmodels#diff-b2djb3JlL19faW5pdF9fLnB5) | `100.00% <100.00%> (ø)` | | | [ogcore/parameters.py](https://app.codecov.io/gh/PSLmodels/OG-Core/pull/987?src=pr&el=tree&filepath=ogcore%2Fparameters.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PSLmodels#diff-b2djb3JlL3BhcmFtZXRlcnMucHk=) | `83.12% <ø> (ø)` | | | [ogcore/fiscal.py](https://app.codecov.io/gh/PSLmodels/OG-Core/pull/987?src=pr&el=tree&filepath=ogcore%2Ffiscal.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PSLmodels#diff-b2djb3JlL2Zpc2NhbC5weQ==) | `97.87% <90.00%> (-1.00%)` | :arrow_down: | | [ogcore/TPI.py](https://app.codecov.io/gh/PSLmodels/OG-Core/pull/987?src=pr&el=tree&filepath=ogcore%2FTPI.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PSLmodels#diff-b2djb3JlL1RQSS5weQ==) | `36.54% <0.00%> (+0.09%)` | :arrow_up: | | [ogcore/SS.py](https://app.codecov.io/gh/PSLmodels/OG-Core/pull/987?src=pr&el=tree&filepath=ogcore%2FSS.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PSLmodels#diff-b2djb3JlL1NTLnB5) | `71.84% <52.63%> (-0.65%)` | :arrow_down: |
jdebacker commented 2 months ago

Added [WIP] to title as still working on some local only tests. Will remove when they are satisfied.

rickecon commented 2 months ago

@jdebacker. For GH Actions tests, this PR just needs the make format command. Merging PR #971 might fix some of the local tests that are failing (see this comment).

towashington commented 2 months ago

Thanks, @jdebacker, @rickecon. Looking forward to using this parameter.

Is it in the road map to have this included in the next OG-Core release so the functionality can be invoked from inside OG-USA?

rickecon commented 2 months ago

@towashington. Yes. This parameter will be able to be used in OG-USA as soon as this is incorporated into OG-Core. @jdebacker, the code looks good to me. You just need to run make format from the ogcore-dev conda environment. Then let me know when the local tests are passing.

jdebacker commented 2 months ago

I've updated docs and this PR is compete. I will run the full suite of local tests when I have power and report results back here.

rickecon commented 2 months ago

@jdebacker. I have gone through the code changes and approved them. The only further updates this PR needs are:

rickecon commented 1 month ago

@jdebacker. I ran all the local tests using your branch, and I got one failure on the last test of test_TPI.py, test_run_TPI_extra[Baseline, Kg>0]. The assert at the end was false. The traceback shows that the error was in the first set of asserts, and it looks like it is the B object (see traceback output summary below).

(ogcore-dev) richardevans@Richards-MacBook-Pro-2 OG-Core % pytest
============================= test session starts ==============================
platform darwin -- Python 3.12.6, pytest-8.3.3, pluggy-1.5.0
rootdir: /Users/richardevans/Docs/Economics/OSE/OG/OG-Core
configfile: pytest.ini
testpaths: ./tests
plugins: cov-5.0.0, anyio-4.6.0, xdist-3.6.1
collected 583 items                                                            

tests/test_SS.py ...................................                     [  6%]
tests/test_TPI.py ..........................F                            [ 10%]
tests/test_aggregates.py ........................................        [ 17%]
tests/test_basic.py ....                                                 [ 18%]
tests/test_demographics.py ................                              [ 20%]
tests/test_elliptical_u_est.py .......                                   [ 22%]
tests/test_execute.py .                                                  [ 22%]
tests/test_firm.py ..................................................... [ 31%]
................                                                         [ 34%]
tests/test_fiscal.py ......................                              [ 37%]
tests/test_household.py ................................................ [ 46%]
..                                                                       [ 46%]
tests/test_output_plots.py ............................................. [ 54%]
..                                                                       [ 54%]
tests/test_output_tables.py ..............                               [ 56%]
tests/test_parameter_plots.py ........................................   [ 63%]
tests/test_parameter_tables.py .......                                   [ 65%]
tests/test_parameters.py ..............                                  [ 67%]
tests/test_pensions.py ...............................                   [ 72%]
tests/test_run_example.py ..                                             [ 73%]
tests/test_run_ogcore.py .                                               [ 73%]
tests/test_tax.py .................................                      [ 78%]
tests/test_txfunc.py ...............................                     [ 84%]
tests/test_user_inputs.py .........                                      [ 85%]
tests/test_utils.py .................................................... [ 94%]
...............................                                          [100%]
______________________ test_run_TPI_extra[Baseline, Kg>0] ______________________
...
        for k, v in expected_dict.items():
            print("Checking ", k)
            try:
                print("Diff = ", np.absolute(test_dict[k][: p.T] - v[: p.T]).max())
>               assert np.allclose(
                    test_dict[k][: p.T], v[: p.T], rtol=1e-04, atol=1e-04
                )
E               assert False
E                +  where False = <function allclose at 0x111a7d970>(array([1.71272101, 1.72938281, 1.73864551, 1.72746434, 1.72145683,\n       1.71792535, 1.71655697, 1.71596647, 1.715334...32, 1.70702823, 1.70733347, 1.70764059, 1.70795034,\n       1.70826377, 1.70858234, 1.70890801, 1.70924351, 1.70959245]), array([1.71272101, 1.72938489, 1.73865549, 1.72748815, 1.72148578,\n       1.71794852, 1.71656468, 1.71595132, 1.715292...2 , 1.7070529 , 1.70735795, 1.70766489, 1.70797448,\n       1.70828778, 1.70860625, 1.70893187, 1.70926737, 1.70961641]), rtol=0.0001, atol=0.0001)
E                +    where <function allclose at 0x111a7d970> = np.allclose
----------------------------- Captured stdout call -----------------------------

...
Iteration: 2
    Distance: 0.4542793707203373
Max absolute value resource constraint error: 0.023755596502261347
Checking time path for violations of constraints.
Max Euler error, savings:  2.3789858971667854e-12
Max Euler error labor supply:  1.7177370637000422e-12
Checking  Y
Diff =  1.2723227424960015e-05
Checking  B
Diff =  0.00030070629741585364
=========================== short test summary info ============================
FAILED tests/test_TPI.py::test_run_TPI_extra[Baseline, Kg>0] - assert False
========= 1 failed, 582 passed, 16753 warnings in 44007.79s (12:13:27) =========
jdebacker commented 1 month ago

@rickecon All local tests are now passing. The failure in tests/test_TPI.py::test_run_TPI_extra[Baseline, Kg>0] was due to a change in the initial value of I_g going into the transition path. Since this tests only runs TPI for two iterations, changes in the initial value can still be having an effect. The test tests/test_TPI.py::test_run_TPI_full_run[Baseline, Kg>0] uses the same parameterization, but fully solves for the equilibrium transition path and this test was unaffected by the changes in the code.

To make sure tests/test_TPI.py::test_run_TPI_extra[Baseline, Kg>0] passes, I saved a new pickle file representing the expected results given the new initial guess for I_g.

rickecon commented 1 month ago

@jdebacker. All local tests pass on my machine (I only checked test_tpy.py::test_run_TPI_extra). I am now just waiting to get all the CI tests to pass. I am doing them one-by-one. This is frustrating when the CI tests don't just run automatically. But I will merge this as soon as I get all the tests to pass on GH Actions.

rickecon commented 1 month ago

@jdebacker. Thanks for this. All is good. Merging now.