Basic Recipe: Static Analysis of a Simple Reform#
This is the recipe you should follow first. Mastering this recipe is a prerequisite for all the other recipes in this cookbook.
Imports#
import taxcalc as tc
import pandas as pd
from bokeh.io import show, output_notebook
Setup#
Use publicly-available CPS input file.
NOTE: if you have access to the restricted-use IRS-SOI PUF-based input file and you have that file (named ‘puf.csv’) located in the directory where this script is located, then you can substitute the following statement for the prior statement:
recs = tc.Records()
recs = tc.Records.cps_constructor()
Specify Calculator object for static analysis of current-law policy.
pol = tc.Policy()
calc1 = tc.Calculator(policy=pol, records=recs)
NOTE: calc1 now contains a PRIVATE COPY of pol and a PRIVATE COPY of recs, so we can continue to use pol and recs in this script without any concern about side effects from Calculator method calls on calc1.
CYR = 2020
Calculate aggregate current-law income tax liabilities for CYR.
calc1.advance_to_year(CYR)
calc1.calc_all()
itax_rev1 = calc1.weighted_total('iitax')
Read JSON reform file and use (the default) static analysis assumptions.
reform_filename = 'github://PSLmodels:Tax-Calculator@master/docs/recipes/_static/reformA.json'
params = tc.Calculator.read_json_param_objects(reform_filename, None)
Specify Calculator object for static analysis of reform policy.
pol.implement_reform(params['policy'])
calc2 = tc.Calculator(policy=pol, records=recs)
Calculate#
Calculate reform income tax liabilities for CYR.
calc2.advance_to_year(CYR)
calc2.calc_all()
itax_rev2 = calc2.weighted_total('iitax')
Results#
Print total revenue estimates for 2018.
Estimates in billons of dollars rounded to nearest hundredth of a billion.
print('{}_CLP_itax_rev($B)= {:.3f}'.format(CYR, itax_rev1 * 1e-9))
print('{}_REF_itax_rev($B)= {:.3f}'.format(CYR, itax_rev2 * 1e-9))
2020_CLP_itax_rev($B)= 756.288
2020_REF_itax_rev($B)= 760.481
Generate several other standard results tables.
# Aggregate diagnostic tables for CYR.
clp_diagnostic_table = calc1.diagnostic_table(1)
ref_diagnostic_table = calc2.diagnostic_table(1)
# Income-tax distribution for CYR with CLP and REF results side-by-side.
dist_table1, dist_table2 = calc1.distribution_tables(calc2, 'weighted_deciles')
assert isinstance(dist_table1, pd.DataFrame)
assert isinstance(dist_table2, pd.DataFrame)
dist_extract = pd.DataFrame()
dist_extract['funits(#m)'] = dist_table1['count']
dist_extract['itax1($b)'] = dist_table1['iitax']
dist_extract['itax2($b)'] = dist_table2['iitax']
dist_extract['aftertax_inc1($b)'] = dist_table1['aftertax_income']
dist_extract['aftertax_inc2($b)'] = dist_table2['aftertax_income']
# Income-tax difference table by expanded-income decile for CYR.
diff_table = calc1.difference_table(calc2, 'weighted_deciles', 'iitax')
assert isinstance(diff_table, pd.DataFrame)
diff_extract = pd.DataFrame()
dif_colnames = ['count', 'tot_change', 'mean', 'pc_aftertaxinc']
ext_colnames = ['funits(#m)', 'agg_diff($b)', 'mean_diff($)', 'aftertaxinc_diff(%)']
for dname, ename in zip(dif_colnames, ext_colnames):
diff_extract[ename] = diff_table[dname]
Plotting#
Generate a decile graph and display it using Bokeh (will render in Jupyter, not in webpage).
fig = calc1.pch_graph(calc2)
output_notebook()
show(fig)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[12], line 3
1 fig = calc1.pch_graph(calc2)
2 output_notebook()
----> 3 show(fig)
File /usr/share/miniconda/envs/taxcalc-dev/lib/python3.11/site-packages/bokeh/io/showing.py:158, in show(obj, browser, new, notebook_handle, notebook_url, **kwargs)
155 assert state.notebook_type is not None
156 return run_notebook_hook(state.notebook_type, 'app', obj, state, notebook_url, **kwargs)
--> 158 raise ValueError(_BAD_SHOW_MSG)
ValueError: Invalid object to show. The object to passed to show must be one of:
* a UIElement (e.g. a plot, figure, widget or layout)
* a Bokeh Application
* a callable suitable to an application FunctionHandler
Print tables#
CLP diagnostic table for CYR.
clp_diagnostic_table
2020 | |
---|---|
Returns (#m) | 204.480 |
AGI ($b) | 11573.238 |
Itemizers (#m) | 27.730 |
Itemized Deduction ($b) | 752.189 |
Standard Deduction Filers (#m) | 176.750 |
Standard Deduction ($b) | 3075.468 |
Personal Exemption ($b) | 0.000 |
Taxable Income ($b) | 8617.397 |
Regular Tax ($b) | 1505.274 |
AMT Income ($b) | 11012.668 |
AMT Liability ($b) | 0.568 |
AMT Filers (#m) | 0.090 |
Tax before Credits ($b) | 1505.841 |
Refundable Credits ($b) | 654.861 |
Nonrefundable Credits ($b) | 99.385 |
Reform Surtaxes ($b) | 0.000 |
Other Taxes ($b) | 12.575 |
Ind Income Tax ($b) | 764.170 |
Payroll Taxes ($b) | 1217.941 |
Combined Liability ($b) | 1982.111 |
With Income Tax <= 0 (#m) | 135.170 |
With Combined Tax <= 0 (#m) | 98.150 |
UBI Benefits ($b) | 0.000 |
Total Benefits, Consumption Value ($b) | 3617.042 |
Total Benefits Cost ($b) | 3617.042 |
REF diagnostic table for CYR.
ref_diagnostic_table
2020 | |
---|---|
Returns (#m) | 204.480 |
AGI ($b) | 11573.238 |
Itemizers (#m) | 27.660 |
Itemized Deduction ($b) | 749.755 |
Standard Deduction Filers (#m) | 176.820 |
Standard Deduction ($b) | 3076.756 |
Personal Exemption ($b) | 375.177 |
Taxable Income ($b) | 8369.678 |
Regular Tax ($b) | 1505.595 |
AMT Income ($b) | 11014.938 |
AMT Liability ($b) | 0.585 |
AMT Filers (#m) | 0.090 |
Tax before Credits ($b) | 1506.180 |
Refundable Credits ($b) | 658.196 |
Nonrefundable Credits ($b) | 93.705 |
Reform Surtaxes ($b) | 0.000 |
Other Taxes ($b) | 12.575 |
Ind Income Tax ($b) | 766.855 |
Payroll Taxes ($b) | 1217.941 |
Combined Liability ($b) | 1984.796 |
With Income Tax <= 0 (#m) | 137.340 |
With Combined Tax <= 0 (#m) | 98.910 |
UBI Benefits ($b) | 0.000 |
Total Benefits, Consumption Value ($b) | 3617.042 |
Total Benefits Cost ($b) | 3617.042 |
Extract of CYR distribution tables by baseline expanded-income decile.
dist_extract
funits(#m) | itax1($b) | itax2($b) | aftertax_inc1($b) | aftertax_inc2($b) | |
---|---|---|---|---|---|
0-10n | 0.103662 | -0.292423 | -0.292423 | -6.364313 | -6.364313 |
0-10z | 8.289516 | -17.339037 | -17.339037 | 17.339037 | 17.339037 |
0-10p | 12.054710 | -25.583473 | -25.583473 | 66.416417 | 66.416417 |
10-20 | 20.448902 | -52.554387 | -52.900799 | 308.444021 | 308.790433 |
20-30 | 20.447972 | -53.636240 | -54.653772 | 542.850180 | 543.867712 |
30-40 | 20.448551 | -46.759061 | -48.021038 | 718.059905 | 719.321882 |
40-50 | 20.448614 | -44.573176 | -46.294368 | 888.228515 | 889.949708 |
50-60 | 20.448520 | -39.736886 | -42.405082 | 1100.805232 | 1103.473428 |
60-70 | 20.448182 | -30.590266 | -34.290827 | 1381.854900 | 1385.555461 |
70-80 | 20.448218 | 2.337068 | -2.517134 | 1742.953419 | 1747.807621 |
80-90 | 20.447460 | 85.024868 | 76.807708 | 2292.728158 | 2300.945318 |
90-100 | 20.449858 | 987.873311 | 1014.344944 | 4737.770572 | 4711.298939 |
ALL | 204.484164 | 764.170298 | 766.854698 | 13791.086043 | 13788.401642 |
90-95 | 10.225611 | 142.001368 | 136.439568 | 1532.001747 | 1537.563546 |
95-99 | 8.177219 | 322.467707 | 320.116774 | 1821.899805 | 1824.250737 |
Top 1% | 2.047027 | 523.404237 | 557.788601 | 1383.869020 | 1349.484656 |
Extract of CYR income-tax difference table by expanded-income decile.
diff_extract
funits(#m) | agg_diff($b) | mean_diff($) | aftertaxinc_diff(%) | |
---|---|---|---|---|
0-10n | 0.103662 | 0.000000 | 0.000000 | 0.000000 |
0-10z | 8.289516 | 0.000000 | 0.000000 | 0.000000 |
0-10p | 12.054710 | 0.000000 | 0.000000 | 0.000000 |
10-20 | 20.448902 | -0.346412 | -16.940394 | 0.112310 |
20-30 | 20.447972 | -1.017532 | -49.762006 | 0.187443 |
30-40 | 20.448551 | -1.261977 | -61.714742 | 0.175748 |
40-50 | 20.448614 | -1.721193 | -84.171605 | 0.193778 |
50-60 | 20.448520 | -2.668196 | -130.483583 | 0.242386 |
60-70 | 20.448182 | -3.700560 | -180.972592 | 0.267797 |
70-80 | 20.448218 | -4.854202 | -237.389972 | 0.278504 |
80-90 | 20.447460 | -8.217160 | -401.867019 | 0.358401 |
90-100 | 20.449858 | 26.471633 | 1294.465375 | -0.558736 |
ALL | 204.484164 | 2.684400 | 13.127667 | -0.019465 |
90-95 | 10.225611 | -5.561800 | -543.908766 | 0.363041 |
95-99 | 8.177219 | -2.350932 | -287.497784 | 0.129037 |
Top 1% | 2.047027 | 34.384364 | 16797.217391 | -2.484655 |