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)= 819.588
2020_REF_itax_rev($B)= 823.781
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).
Print tables#
CLP diagnostic table for CYR.
clp_diagnostic_table
2020 | |
---|---|
Returns (#m) | 204.480 |
AGI ($b) | 11573.238 |
Itemizers (#m) | 27.470 |
Itemized Deduction ($b) | 745.352 |
Standard Deduction Filers (#m) | 176.900 |
Standard Deduction ($b) | 3080.762 |
Personal Exemption ($b) | 0.000 |
Taxable Income ($b) | 8615.433 |
Regular Tax ($b) | 1497.393 |
AMT Income ($b) | 10965.716 |
AMT Liability ($b) | 0.541 |
AMT Filers (#m) | 0.070 |
Tax before Credits ($b) | 1497.933 |
Refundable Credits ($b) | 655.022 |
Nonrefundable Credits ($b) | 99.198 |
Reform Surtaxes ($b) | 0.000 |
Other Taxes ($b) | 75.874 |
Ind Income Tax ($b) | 819.588 |
Payroll Taxes ($b) | 1154.642 |
Combined Liability ($b) | 1974.229 |
With Income Tax <= 0 (#m) | 133.130 |
With Combined Tax <= 0 (#m) | 98.170 |
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.390 |
Itemized Deduction ($b) | 742.838 |
Standard Deduction Filers (#m) | 176.980 |
Standard Deduction ($b) | 3082.124 |
Personal Exemption ($b) | 375.177 |
Taxable Income ($b) | 8367.731 |
Regular Tax ($b) | 1499.234 |
AMT Income ($b) | 10969.767 |
AMT Liability ($b) | 0.547 |
AMT Filers (#m) | 0.070 |
Tax before Credits ($b) | 1499.782 |
Refundable Credits ($b) | 658.339 |
Nonrefundable Credits ($b) | 93.536 |
Reform Surtaxes ($b) | 0.000 |
Other Taxes ($b) | 75.874 |
Ind Income Tax ($b) | 823.781 |
Payroll Taxes ($b) | 1154.642 |
Combined Liability ($b) | 1978.423 |
With Income Tax <= 0 (#m) | 135.240 |
With Combined Tax <= 0 (#m) | 98.930 |
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.550068 | -25.550068 | 66.416417 | 66.416417 |
10-20 | 20.448902 | -52.266475 | -52.612891 | 308.444006 | 308.790421 |
20-30 | 20.447972 | -52.553068 | -53.568119 | 542.856550 | 543.871602 |
30-40 | 20.448551 | -42.946473 | -44.197306 | 718.134974 | 719.385807 |
40-50 | 20.448614 | -40.569819 | -42.278163 | 888.355808 | 890.064151 |
50-60 | 20.448520 | -34.560689 | -37.200719 | 1101.044444 | 1103.684474 |
60-70 | 20.448182 | -25.183853 | -28.845158 | 1382.293780 | 1385.955085 |
70-80 | 20.448218 | 6.753094 | 1.925130 | 1743.435206 | 1748.263169 |
80-90 | 20.447460 | 92.514875 | 84.338966 | 2293.854669 | 2302.030579 |
90-100 | 20.449858 | 1011.581643 | 1039.400651 | 4743.157485 | 4715.338477 |
ALL | 204.484164 | 819.587706 | 823.780862 | 13798.968063 | 13794.774906 |
90-95 | 10.225611 | 146.744821 | 141.194059 | 1532.950663 | 1538.501426 |
95-99 | 8.177219 | 331.047694 | 328.701005 | 1824.009496 | 1826.356185 |
Top 1% | 2.047027 | 533.789128 | 569.505587 | 1386.197326 | 1350.480867 |
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.346415 | -16.940538 | 0.112311 |
20-30 | 20.447972 | -1.015051 | -49.640688 | 0.186983 |
30-40 | 20.448551 | -1.250833 | -61.169772 | 0.174178 |
40-50 | 20.448614 | -1.708343 | -83.543242 | 0.192304 |
50-60 | 20.448520 | -2.640029 | -129.106130 | 0.239775 |
60-70 | 20.448182 | -3.661304 | -179.052813 | 0.264872 |
70-80 | 20.448218 | -4.827964 | -236.106817 | 0.276922 |
80-90 | 20.447460 | -8.175910 | -399.849661 | 0.356427 |
90-100 | 20.449858 | 27.819008 | 1360.352150 | -0.586508 |
ALL | 204.484164 | 4.193157 | 20.506023 | -0.030387 |
90-95 | 10.225611 | -5.550763 | -542.829424 | 0.362097 |
95-99 | 8.177219 | -2.346689 | -286.978824 | 0.128656 |
Top 1% | 2.047027 | 35.716459 | 17447.963236 | -2.576578 |