Recipe 1: Directly Comparing Two Reforms
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)= 1357.983
2018_REFORM2_iitax_rev($B)= 1191.571
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.099275 0.000000 0.000000 0.000000 0.000000 0.000000
0-10z 8.084575 0.000000 0.000000 0.000000 0.000000 NaN
0-10p 11.736716 0.169109 0.011897 -0.011921 -1.015679 0.031167
10-20 19.920648 6.244056 2.883407 -0.773509 -38.829518 0.322414
20-30 19.920369 10.151692 2.378508 -1.896750 -95.216622 0.419343
30-40 19.920510 9.246090 1.994306 -3.503089 -175.853380 0.571074
40-50 19.920961 11.036375 2.113940 -5.831999 -292.756920 0.767197
50-60 19.919733 13.189452 2.028448 -8.722770 -437.895906 0.920883
60-70 19.920039 14.175127 1.732710 -11.956366 -600.218012 1.000142
70-80 19.922180 15.556599 1.507744 -17.063260 -856.495621 1.126855
80-90 19.920490 16.985303 1.623547 -26.169107 -1313.677861 1.300507
90-100 19.920987 18.176452 1.484443 -90.484066 -4542.147681 2.145438
ALL 199.206484 114.930254 17.758950 -166.412837 -835.378618 1.388565
90-95 9.960346 8.974041 0.753146 -22.527613 -2261.729963 1.659858
95-99 7.967575 7.400193 0.540449 -37.482913 -4704.431831 2.289373
Top 1% 1.993066 1.802218 0.190848 -30.473540 -15289.777108 2.491596