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

Add reverse operator #790

Merged
merged 8 commits into from Jan 5, 2018
Merged

Add reverse operator #790

merged 8 commits into from Jan 5, 2018

Conversation

hdoupe
Copy link
Collaborator

@hdoupe hdoupe commented Dec 22, 2017

This PR adds the reverse operator discussed in issue #763.

Basic rules as described in this comment in #763 :

I think we should impose some strict rules on how this symbol can be used so that we can keep everything simple.

  1. It can only be used at the beginning of the string.
  2. It can only send a parameter back one year (this rule could be relaxed fairly easily)

For example, if you set the start year as 2018 and the cpi_offset parameter to "<,-0.0025", then this sets the cpi_offset to -0.0025 in 2017.

@hdoupe
Copy link
Collaborator Author

hdoupe commented Dec 22, 2017

PR #790 is on the test app.

@MattHJensen
Copy link
Contributor

MattHJensen commented Dec 22, 2017

@hdoupe, I got a value error running the example you gave.

Also noticed that we should add a user tip before the "Read the Docs" Bullet. Something like, "You may specify a parameter change in the year before the Start Year with the > operator. For example, if you set the Start Year as 2018 and a Parameter Indexing Offset parameter to <,-0.0025, then this sets the Offset to -0.0025 in 2017."

@hdoupe
Copy link
Collaborator Author

hdoupe commented Dec 22, 2017

Thanks for the bug report. The most recent commit resolves the issue. That error should only affect the edit page.

@hdoupe
Copy link
Collaborator Author

hdoupe commented Dec 22, 2017

Also noticed that we should add a user tip before the "Read the Docs" Bullet. Something like, "You may specify a parameter change in the year before the Start Year with the > operator. For example, if you set the Start Year as 2018 and a Parameter Indexing Offset parameter to <,-0.0025, then this sets the Offset to -0.0025 in 2017."

Good idea. Yes, I agree. I'll add something along those lines.

@hdoupe
Copy link
Collaborator Author

hdoupe commented Dec 22, 2017

Changes up to Add reverse operator instructions are on the test app.

@MattHJensen
Copy link
Contributor

@hdoupe, I would expect to see a change in results in 2017 with this reform: http://ospc-taxes7.herokuapp.com/taxbrain/1494/.

@MattHJensen
Copy link
Contributor

^^ Interestingly, the reverse operator does appear to be working in other contexts based on the differences in 2017 between http://ospc-taxes7.herokuapp.com/taxbrain/1498/ and http://ospc-taxes7.herokuapp.com/taxbrain/1499/.

@hdoupe
Copy link
Collaborator Author

hdoupe commented Dec 23, 2017

@MattHJensen Ok, I submitted the parameters from your reform (+ set FICA_ss_trt to 0.78 so I could identify the run) and dug out the keywords to dropq:

{'behavior': {},
 'consumption': {},
 'growdiff_baseline': {},
 'growdiff_response': {},
 'policy': {'2016': {'_cpi_offset': [-0.005]},
  '2017': {'_ALD_InvInc_ec_base_RyanBrady': [False],
   '_CG_nodiff': [False],
   '_CTC_new_for_all': [False],
   '_CTC_new_refund_limited': [False],
   '_CTC_new_refund_limited_all_payroll': [False],
   '_EITC_indiv': [False],
   '_FICA_ss_trt': [0.78],
   '_ID_AmountCap_Switch': [[1, 1, 1, 1, 1, 1, 1]],
   '_ID_BenefitCap_Switch': [[1, 1, 1, 1, 1, 1, 1]],
   '_ID_BenefitSurtax_Switch': [[1, 1, 1, 1, 1, 1, 1]],
   '_II_no_em_nu18': [False],
   '_NIIT_PT_taxed': [False],
   '_PT_top_stacking': [True],
   '_PT_wages_active_income': [False]},
  '2018': {'_DependentCredit_before_CTC': [True]}}}

It looks like everything is passed to Tax-Calculator correctly. Have you checked the results using Tax-Calculator directly?

