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:examples@main/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:examples@main/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('')
/Users/jason.debacker/Library/Python/3.9/lib/python/site-packages/urllib3/__init__.py:34: NotOpenSSLWarning: urllib3 v2.0 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with 'LibreSSL 2.8.3'. See: https://github.com/urllib3/urllib3/issues/3020
  warnings.warn(
2018_REFORM1_iitax_rev($B)= 1357.959
2018_REFORM2_iitax_rev($B)= 1191.548

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.084542     0.000000     0.000000      0.000000      0.000000                      NaN
0-10p    11.735976     0.169109     0.011897     -0.011921     -1.015744                 0.031171
10-20    19.921421     6.244056     2.883407     -0.773509    -38.828008                 0.322410
20-30    19.920369    10.151692     2.378508     -1.896750    -95.216620                 0.419345
30-40    19.917881     9.242263     1.994306     -3.502678   -175.855977                 0.571117
40-50    19.923591    11.040202     2.113940     -5.832407   -292.738759                 0.767135
50-60    19.919733    13.189452     2.028448     -8.722775   -437.896167                 0.920887
60-70    19.921081    14.175127     1.733752    -11.955894   -600.162899                 1.000052
70-80    19.921138    15.556599     1.506702    -17.063720   -856.563503                 1.126938
80-90    19.920627    16.985440     1.623547    -26.169065  -1313.666732                 1.300501
90-100   19.920851    18.176315     1.484443    -90.482764  -4542.113487                 2.145463
ALL     199.206484   114.930254    17.758950   -166.411483   -835.371819                 1.388568
90-95     9.960209     8.973904     0.753146    -22.527567  -2261.756334                 1.659892
95-99     7.968375     7.400993     0.540449    -37.453830  -4700.309681                 2.287011
Top 1%    1.992266     1.801418     0.190848    -30.501367 -15309.885606                 2.494891