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)= 773.587
2020_REF_itax_rev($B)= 777.762
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) | 11572.622 |
| Itemizers (#m) | 27.730 |
| Itemized Deduction ($b) | 752.076 |
| Standard Deduction Filers (#m) | 176.760 |
| Standard Deduction ($b) | 3076.415 |
| Personal Exemption ($b) | 0.000 |
| Taxable Income ($b) | 8619.530 |
| Regular Tax ($b) | 1498.038 |
| AMT Income ($b) | 10952.969 |
| AMT Liability ($b) | 0.537 |
| AMT Filers (#m) | 0.070 |
| Tax before Credits ($b) | 1498.575 |
| Refundable Credits ($b) | 638.295 |
| Nonrefundable Credits ($b) | 99.269 |
| Reform Surtaxes ($b) | 0.000 |
| Other Taxes ($b) | 75.874 |
| Ind Income Tax ($b) | 773.587 |
| Payroll Taxes ($b) | 1217.941 |
| Combined Liability ($b) | 1991.528 |
| With Income Tax <= 0 (#m) | 135.400 |
| With Combined Tax <= 0 (#m) | 97.110 |
| 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) | 11572.622 |
| Itemizers (#m) | 27.650 |
| Itemized Deduction ($b) | 749.594 |
| Standard Deduction Filers (#m) | 176.830 |
| Standard Deduction ($b) | 3077.754 |
| Personal Exemption ($b) | 375.177 |
| Taxable Income ($b) | 8371.745 |
| Regular Tax ($b) | 1499.863 |
| AMT Income ($b) | 10957.001 |
| AMT Liability ($b) | 0.544 |
| AMT Filers (#m) | 0.070 |
| Tax before Credits ($b) | 1500.407 |
| Refundable Credits ($b) | 641.613 |
| Nonrefundable Credits ($b) | 93.606 |
| Reform Surtaxes ($b) | 0.000 |
| Other Taxes ($b) | 75.874 |
| Ind Income Tax ($b) | 777.762 |
| Payroll Taxes ($b) | 1217.941 |
| Combined Liability ($b) | 1995.703 |
| With Income Tax <= 0 (#m) | 137.560 |
| With Combined Tax <= 0 (#m) | 97.850 |
| 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.215491 | -25.215491 | 66.048435 | 66.048435 |
| 10-20 | 20.448902 | -51.032191 | -51.378666 | 306.921825 | 307.268299 |
| 20-30 | 20.447972 | -52.105279 | -53.120997 | 541.319218 | 542.334937 |
| 30-40 | 20.448551 | -44.346304 | -45.598561 | 715.647148 | 716.899405 |
| 40-50 | 20.448614 | -41.796791 | -43.507410 | 885.452131 | 887.162750 |
| 50-60 | 20.448520 | -37.680448 | -40.323017 | 1098.748794 | 1101.391362 |
| 60-70 | 20.448182 | -28.577619 | -32.240598 | 1379.842253 | 1383.505231 |
| 70-80 | 20.448218 | 3.971282 | -0.858011 | 1741.319205 | 1746.148498 |
| 80-90 | 20.447460 | 85.058903 | 76.874671 | 2292.694123 | 2300.878355 |
| 90-100 | 20.449858 | 982.941978 | 1010.761603 | 4742.701863 | 4714.882238 |
| ALL | 204.484164 | 773.586579 | 777.762063 | 13781.669719 | 13777.494235 |
| 90-95 | 10.225611 | 141.366846 | 135.815262 | 1532.636268 | 1538.187853 |
| 95-99 | 8.177219 | 320.487093 | 318.139935 | 1823.880376 | 1826.227534 |
| Top 1% | 2.047027 | 521.088038 | 556.806406 | 1386.185219 | 1350.466850 |
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.346475 | -16.943439 | 0.112887 |
| 20-30 | 20.447972 | -1.015719 | -49.673318 | 0.187638 |
| 30-40 | 20.448551 | -1.252257 | -61.239383 | 0.174982 |
| 40-50 | 20.448614 | -1.710619 | -83.654528 | 0.193192 |
| 50-60 | 20.448520 | -2.642569 | -129.230324 | 0.240507 |
| 60-70 | 20.448182 | -3.662979 | -179.134680 | 0.265464 |
| 70-80 | 20.448218 | -4.829293 | -236.171839 | 0.277335 |
| 80-90 | 20.447460 | -8.184232 | -400.256663 | 0.356970 |
| 90-100 | 20.449858 | 27.819625 | 1360.382342 | -0.586578 |
| ALL | 204.484164 | 4.175483 | 20.419593 | -0.030297 |
| 90-95 | 10.225611 | -5.551584 | -542.909800 | 0.362225 |
| 95-99 | 8.177219 | -2.347159 | -287.036298 | 0.128690 |
| Top 1% | 2.047027 | 35.718368 | 17448.895957 | -2.576739 |