Skip to content

Commit

Permalink
Use compound reforms instead of creating separate reforms.
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxGhenis committed Jan 2, 2018
1 parent 2455a85 commit d37bbd9
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 240 deletions.
115 changes: 62 additions & 53 deletions charitable_repeal/Effect of repealing charitable deduction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"\n",
"This identifies beneficiaries of the charitable deduction by modeling its repeal. Both repeal from current (2017) state and TCJA state are considered on a static basis. Change to after-tax income by decile and share of after-tax income held by top 10% are calculated.\n",
"\n",
"*taxcalc version: 0.14.3 | Data: CPS | Tax year: 2018 | Type: Static | Author: Max Ghenis | Date run: 2017-12-30*"
"*taxcalc version: 0.14.3 | Data: CPS | Tax year: 2018 | Type: Static | Author: Max Ghenis | Date run: 2018-01-02*"
]
},
{
Expand All @@ -31,6 +31,7 @@
"from __future__ import print_function # Necessary only if using Python 2.7.\n",
"import taxcalc as tc\n",
"import pandas as pd\n",
"import copy\n",
"import urllib as url_lib # On Python 3.6 use \"import urllib.request as url_lib\"."
]
},
Expand Down Expand Up @@ -61,19 +62,20 @@
"def read_url(url):\n",
" return url_lib.urlopen(url).read()\n",
"\n",
"def read_reform_github(reform_name):\n",
" return read_url(GITHUB_BASE_URL + reform_name + '.json')\n",
"\n",
"def read_reform_taxcalc_github(reform_name):\n",
" return read_url(TAXCALC_GITHUB_BASE_URL + reform_name + '.json')\n",
"\n",
"def create_static_params_github(reform_name):\n",
" return tc.Calculator.read_json_param_objects(\n",
" read_reform_github(reform_name), None)\n",
"def policy_from_reform(reform):\n",
" pol = tc.Policy()\n",
" pol.implement_reform(reform['policy'])\n",
" if pol.reform_errors:\n",
" print(pol.reform_errors)\n",
" return pol\n",
"\n",
"def create_static_params_taxcalc_github(reform_name):\n",
" return tc.Calculator.read_json_param_objects(\n",
" read_reform_taxcalc_github(reform_name), None)"
"def create_static_policy_taxcalc_github(reform_name):\n",
" reform = tc.Calculator.read_json_param_objects(\n",
" read_reform_taxcalc_github(reform_name), None)\n",
" return policy_from_reform(reform)"
]
},
{
Expand All @@ -84,12 +86,21 @@
},
"outputs": [],
"source": [
"no_charitable_reform = create_static_params_github(\n",
" 'MaxGhenis/taxcalc-notebooks/master/charitable_repeal/NoCharitableDeduction')\n",
"tcja_reform = create_static_params_taxcalc_github(\n",
" 'TCJA_Reconciliation')\n",
"tcja_no_charitable_reform = create_static_params_github(\n",
" 'MaxGhenis/taxcalc-notebooks/master/charitable_repeal/TCJA_NoCharitable')"
"tcja_policy = create_static_policy_taxcalc_github(\n",
" 'TCJA_Reconciliation')"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"no_charitable_reform = {2018: {'_ID_Charity_crt_all': [0]}}\n",
"tcja_no_charitable_policy = copy.deepcopy(tcja_policy)\n",
"tcja_no_charitable_policy.implement_reform(no_charitable_reform)\n",
"no_charitable_policy = tc.Policy() # Can't combine with next step.\n",
"no_charitable_policy.implement_reform(no_charitable_reform)"
]
},
{
Expand All @@ -101,16 +112,18 @@
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"execution_count": 5,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"recs = tc.Records.cps_constructor()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 6,
"metadata": {
"collapsed": true
},
Expand All @@ -125,17 +138,13 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 7,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def static_calc_from_reform(reform, year):\n",
" pol = tc.Policy()\n",
" pol.implement_reform(reform['policy'])\n",
" if pol.reform_errors:\n",
" print(pol.reform_errors)\n",
"def static_calc_from_policy(pol, year):\n",
" calc = tc.Calculator(records=recs, policy=pol)\n",
" calc.advance_to_year(year)\n",
" calc.calc_all()\n",
Expand All @@ -145,7 +154,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 8,
"metadata": {},
"outputs": [
{
Expand All @@ -165,9 +174,9 @@
],
"source": [
"baseline_calc = static_baseline_calc(2018)\n",
"no_charitable_calc = static_calc_from_reform(no_charitable_reform, 2018)\n",
"tcja_calc = static_calc_from_reform(tcja_reform, 2018)\n",
"tcja_no_charitable_calc = static_calc_from_reform(tcja_no_charitable_reform, 2018)"
"no_charitable_calc = static_calc_from_policy(no_charitable_policy, 2018)\n",
"tcja_calc = static_calc_from_policy(tcja_policy, 2018)\n",
"tcja_no_charitable_calc = static_calc_from_policy(tcja_no_charitable_policy, 2018)"
]
},
{
Expand All @@ -186,7 +195,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 9,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -218,16 +227,16 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 10,
"metadata": {},
"outputs": [
{
"ename": "ValueError",
"evalue": "Buffer dtype mismatch, expected 'Python object' but got 'long'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
"\u001b[0;31mValueError\u001b[0m: Buffer dtype mismatch, expected 'Python object' but got 'long'"
]
},
Expand All @@ -243,8 +252,8 @@
"evalue": "Buffer dtype mismatch, expected 'Python object' but got 'long'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
"\u001b[0;31mValueError\u001b[0m: Buffer dtype mismatch, expected 'Python object' but got 'long'"
]
},
Expand All @@ -263,7 +272,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 11,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -520,7 +529,7 @@
"13 3,045,122,774.39 6.80 0.29 -0.29 "
]
},
"execution_count": 10,
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -531,7 +540,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 12,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -788,7 +797,7 @@
"13 2,529,410,335.61 11.28 0.23 -0.23 "
]
},
"execution_count": 11,
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -806,7 +815,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 13,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -927,7 +936,7 @@
"13 0.29 0.23"
]
},
"execution_count": 12,
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -957,16 +966,16 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 14,
"metadata": {},
"outputs": [
{
"ename": "ValueError",
"evalue": "Buffer dtype mismatch, expected 'Python object' but got 'long'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
"\u001b[0;31mValueError\u001b[0m: Buffer dtype mismatch, expected 'Python object' but got 'long'"
]
},
Expand All @@ -982,8 +991,8 @@
"evalue": "Buffer dtype mismatch, expected 'Python object' but got 'long'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
"\u001b[0;31mValueError\u001b[0m: Buffer dtype mismatch, expected 'Python object' but got 'long'"
]
},
Expand All @@ -999,8 +1008,8 @@
"evalue": "Buffer dtype mismatch, expected 'Python object' but got 'long'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
"\u001b[0;31mValueError\u001b[0m: Buffer dtype mismatch, expected 'Python object' but got 'long'"
]
},
Expand All @@ -1016,8 +1025,8 @@
"evalue": "Buffer dtype mismatch, expected 'Python object' but got 'long'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
"\u001b[0;31mValueError\u001b[0m: Buffer dtype mismatch, expected 'Python object' but got 'long'"
]
},
Expand All @@ -1036,7 +1045,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 15,
"metadata": {
"collapsed": true
},
Expand All @@ -1048,7 +1057,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 16,
"metadata": {},
"outputs": [
{
Expand All @@ -1073,7 +1082,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 17,
"metadata": {},
"outputs": [
{
Expand Down
13 changes: 0 additions & 13 deletions charitable_repeal/NoCharitableDeduction.json

This file was deleted.

Loading

0 comments on commit d37bbd9

Please sign in to comment.