예제 #1
0
def test_proportional_change_in_gdp(cps_subsample):
    """
    Test correct and incorrect calls to proportional_change_in_gdp function.
    """
    rec = Records.cps_constructor(data=cps_subsample, no_benefits=True)
    pol = Policy()
    calc1 = Calculator(policy=pol, records=rec)
    reform = {2015: {'_II_em': [0.0]}}  # reform increases taxes and MTRs
    pol.implement_reform(reform)
    calc2 = Calculator(policy=pol, records=rec)
    assert calc1.current_year == calc2.current_year
    assert calc1.current_year == 2014  # because using CPS data
    gdpc = proportional_change_in_gdp(2014, calc1, calc2, elasticity=0.36)
    assert gdpc == 0.0  # no effect for first data year
    gdpc = proportional_change_in_gdp(2015, calc1, calc2, elasticity=0.36)
    assert gdpc == 0.0  # no effect in first year of reform
    calc1.increment_year()
    calc2.increment_year()
    assert calc1.current_year == 2015
    gdp_pchg = 100.0 * proportional_change_in_gdp(
        2016, calc1, calc2, elasticity=0.36)
    exp_pchg = -0.54  # higher MTRs imply negative expected GDP percent change
    abs_diff_pchg = abs(gdp_pchg - exp_pchg)
    if abs_diff_pchg > 0.01:
        msg = 'year,gdp_pchg,exp_pchg= {} {:.3f} {:.3f}'.format(
            2016, gdp_pchg, exp_pchg)
        assert msg == 'ERROR: gdp_pchg not close to exp_pchg'
    # skip calcN.increment_year to 2016, so calcN.current_year is still 2015
    with pytest.raises(ValueError):
        proportional_change_in_gdp(2017, calc1, calc2, elasticity=0.36)
예제 #2
0
def run_nth_year_gdp_elast_model(year_n,
                                 start_year,
                                 use_puf_not_cps,
                                 use_full_sample,
                                 user_mods,
                                 gdp_elasticity,
                                 return_dict=True):
    """
    The run_nth_year_gdp_elast_model function assumes user_mods is a dictionary
      returned by the Calculator.read_json_param_objects() function.
    Setting use_puf_not_cps=True implies use puf.csv input file;
      otherwise, use cps.csv input file.
    Setting use_full_sample=False implies use sub-sample of input file;
      otherwsie, use the complete sample.
    """
    # pylint: disable=too-many-arguments,too-many-locals

    # calculate gdp_effect
    fyear = check_years_return_first_year(year_n, start_year, use_puf_not_cps)
    if (start_year + year_n) > fyear:
        # create calc1 and calc2 calculated for year_n - 1
        (calc1, calc2, _) = calculate((year_n - 1),
                                      start_year,
                                      use_puf_not_cps,
                                      use_full_sample,
                                      user_mods,
                                      behavior_allowed=False)
        # compute GDP effect given specified gdp_elasticity
        gdp_effect = proportional_change_in_gdp((start_year + year_n), calc1,
                                                calc2, gdp_elasticity)
    else:
        gdp_effect = 0.0

    # return gdp_effect results
    if return_dict:
        gdp_df = pd.DataFrame(data=[gdp_effect], columns=['col0'])
        gdp_elast_names_n = [
            x + '_' + str(year_n) for x in GDP_ELAST_ROW_NAMES
        ]
        gdp_elast_total = create_dict_table(gdp_df,
                                            row_names=gdp_elast_names_n,
                                            num_decimals=5)
        gdp_elast_total = dict((k, v[0]) for k, v in gdp_elast_total.items())
        return gdp_elast_total
    else:
        return gdp_effect