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.585
2020_REF_itax_rev($B)= 823.778
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.240 |
| Itemizers (#m) | 27.470 |
| Itemized Deduction ($b) | 745.341 |
| Standard Deduction Filers (#m) | 176.900 |
| Standard Deduction ($b) | 3080.762 |
| Personal Exemption ($b) | 0.000 |
| Taxable Income ($b) | 8615.438 |
| Regular Tax ($b) | 1497.393 |
| AMT Income ($b) | 10965.638 |
| AMT Liability ($b) | 0.537 |
| AMT Filers (#m) | 0.070 |
| Tax before Credits ($b) | 1497.931 |
| 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.585 |
| Payroll Taxes ($b) | 1154.642 |
| Combined Liability ($b) | 1974.227 |
| 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.240 |
| Itemizers (#m) | 27.390 |
| Itemized Deduction ($b) | 742.827 |
| Standard Deduction Filers (#m) | 176.980 |
| Standard Deduction ($b) | 3082.124 |
| Personal Exemption ($b) | 375.177 |
| Taxable Income ($b) | 8367.736 |
| Regular Tax ($b) | 1499.235 |
| AMT Income ($b) | 10969.689 |
| AMT Liability ($b) | 0.544 |
| AMT Filers (#m) | 0.070 |
| Tax before Credits ($b) | 1499.779 |
| 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.778 |
| Payroll Taxes ($b) | 1154.642 |
| Combined Liability ($b) | 1978.420 |
| 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.266473 | -52.612889 | 308.444004 | 308.790419 |
| 20-30 | 20.447972 | -52.553056 | -53.568108 | 542.856538 | 543.871590 |
| 30-40 | 20.448551 | -42.946454 | -44.197289 | 718.134955 | 719.385790 |
| 40-50 | 20.448614 | -40.569791 | -42.278136 | 888.355779 | 890.064124 |
| 50-60 | 20.448520 | -34.560649 | -37.200681 | 1101.044404 | 1103.684436 |
| 60-70 | 20.448182 | -25.183794 | -28.845101 | 1382.293720 | 1385.955027 |
| 70-80 | 20.448218 | 6.753192 | 1.925226 | 1743.435107 | 1748.263073 |
| 80-90 | 20.447460 | 92.515064 | 84.339146 | 2293.854481 | 2302.030399 |
| 90-100 | 20.449858 | 1011.578642 | 1039.397652 | 4743.160486 | 4715.341476 |
| ALL | 204.484164 | 819.585153 | 823.778293 | 13798.970615 | 13794.777476 |
| 90-95 | 10.225611 | 146.744991 | 141.194226 | 1532.950494 | 1538.501259 |
| 95-99 | 8.177219 | 331.047883 | 328.701195 | 1824.009307 | 1826.355994 |
| Top 1% | 2.047027 | 533.785769 | 569.502231 | 1386.200685 | 1350.484223 |
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.346416 | -16.940556 | 0.112311 |
| 20-30 | 20.447972 | -1.015052 | -49.640733 | 0.186984 |
| 30-40 | 20.448551 | -1.250834 | -61.169823 | 0.174178 |
| 40-50 | 20.448614 | -1.708345 | -83.543321 | 0.192304 |
| 50-60 | 20.448520 | -2.640032 | -129.106266 | 0.239775 |
| 60-70 | 20.448182 | -3.661307 | -179.052934 | 0.264872 |
| 70-80 | 20.448218 | -4.827966 | -236.106917 | 0.276923 |
| 80-90 | 20.447460 | -8.175918 | -399.850070 | 0.356427 |
| 90-100 | 20.449858 | 27.819010 | 1360.352254 | -0.586508 |
| ALL | 204.484164 | 4.193139 | 20.505937 | -0.030387 |
| 90-95 | 10.225611 | -5.550765 | -542.829616 | 0.362097 |
| 95-99 | 8.177219 | -2.346687 | -286.978651 | 0.128655 |
| Top 1% | 2.047027 | 35.716462 | 17447.964546 | -2.576572 |