def test_Calculator_current_law_version(records_2009):
    policy = Policy()
    reform = {2013: {'_II_rt7': [0.45]}}
    policy.implement_reform(reform)
    calc = Calculator(policy=policy, records=records_2009)
    calc_clp = calc.current_law_version()
    assert isinstance(calc_clp, Calculator)
    assert calc.policy.II_rt6 == calc_clp.policy.II_rt6
    assert calc.policy.II_rt7 != calc_clp.policy.II_rt7
示例#2
0
def test_Calculator_current_law_version(records_2009):
    policy = Policy()
    reform = {2013: {'_II_rt7': [0.45]}}
    policy.implement_reform(reform)
    calc = Calculator(policy=policy, records=records_2009)
    calc_clp = calc.current_law_version()
    assert isinstance(calc_clp, Calculator)
    assert calc.policy.II_rt6 == calc_clp.policy.II_rt6
    assert calc.policy.II_rt7 != calc_clp.policy.II_rt7
def test_calculator_current_law_version(cps_subsample):
    rec = Records.cps_constructor(data=cps_subsample)
    pol = Policy()
    reform = {2013: {'_II_rt7': [0.45]}}
    pol.implement_reform(reform)
    calc = Calculator(policy=pol, records=rec)
    calc_clp = calc.current_law_version()
    assert isinstance(calc_clp, Calculator)
    assert calc.policy.II_rt6 == calc_clp.policy.II_rt6
    assert calc.policy.II_rt7 != calc_clp.policy.II_rt7
示例#4
0
def reform_results(reform_dict, puf_data):
    """
    Return actual results of the reform specified in reform_dict.
    """
    # pylint: disable=too-many-locals
    # create current-law-policy Calculator object
    pol1 = Policy()
    rec1 = Records(data=puf_data)
    calc1 = Calculator(policy=pol1, records=rec1, verbose=False, behavior=None)
    # create reform Calculator object with possible behavioral responses
    start_year = reform_dict['start_year']
    beh2 = Behavior()
    if '_BE_cg' in reform_dict['value']:
        elasticity = reform_dict['value']['_BE_cg']
        del reform_dict['value']['_BE_cg']  # in order to have a valid reform
        beh_assump = {start_year: {'_BE_cg': elasticity}}
        beh2.update_behavior(beh_assump)
    reform = {start_year: reform_dict['value']}
    pol2 = Policy()
    pol2.implement_reform(reform)
    rec2 = Records(data=puf_data)
    calc2 = Calculator(policy=pol2, records=rec2, verbose=False, behavior=beh2)
    # increment both calculators to reform's start_year
    calc1.advance_to_year(start_year)
    calc2.advance_to_year(start_year)
    # calculate prereform and postreform output for several years
    output_type = reform_dict['output_type']
    num_years = 4
    results = list()
    for _ in range(0, num_years):
        calc1.calc_all()
        prereform = getattr(calc1.records, output_type)
        if calc2.behavior.has_response():
            calc_clp = calc2.current_law_version()
            calc2_br = Behavior.response(calc_clp, calc2)
            postreform = getattr(calc2_br.records, output_type)
        else:
            calc2.calc_all()
            postreform = getattr(calc2.records, output_type)
        diff = postreform - prereform
        weighted_sum_diff = (diff * calc1.records.s006).sum() * 1.0e-9
        results.append(weighted_sum_diff)
        calc1.increment_year()
        calc2.increment_year()
    # write actual results to actual_str
    reform_description = reform_dict['name']
    actual_str = '{}\n'.format(reform_description)
    actual_str += 'Tax-Calculator'
    for iyr in range(0, num_years):
        actual_str += ',{:.1f}'.format(results[iyr])
    return actual_str
