Recipe 1: Directly Comparing Two Reforms

This is an advanced recipe that should be followed only after mastering the basic recipe. This recipe shows how to compare two reforms (instead of comparing a reform to current-law policy) and also shows how to use the reform files available on the Tax-Calculator website (instead of reform files on your computer’s disk).

import pandas as pd
import taxcalc as tc

# read an "old" reform file
# ("old" means the reform file is defined relative to pre-TCJA policy)
# specify reform dictionary for pre-TCJA policy
reform1 = tc.Policy.read_json_reform('github://PSLmodels:[email protected]/psl_examples/taxcalc/2017_law.json')

# specify reform dictionary for TCJA as passed by Congress in late 2017
reform2 = tc.Policy.read_json_reform('github://PSLmodels:[email protected]/psl_examples/taxcalc/TCJA.json')

# specify Policy object for pre-TCJA policy
bpolicy = tc.Policy()
bpolicy.implement_reform(reform1, print_warnings=False, raise_errors=False)
assert not bpolicy.parameter_errors

# specify Policy object for TCJA reform relative to pre-TCJA policy
rpolicy = tc.Policy()
rpolicy.implement_reform(reform1, print_warnings=False, raise_errors=False)
assert not rpolicy.parameter_errors
rpolicy.implement_reform(reform2, print_warnings=False, raise_errors=False)
assert not rpolicy.parameter_errors

# specify Calculator objects using bpolicy and rpolicy
recs = tc.Records.cps_constructor()
calc1 = tc.Calculator(policy=bpolicy, records=recs)
calc2 = tc.Calculator(policy=rpolicy, records=recs)

CYR = 2018

# calculate for specified CYR
calc1.advance_to_year(CYR)
calc1.calc_all()
calc2.advance_to_year(CYR)
calc2.calc_all()

# compare aggregate individual income tax revenue in cyr
iitax_rev1 = calc1.weighted_total('iitax')
iitax_rev2 = calc2.weighted_total('iitax')

# construct reform-vs-baseline difference table with results for income deciles
diff_table = calc1.difference_table(calc2, 'weighted_deciles', 'iitax')
assert isinstance(diff_table, pd.DataFrame)
diff_extract = pd.DataFrame()
dif_colnames = ['count', 'tax_cut', 'tax_inc',
                'tot_change', 'mean', 'pc_aftertaxinc']
ext_colnames = ['funits(#m)', 'taxfall(#m)', 'taxrise(#m)',
                'agg_diff($b)', 'mean_diff($)', 'aftertax_income_diff(%)']
for dname, ename in zip(dif_colnames, ext_colnames):
    diff_extract[ename] = diff_table[dname]

# print total revenue estimates for cyr
# (estimates in billons of dollars)
print('{}_REFORM1_iitax_rev($B)= {:.3f}'.format(CYR, iitax_rev1 * 1e-9))
print('{}_REFORM2_iitax_rev($B)= {:.3f}'.format(CYR, iitax_rev2 * 1e-9))
print('')
2018_REFORM1_iitax_rev($B)= 1361.859
2018_REFORM2_iitax_rev($B)= 1196.075

Print reform2-vs-reform1 difference table

title = 'Extract of {} income-tax difference table by expanded-income decile'
print(title.format(CYR))
print('(taxfall is count of funits with cut in income tax in reform 2 vs 1)')
print('(taxrise is count of funits with rise in income tax in reform 2 vs 1)')
print(diff_extract.to_string())
Extract of 2018 income-tax difference table by expanded-income decile
(taxfall is count of funits with cut in income tax in reform 2 vs 1)
(taxrise is count of funits with rise in income tax in reform 2 vs 1)
        funits(#m)  taxfall(#m)  taxrise(#m)  agg_diff($b)  mean_diff($)  aftertax_income_diff(%)
0-10n     0.099742     0.000000     0.000000      0.000000      0.000000                 0.000000
0-10z     8.084653     0.000000     0.000000      0.000000      0.000000                      NaN
0-10p    11.735831     0.169713     0.011669     -0.011923     -1.015920                 0.031151
10-20    19.920848     6.239705     2.895547     -0.766881    -38.496427                 0.319477
20-30    19.920146    10.132640     2.387495     -1.866205    -93.684295                 0.412454
30-40    19.920561     9.239134     2.015874     -3.466169   -173.999549                 0.564827
40-50    19.919924    11.020788     2.138870     -5.783431   -290.333976                 0.760367
50-60    19.922029    13.174235     2.061306     -8.655064   -434.446919                 0.912881
60-70    19.920346    14.126142     1.781818    -11.867154   -595.730290                 0.991809
70-80    19.917057    15.546695     1.522491    -16.993878   -853.232403                 1.121252
80-90    19.923101    16.962623     1.655510    -26.056769  -1307.867172                 1.293067
90-100   19.922247    18.148631     1.518318    -90.316241  -4533.436382                 2.135573
ALL     199.206484   114.760307    17.988898   -165.783714   -832.220471                 1.381147
90-95     9.961787     8.956795     0.774215    -22.404568  -2249.051168                 1.647649
95-99     7.965885     7.392816     0.548547    -37.437716  -4699.756143                 2.282615
Top 1%    1.994576     1.799021     0.195555    -30.473957 -15278.415215                 2.479132