@hdoupe
Copy link
Collaborator Author

hdoupe commented Dec 23, 2017

Here are the input and output from doing run using the edit parameters page created fromhttp://ospc-taxes7.herokuapp.com/taxbrain/1494/:

{'start_year': 2017,
 'use_full_sample': True,
 'use_puf_not_cps': True,
 'user_mods': {'behavior': {},
  'consumption': {},
  'growdiff_baseline': {},
  'growdiff_response': {},
  'policy': {2016: {'_cpi_offset': [-0.005]},
   2017: {'_ALD_InvInc_ec_base_RyanBrady': [False],
    '_CG_nodiff': [False],
    '_CTC_new_for_all': [False],
    '_CTC_new_refund_limited': [False],
    '_CTC_new_refund_limited_all_payroll': [False],
    '_EITC_indiv': [False],
    '_ID_AmountCap_Switch': [[1, 1, 1, 1, 1, 1, 1]],
    '_ID_BenefitCap_Switch': [[1, 1, 1, 1, 1, 1, 1]],
    '_ID_BenefitSurtax_Switch': [[1, 1, 1, 1, 1, 1, 1]],
    '_II_no_em_nu18': [False],
    '_NIIT_PT_taxed': [False],
    '_PT_top_stacking': [True],
    '_PT_wages_active_income': [False]},
   2018: {'_DependentCredit_before_CTC': [True]}}},
 'year_n': 8}

http://ospc-taxes7.herokuapp.com/taxbrain/1501/

They look the same. Maybe the magnitude change is just really small?

@MattHJensen
Copy link
Contributor

Ok, the right way to test would be to just run the reform through tc CLI and see if the 2017 change is small, but I'm not in a position to do so at the moment.

@hdoupe
Copy link
Collaborator Author

hdoupe commented Dec 23, 2017

Ok, good idea. Here are the results:

