def test_future_update_behavior(): behv = Behavior() assert behv.current_year == behv.start_year assert behv.has_response() is False cyr = 2020 behv.set_year(cyr) behv.update_behavior({cyr: {'_BE_cg': [-1.0]}}) assert behv.current_year == cyr assert behv.has_response() is True behv.set_year(cyr - 1) assert behv.has_response() is False
def test_future_update_behavior(): behv = Behavior() assert behv.current_year == behv.start_year assert behv.has_response() is False cyr = 2020 behv.set_year(cyr) behv.update_behavior({cyr: {'_BE_cg': [1.0]}}) assert behv.current_year == cyr assert behv.has_response() is True behv.set_year(cyr - 1) assert behv.has_response() is False
def test_Calculator_diagnostic_table(): puf = Records(data=TAXDATA, weights=WEIGHTS, start_year=Records.PUF_YEAR) beh = Behavior() beh.update_behavior({2013: {'_BE_sub': [0.4]}}) assert beh.has_response() calc = Calculator(policy=Policy(), records=puf, behavior=beh) calc.diagnostic_table(base_calc=calc)
def test_behavioral_response_Calculator(cps_subsample): # create Records objects records_x = Records.cps_constructor(data=cps_subsample) records_y = Records.cps_constructor(data=cps_subsample) year = records_x.current_year # create Policy objects policy_x = Policy() policy_y = Policy() # implement policy_y reform reform = {year: {'_II_rt7': [0.496], '_PT_rt7': [0.496]}} policy_y.implement_reform(reform) # create two Calculator objects behavior_y = Behavior() calc_x = Calculator(policy=policy_x, records=records_x) calc_y = Calculator(policy=policy_y, records=records_y, behavior=behavior_y) # test incorrect use of Behavior._mtr_xy method with pytest.raises(ValueError): behv = Behavior._mtr_xy(calc_x, calc_y, mtr_of='e00200p', tax_type='nonsense') # vary substitution and income effects in calc_y behavior0 = {year: {'_BE_sub': [0.0], '_BE_cg': [0.0], '_BE_charity': [[0.0, 0.0, 0.0]]}} behavior_y.update_behavior(behavior0) calc_y_behavior0 = Behavior.response(calc_x, calc_y) behavior1 = {year: {'_BE_sub': [0.3], '_BE_inc': [-0.1], '_BE_cg': [0.0], '_BE_subinc_wrt_earnings': [True]}} behavior_y.update_behavior(behavior1) assert behavior_y.has_response() is True epsilon = 1e-9 assert abs(behavior_y.BE_sub - 0.3) < epsilon assert abs(behavior_y.BE_inc - -0.1) < epsilon assert abs(behavior_y.BE_cg - 0.0) < epsilon calc_y_behavior1 = Behavior.response(calc_x, calc_y) behavior2 = {year: {'_BE_sub': [0.5], '_BE_cg': [-0.8]}} behavior_y.update_behavior(behavior2) calc_y_behavior2 = Behavior.response(calc_x, calc_y) behavior3 = {year: {'_BE_inc': [-0.2], '_BE_cg': [-0.8]}} behavior_y.update_behavior(behavior3) calc_y_behavior3 = Behavior.response(calc_x, calc_y) behavior4 = {year: {'_BE_cg': [-0.8]}} behavior_y.update_behavior(behavior4) calc_y_behavior4 = Behavior.response(calc_x, calc_y) behavior5 = {year: {'_BE_charity': [[-0.5, -0.5, -0.5]]}} behavior_y.update_behavior(behavior5) calc_y_behavior5 = Behavior.response(calc_x, calc_y) # check that total income tax liability differs across the # six sets of behavioral-response elasticities assert (calc_y_behavior0.records.iitax.sum() != calc_y_behavior1.records.iitax.sum() != calc_y_behavior2.records.iitax.sum() != calc_y_behavior3.records.iitax.sum() != calc_y_behavior4.records.iitax.sum() != calc_y_behavior5.records.iitax.sum()) # test incorrect _mtr_xy() usage with pytest.raises(ValueError): Behavior._mtr_xy(calc_x, calc_y, mtr_of='e00200p', tax_type='?')
def test_behavioral_response_Calculator(puf_1991, weights_1991): # create Records objects records_x = Records(data=puf_1991, weights=weights_1991, start_year=2009) records_y = Records(data=puf_1991, weights=weights_1991, start_year=2009) # create Policy objects policy_x = Policy() policy_y = Policy() # implement policy_y reform reform = {2013: {'_II_rt7': [0.496], '_PT_rt7': [0.496]}} policy_y.implement_reform(reform) # create two Calculator objects behavior_y = Behavior() calc_x = Calculator(policy=policy_x, records=records_x) calc_y = Calculator(policy=policy_y, records=records_y, behavior=behavior_y) # test incorrect use of Behavior._mtr_xy method with pytest.raises(ValueError): behv = Behavior._mtr_xy(calc_x, calc_y, mtr_of='e00200p', tax_type='nonsense') # vary substitution and income effects in calc_y behavior0 = {2013: {'_BE_sub': [0.0], '_BE_cg': [0.0], '_BE_charity': [[0.0, 0.0, 0.0]]}} behavior_y.update_behavior(behavior0) calc_y_behavior0 = Behavior.response(calc_x, calc_y) behavior1 = {2013: {'_BE_sub': [0.3], '_BE_cg': [0.0]}} behavior_y.update_behavior(behavior1) assert behavior_y.has_response() is True assert behavior_y.BE_sub == 0.3 assert behavior_y.BE_inc == 0.0 assert behavior_y.BE_cg == 0.0 calc_y_behavior1 = Behavior.response(calc_x, calc_y) behavior2 = {2013: {'_BE_sub': [0.5], '_BE_cg': [-0.8]}} behavior_y.update_behavior(behavior2) calc_y_behavior2 = Behavior.response(calc_x, calc_y) behavior3 = {2013: {'_BE_inc': [-0.2], '_BE_cg': [-0.8]}} behavior_y.update_behavior(behavior3) calc_y_behavior3 = Behavior.response(calc_x, calc_y) behavior4 = {2013: {'_BE_cg': [-0.8]}} behavior_y.update_behavior(behavior4) calc_y_behavior4 = Behavior.response(calc_x, calc_y) behavior5 = {2013: {'_BE_charity': [[-0.5, -0.5, -0.5]]}} behavior_y.update_behavior(behavior5) calc_y_behavior5 = Behavior.response(calc_x, calc_y) # check that total income tax liability differs across the # six sets of behavioral-response elasticities assert (calc_y_behavior0.records.iitax.sum() != calc_y_behavior1.records.iitax.sum() != calc_y_behavior2.records.iitax.sum() != calc_y_behavior3.records.iitax.sum() != calc_y_behavior4.records.iitax.sum() != calc_y_behavior5.records.iitax.sum()) # test incorrect _mtr_xy() usage with pytest.raises(ValueError): Behavior._mtr_xy(calc_x, calc_y, mtr_of='e00200p', tax_type='?')
def test_behavioral_response_Calculator(): # create Records objects records_x = Records(data=TAXDATA, weights=WEIGHTS, start_year=2009) records_y = Records(data=TAXDATA, weights=WEIGHTS, start_year=2009) # create Policy objects policy_x = Policy() policy_y = Policy() # implement policy_y reform reform = { 2013: { "_II_rt7": [0.496] } } policy_y.implement_reform(reform) # create two Calculator objects behavior_y = Behavior() calc_x = Calculator(policy=policy_x, records=records_x) calc_y = Calculator(policy=policy_y, records=records_y, behavior=behavior_y) # vary substitution and income effects in calc_y behavior1 = { 2013: { "_BE_sub": [0.4], "_BE_inc": [-0.15] } } behavior_y.update_behavior(behavior1) assert behavior_y.has_response() assert behavior_y.BE_sub == 0.4 assert behavior_y.BE_inc == -0.15 calc_y_behavior1 = calc_y.behavior.response(calc_x, calc_y) behavior2 = { 2013: { "_BE_sub": [0.5], "_BE_inc": [-0.15] } } behavior_y.update_behavior(behavior2) calc_y_behavior2 = calc_y.behavior.response(calc_x, calc_y) behavior3 = { 2013: { "_BE_sub": [0.4], "_BE_inc": [0.0] } } behavior_y.update_behavior(behavior3) calc_y_behavior3 = calc_y.behavior.response(calc_x, calc_y) # check that total income tax liability differs across the # three sets of behavioral-response elasticities assert (calc_y_behavior1.records._iitax.sum() != calc_y_behavior2.records._iitax.sum() != calc_y_behavior3.records._iitax.sum())
def test_behavioral_response_Calculator(puf_1991, weights_1991): # create Records objects records_x = Records(data=puf_1991, weights=weights_1991, start_year=2009) records_y = Records(data=puf_1991, weights=weights_1991, start_year=2009) # create Policy objects policy_x = Policy() policy_y = Policy() # implement policy_y reform reform = {2013: {"_II_rt7": [0.496], "_PT_rt7": [0.496]}} policy_y.implement_reform(reform) # create two Calculator objects behavior_y = Behavior() calc_x = Calculator(policy=policy_x, records=records_x) calc_y = Calculator(policy=policy_y, records=records_y, behavior=behavior_y) # test incorrect use of Behavior._mtr_xy method with pytest.raises(ValueError): behv = Behavior._mtr_xy(calc_x, calc_y, mtr_of="e00200p", tax_type="nonsense") # vary substitution and income effects in calc_y behavior1 = {2013: {"_BE_sub": [0.3], "_BE_cg": [0.0]}} behavior_y.update_behavior(behavior1) assert behavior_y.has_response() is True assert behavior_y.BE_sub == 0.3 assert behavior_y.BE_inc == 0.0 assert behavior_y.BE_cg == 0.0 calc_y_behavior1 = Behavior.response(calc_x, calc_y) behavior2 = {2013: {"_BE_sub": [0.5], "_BE_cg": [-0.8]}} behavior_y.update_behavior(behavior2) calc_y_behavior2 = Behavior.response(calc_x, calc_y) behavior3 = {2013: {"_BE_inc": [-0.2], "_BE_cg": [-0.8]}} behavior_y.update_behavior(behavior3) calc_y_behavior3 = Behavior.response(calc_x, calc_y) behavior4 = {2013: {"_BE_cg": [-0.8]}} behavior_y.update_behavior(behavior4) calc_y_behavior4 = Behavior.response(calc_x, calc_y) # check that total income tax liability differs across the # four sets of behavioral-response elasticities assert ( calc_y_behavior1.records._iitax.sum() != calc_y_behavior2.records._iitax.sum() != calc_y_behavior3.records._iitax.sum() != calc_y_behavior4.records._iitax.sum() ) # test incorrect _mtr_xy() usage with pytest.raises(ValueError): Behavior._mtr_xy(calc_x, calc_y, mtr_of="e00200p", tax_type="?")
def test_behavioral_response_Calculator(): # create Records objects records_x = Records(data=TAXDATA, weights=WEIGHTS, start_year=2009) records_y = Records(data=TAXDATA, weights=WEIGHTS, start_year=2009) # create Policy objects policy_x = Policy() policy_y = Policy() # implement policy_y reform reform = {2013: {'_II_rt7': [0.496]}} policy_y.implement_reform(reform) # create two Calculator objects behavior_y = Behavior() calc_x = Calculator(policy=policy_x, records=records_x) calc_y = Calculator(policy=policy_y, records=records_y, behavior=behavior_y) # test incorrect use of Behavior._mtr_xy method with pytest.raises(ValueError): behv = Behavior._mtr_xy(calc_x, calc_y, mtr_of='e00200p', tax_type='nonsense') # vary substitution and income effects in calc_y behavior1 = {2013: {'_BE_sub': [0.4], '_BE_inc': [-0.1]}} behavior_y.update_behavior(behavior1) assert behavior_y.has_response() is True assert behavior_y.BE_sub == 0.4 assert behavior_y.BE_inc == -0.1 calc_y_behavior1 = Behavior.response(calc_x, calc_y) behavior2 = {2013: {'_BE_sub': [0.5], '_BE_cg': [0.8]}} behavior_y.update_behavior(behavior2) calc_y_behavior2 = Behavior.response(calc_x, calc_y) behavior3 = {2013: {'_BE_inc': [-0.2], '_BE_cg': [0.6]}} behavior_y.update_behavior(behavior3) calc_y_behavior3 = Behavior.response(calc_x, calc_y) # check that total income tax liability differs across the # three sets of behavioral-response elasticities assert (calc_y_behavior1.records._iitax.sum() != calc_y_behavior2.records._iitax.sum() != calc_y_behavior3.records._iitax.sum()) # test incorrect _mtr_xy() usage with pytest.raises(ValueError): Behavior._mtr_xy(calc_x, calc_y, mtr_of='e00200p', tax_type='?')