def summary_diff_xdec(res, df1, df2): """ res is dictionary of summary-results DataFrames. df1 contains results variables for baseline policy. df2 contains results variables for reform policy. returns augmented dictionary of summary-results DataFrames. """ # create difference tables grouped by xdec res['diff_itax_xdec'] = \ create_difference_table(df1, df2, 'weighted_deciles', 'iitax') res['diff_ptax_xdec'] = \ create_difference_table(df1, df2, 'weighted_deciles', 'payrolltax') res['diff_comb_xdec'] = \ create_difference_table(df1, df2, 'weighted_deciles', 'combined') # return res dictionary return res
def test_Calculator_create_difference_table(): # create current-law Policy object and use to create Calculator calc1 policy1 = Policy() puf1 = Records(data=TAX_DTA, weights=WEIGHTS, start_year=2009) calc1 = Calculator(policy=policy1, records=puf1) calc1.calc_all() # create policy-reform Policy object and use to create Calculator calc2 policy2 = Policy() reform = {2013: {'_II_rt7': [0.45]}} policy2.implement_reform(reform) puf2 = Records(data=TAX_DTA, weights=WEIGHTS, start_year=2009) calc2 = Calculator(policy=policy2, records=puf2) # create difference table and check that it is a Pandas DataFrame dtable = create_difference_table(calc1, calc2, groupby="weighted_deciles") assert isinstance(dtable, pd.DataFrame)
def test_Calculator_create_difference_table(): # create current-law Policy object and use to create Calculator calc1 policy1 = Policy() puf1 = Records(data=TAXDATA, weights=WEIGHTS, start_year=2009) calc1 = Calculator(policy=policy1, records=puf1) calc1.calc_all() # create policy-reform Policy object and use to create Calculator calc2 policy2 = Policy() reform = {2013: {'_II_rt7': [0.45]}} policy2.implement_reform(reform) puf2 = Records(data=TAXDATA, weights=WEIGHTS, start_year=2009) calc2 = Calculator(policy=policy2, records=puf2) # create difference table and check that it is a Pandas DataFrame dtable = create_difference_table(calc1, calc2, groupby="weighted_deciles") assert isinstance(dtable, pd.DataFrame)
def test_Calculator_create_difference_table(cps_subsample): # create current-law Policy object and use to create Calculator calc1 cps1 = Records.cps_constructor(data=cps_subsample) year = cps1.current_year calc1 = Calculator(policy=Policy(), records=cps1) calc1.calc_all() # create policy-reform Policy object and use to create Calculator calc2 policy2 = Policy() reform = {year: {'_II_rt7': [0.45]}} policy2.implement_reform(reform) cps2 = Records.cps_constructor(data=cps_subsample) calc2 = Calculator(policy=policy2, records=cps2) calc2.calc_all() # create difference table and check that it is a Pandas DataFrame dtable = create_difference_table(calc1.records, calc2.records, groupby='weighted_deciles', income_measure='expanded_income', tax_to_diff='payrolltax') assert isinstance(dtable, pd.DataFrame)
def test_Calculator_create_difference_table(puf_1991, weights_1991): # create current-law Policy object and use to create Calculator calc1 policy1 = Policy() puf1 = Records(data=puf_1991, weights=weights_1991, start_year=2009) calc1 = Calculator(policy=policy1, records=puf1) calc1.advance_to_year(2013) calc1.calc_all() # create policy-reform Policy object and use to create Calculator calc2 policy2 = Policy() reform = { 2013: {'_II_rt7': [0.45]}, 2013: {'_ALD_Investment_ec_base_code_active': [True]}, 0: {'ALD_Investment_ec_base_code': 'e00300 + e00650 + p23250'} } policy2.implement_reform(reform) puf2 = Records(data=puf_1991, weights=weights_1991, start_year=2009) calc2 = Calculator(policy=policy2, records=puf2) calc2.advance_to_year(2013) calc2.calc_all() # create difference table and check that it is a Pandas DataFrame dtable = create_difference_table(calc1.records, calc2.records, groupby="weighted_deciles") assert isinstance(dtable, pd.DataFrame)