(taxcalc-dev) HDoupe-MacBook-Pro:Tax-Calculator henrydoupe$ cat taxcalc/reforms/matt_test.json 
{
    "policy": {
        "_cpi_offset": {"2016": [-0.005]},
        "_ALD_InvInc_ec_base_RyanBrady": {"2017": [false]},
        "_CG_nodiff": {"2017": [false]},
        "_CTC_new_for_all": {"2017": [false]},
        "_CTC_new_refund_limited": {"2017": [false]},
        "_CTC_new_refund_limited_all_payroll": {"2017": [false]},
        "_EITC_indiv": {"2017": [false]},
        "_ID_AmountCap_Switch": {"2017": [[1, 1, 1, 1, 1, 1, 1]]},
        "_ID_BenefitCap_Switch": {"2017": [[1, 1, 1, 1, 1, 1, 1]]},
        "_ID_BenefitSurtax_Switch": {"2017": [[1, 1, 1, 1, 1, 1, 1]]},
        "_II_no_em_nu18": {"2017": [false]},
        "_NIIT_PT_taxed": {"2017": [false]},
        "_PT_top_stacking": {"2017": [true]},
        "_PT_wages_active_income": {"2017":[false]},
        "_DependentCredit_before_CTC": {"2018":[true]}
    }
}
(taxcalc-dev) HDoupe-MacBook-Pro:Tax-Calculator henrydoupe$ tc puf.csv 2017 --reform taxcalc/reforms/matt_test.json --tables
You loaded data for 2009.
Tax-Calculator startup automatically extrapolated your data to 2017.
(taxcalc-dev) HDoupe-MacBook-Pro:Tax-Calculator henrydoupe$ cat puf-17-matt_test-#-tab.text
Weighted Tax Reform Totals by Baseline Expanded-Income Decile
    Returns    ExpInc    IncTax    PayTax     LSTax    AllTax
       (#m)      ($b)      ($b)      ($b)      ($b)      ($b)
 0    17.00    -119.5      -2.6       6.5       0.0       3.9
 1    17.01     152.8     -12.0      14.4       0.0       2.4
 2    17.00     274.1     -24.9      24.5       0.0      -0.4
 3    17.01     401.0     -17.4      35.7       0.0      18.4
 4    17.01     558.9      -0.8      52.7       0.0      51.9
 5    17.01     755.1      26.6      72.3       0.0      98.8
 6    17.01    1010.6      61.4      97.0       0.0     158.4
 7    17.01    1382.0     116.8     143.2       0.0     260.0
 8    17.01    2058.9     215.9     234.2       0.0     450.1
 9    17.01    6325.0    1357.9     412.0       0.0    1770.0
 A   170.05   12799.0    1721.0    1092.5       0.0    2813.6

Weighted Tax Differences by Baseline Expanded-Income Decile
    Returns    ExpInc    IncTax    PayTax     LSTax    AllTax
       (#m)      ($b)      ($b)      ($b)      ($b)      ($b)
 0    17.00    -119.5       0.0       0.0       0.0       0.0
 1    17.01     152.8       0.0       0.0       0.0       0.0
 2    17.00     274.1       0.0       0.0       0.0       0.0
 3    17.01     401.0       0.0       0.0       0.0       0.0
 4    17.01     558.9       0.0       0.0       0.0       0.0
 5    17.01     755.1       0.0       0.0       0.0       0.0
 6    17.01    1010.6       0.0       0.0       0.0       0.0
 7    17.01    1382.0       0.0       0.0       0.0       0.0
 8    17.01    2058.9       0.0       0.0       0.0       0.0
 9    17.01    6325.0       0.0       0.0       0.0       0.0
 A   170.05   12799.0       0.0       0.0       0.0       0.0
(taxcalc-dev) HDoupe-MacBook-Pro:Tax-Calculator henrydoupe$ tc puf.csv 2018 --reform taxcalc/reforms/matt_test.json --tables
You loaded data for 2009.
Tax-Calculator startup automatically extrapolated your data to 2018.
(taxcalc-dev) HDoupe-MacBook-Pro:Tax-Calculator henrydoupe$ cat puf-18-matt_test-#-tab.text
Weighted Tax Reform Totals by Baseline Expanded-Income Decile
    Returns    ExpInc    IncTax    PayTax     LSTax    AllTax
       (#m)      ($b)      ($b)      ($b)      ($b)      ($b)
 0    17.28    -122.5      -2.7       6.7       0.0       4.0
 1    17.28     158.8     -12.3      14.8       0.0       2.5
 2    17.29     286.0     -25.5      25.4       0.0      -0.1
 3    17.29     418.0     -17.1      36.8       0.0      19.7
 4    17.29     583.7       0.1      54.8       0.0      54.9
 5    17.29     789.0      29.0      74.7       0.0     103.7
 6    17.29    1055.9      65.4     101.0       0.0     166.4
 7    17.29    1444.0     123.7     149.2       0.0     272.9
 8    17.29    2154.1     229.1     244.5       0.0     473.6
 9    17.29    6574.2    1410.5     434.0       0.0    1844.5
 A   172.86   13341.0    1800.3    1141.8       0.0    2942.1

Weighted Tax Differences by Baseline Expanded-Income Decile
    Returns    ExpInc    IncTax    PayTax     LSTax    AllTax
       (#m)      ($b)      ($b)      ($b)      ($b)      ($b)
 0    17.28    -122.5       0.0       0.0       0.0       0.0
 1    17.28     158.8       0.0       0.0       0.0       0.0
 2    17.29     286.0       0.1       0.0       0.0       0.1
 3    17.29     418.0       0.2       0.0       0.0       0.2
 4    17.29     583.7       0.3       0.0       0.0       0.3
 5    17.29     789.0       0.3       0.0       0.0       0.3
 6    17.29    1055.9       0.4       0.0       0.0       0.4
 7    17.29    1444.0       0.4       0.0       0.0       0.4
 8    17.29    2154.1       0.8       0.0       0.0       0.8
 9    17.29    6574.2       1.9       0.0       0.0       1.9
 A   172.86   13341.0       4.5       0.0       0.0       4.5
(taxcalc-dev) HDoupe-MacBook-Pro:Tax-Calculator henrydoupe$ 

Looks good to me.

@MattHJensen
Copy link
Contributor

MattHJensen commented Dec 23, 2017

@hdoupe, @martinholmer, am I right to think that this ^^ might indicate a bug in Tax-Calculator? I would have thought that the weighted difference table for 2017 should show a positive value in the AllTax column (and some others) because of the "_cpi_offset": {"2016": [-0.005]},

@MattHJensen
Copy link
Contributor

@hdoupe, it does seem like this PR has PolicyBrain accurately reflecting the results from Tax-Calculator, even if those results don't currently make sense to me.

@hdoupe
Copy link
Collaborator Author

hdoupe commented Dec 23, 2017

@MattHJensen asked

am I right to think that this ^^ might indicate a bug in Tax-Calculator? I would have thought that the weighted difference table for 2017 should show a positive value in the AllTax column (and some others) because of the "_cpi_offset": {"2016": [-0.005]},

I'm not sure. I ran another reform where I only changed the cpi_offset parameter, and there isn't any change in revenue in 2017. From 2018 to 2019, the difference between the changes is about $2 billion followed by a $2.6 change from 2019 to 2020. This pattern carries on until 2027. So, perhaps, the change in revenue is negligible at the beginning. Then, the changes grow over time and become more noticeable.

http://ospc-taxes7.herokuapp.com/taxbrain/1503/

@hdoupe
Copy link
Collaborator Author

hdoupe commented Dec 23, 2017

@MattHJensen said:

it does seem like this PR has PolicyBrain accurately reflecting the results from Tax-Calculator, even if those results don't currently make sense to me.

Ok, thanks for the thorough review.

@martinholmer
Copy link
Contributor

martinholmer commented Dec 23, 2017

@MattHJensen and @hdoupe, the following results should help clear up the mystery in #790.

Here is a simple Python script:

iMac2:tax-calculator mrh$ cat chained_cpi.py
from __future__ import print_function
from taxcalc import *

policy1 = Policy()

policy2 = Policy()
ref = {2015: {'_cpi_offset': [-0.005]}}
print(ref)
policy2.implement_reform(ref)
if policy2.reform_errors:
    print(policy2.reform_errors)
    exit(1)

print('YEAR  EXMP1  EXMP2')
res = '{}  {:.0f}   {:.0f}'
syr = Policy.JSON_START_YEAR
for cyr in range(2014, 2026):
    policy1.set_year(cyr)
    policy2.set_year(cyr)
    print(res.format(cyr, policy1.II_em, policy2.II_em))

exit(0)

If we execute that script, we get these results:

iMac2:tax-calculator mrh$ python chained_cpi.py
{2015: {'_cpi_offset': [-0.005]}}
YEAR  EXMP1  EXMP2
2014  3950   3950
2015  4000   4000
2016  4050   4050
2017  4050   4050
2018  4141   4121
2019  4234   4193
2020  4332   4268
2021  4435   4349
2022  4543   4433
2023  4650   4516
2024  4762   4601
2025  4875   4688

So, why isn't the personal exemption amount under the reform (policy2) lower than under current-law (policy1) beginning in 2016? The answer is because we have known values of _II_em through 2017 (see the user documentation of the personal exemption parameter). The inflation indexing of policy parameters applies only to unknown values of policy parameters, which is the way Tax-Calculator has worked since before I started working on the project.

@GoFroggyRun
Copy link
Contributor

The operator looks good to me +1. Thanks for adding this enhancement @hdoupe.

@MattHJensen
Copy link
Contributor

@martinholmer, thanks very much for the Tax-Calculator illumination. @hdoupe, this looks good to me.

@hdoupe
Copy link
Collaborator Author

hdoupe commented Jan 5, 2018

Thanks for the review @MattHJensen, @martinholmer, and @GoFroggyRun

@hdoupe hdoupe merged commit 2a3cd78 into ospc-org:master Jan 5, 2018
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