示例#5
0
def test_multiyear_diagnostic_table_w_behv(records_2009):
    pol = Policy()
    behv = Behavior()
    calc = Calculator(policy=pol, records=records_2009, behavior=behv)
    assert calc.current_year == 2013
    reform = {2013: {"_II_rt7": [0.33], "_PT_rt7": [0.33]}}
    pol.implement_reform(reform)
    reform_be = {2013: {"_BE_sub": [0.4], "_BE_cg": [-3.67]}}
    behv.update_behavior(reform_be)
    calc_clp = calc.current_law_version()
    calc_behv = Behavior.response(calc_clp, calc)
    calc_behv.calc_all()
    liabilities_x = (calc_behv.records._combined * calc_behv.records.s006).sum()
    adt = multiyear_diagnostic_table(calc_behv, 1)
    # extract combined liabilities as a float and
    # adopt units of the raw calculator data in liabilities_x
    liabilities_y = adt.iloc[18].tolist()[0] * 1000000000
    npt.assert_almost_equal(liabilities_x, liabilities_y, 2)
示例#6
0
def test_myr_diag_table_w_behv(cps_subsample):
    pol = Policy()
    rec = Records.cps_constructor(data=cps_subsample)
    year = rec.current_year
    beh = Behavior()
    calc = Calculator(policy=pol, records=rec, behavior=beh)
    assert calc.current_year == year
    reform = {year: {'_II_rt7': [0.33], '_PT_rt7': [0.33]}}
    pol.implement_reform(reform)
    reform_behav = {year: {'_BE_sub': [0.4], '_BE_cg': [-3.67]}}
    beh.update_behavior(reform_behav)
    calc_clp = calc.current_law_version()
    calc_beh = Behavior.response(calc_clp, calc)
    calc_beh.calc_all()
    liabilities_x = (calc_beh.records.combined * calc_beh.records.s006).sum()
    adt = multiyear_diagnostic_table(calc_beh, 1)
    # extract combined liabilities as a float and
    # adopt units of the raw calculator data in liabilities_x
    liabilities_y = adt.iloc[19].tolist()[0] * 1e9
    assert np.allclose(liabilities_x, liabilities_y, atol=0.01, rtol=0.0)
示例#7
0
def test_myr_diag_table_w_behv(records_2009):
    pol = Policy()
    behv = Behavior()
    calc = Calculator(policy=pol, records=records_2009, behavior=behv)
    assert calc.current_year == 2013
    reform = {
        2013: {
            '_II_rt7': [0.33],
            '_PT_rt7': [0.33],
        }
    }
    pol.implement_reform(reform)
    reform_be = {2013: {'_BE_sub': [0.4], '_BE_cg': [-3.67]}}
    behv.update_behavior(reform_be)
    calc_clp = calc.current_law_version()
    calc_behv = Behavior.response(calc_clp, calc)
    calc_behv.calc_all()
    liabilities_x = (calc_behv.records.combined * calc_behv.records.s006).sum()
    adt = multiyear_diagnostic_table(calc_behv, 1)
    # extract combined liabilities as a float and
    # adopt units of the raw calculator data in liabilities_x
    liabilities_y = adt.iloc[19].tolist()[0] * 1000000000
    assert_almost_equal(liabilities_x, liabilities_y, 2)
示例#8
0
    rec2 = Records(data=PUF_DATA)
    calc2 = Calculator(policy=pol2, records=rec2, verbose=False, behavior=beh2)
    output_type = REFORMS_JSON.get(this_reform).get("output_type")
    reform_name = REFORMS_JSON.get(this_reform).get("name")

    # increment both calculators to reform's start_year
    calc1.advance_to_year(start_year)
    calc2.advance_to_year(start_year)

    # calculate prereform and postreform for num_years
    reform_results = []
    for _ in range(0, NUM_YEARS):
        calc1.calc_all()
        prereform = getattr(calc1.records, output_type)
        if calc2.behavior.has_response():
            calc_clp = calc2.current_law_version()
            calc2_br = Behavior.response(calc_clp, calc2)
            postreform = getattr(calc2_br.records, output_type)
        else:
            calc2.calc_all()
            postreform = getattr(calc2.records, output_type)
        diff = postreform - prereform
        weighted_sum_diff = (diff * calc1.records.s006).sum() * 1.0e-9
        reform_results.append(weighted_sum_diff)
        calc1.increment_year()
        calc2.increment_year()

    # put reform_results in the dictionary of all results
    RESULTS[reform_name] = reform_results

# write RESULTS to text file