From 92f689592a33b01bbfe28c7757cc8911f962988c Mon Sep 17 00:00:00 2001 From: Martin Holmer Date: Thu, 7 Feb 2019 13:50:47 -0500 Subject: [PATCH 1/6] Strengthen test_sub_effect_independence --- behresp/tests/test_behavior.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/behresp/tests/test_behavior.py b/behresp/tests/test_behavior.py index 9117c22..57e0d76 100644 --- a/behresp/tests/test_behavior.py +++ b/behresp/tests/test_behavior.py @@ -148,8 +148,9 @@ def test_sub_effect_independence(): # with one having large long-term capital gains and the other having # no long-term capital gains input_csv = (u'RECID,MARS,e00200,e00200p,p23250\n' - u'1,1,1000000,1000000,500000\n' - u'2,1,1000000,1000000,0\n') + u'1,1,1000000,1000000,0 \n' + u'2,1,1000000,1000000,500000\n' + u'3,1,1000000,1000000,-50000\n') recs = tc.Records(data=pd.read_csv(StringIO(input_csv)), start_year=refyear, gfactors=None, weights=None) @@ -164,15 +165,19 @@ def test_sub_effect_independence(): df1, df2 = response(calc1, calc2, beh_dict) del calc1 del calc2 - # compute change in taxable income for each of the two filing units + # compute change in taxable income for each of the three filing units chg_funit1 = df2['c04800'][0] - df1['c04800'][0] # funit with RECID=1 chg_funit2 = df2['c04800'][1] - df1['c04800'][1] # funit with RECID=2 + chg_funit3 = df2['c04800'][2] - df1['c04800'][2] # funit with RECID=3 del df1 del df2 # confirm reform reduces taxable income when assuming substitution effect assert chg_funit1 < 0 assert chg_funit2 < 0 - # confirm change in taxable income is same for the two filing units - assert np.allclose(chg_funit1, chg_funit2) + assert chg_funit3 < 0 + # confirm change in taxable income is same for all three filing units + assert np.allclose(chg_funit2, chg_funit1) + assert np.allclose(chg_funit3, chg_funit1) del chg_funit1 del chg_funit2 + del chg_funit3 From 528f9f2e6d886db0f5ef62b054d11d3b0bf8818f Mon Sep 17 00:00:00 2001 From: matthjensen Date: Thu, 14 Feb 2019 07:38:16 -0500 Subject: [PATCH 2/6] resolve test failures --- behresp/behavior.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/behresp/behavior.py b/behresp/behavior.py index 1a34a76..ccf1f55 100644 --- a/behresp/behavior.py +++ b/behresp/behavior.py @@ -202,7 +202,8 @@ def _mtr12(calc__1, calc__2, mtr_of='e00200p', tax_type='combined'): pch = ((1. - mtr2) / (1. - mtr1)) - 1. # Note: c04800 is filing unit's taxable income and # p23250 is filing units' long-term capital gains - taxinc_less_ltcg = calc1.array('c04800') - calc1.array('p23250') + taxinc_less_ltcg = (calc1.array('c04800') - + np.maximum(-3000, calc1.array('p23250'))) sub = (pvalue['BE_sub'] * pch * taxinc_less_ltcg) # calculate magnitude of income effect if pvalue['BE_inc'] == 0.0: From 4931dced305061e0fd3033d2fe93c84ffe6c4997 Mon Sep 17 00:00:00 2001 From: matthjensen Date: Thu, 14 Feb 2019 07:44:46 -0500 Subject: [PATCH 3/6] strengthen test sub_effect_independence --- behresp/tests/test_behavior.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/behresp/tests/test_behavior.py b/behresp/tests/test_behavior.py index 57e0d76..f8880e3 100644 --- a/behresp/tests/test_behavior.py +++ b/behresp/tests/test_behavior.py @@ -150,7 +150,8 @@ def test_sub_effect_independence(): input_csv = (u'RECID,MARS,e00200,e00200p,p23250\n' u'1,1,1000000,1000000,0 \n' u'2,1,1000000,1000000,500000\n' - u'3,1,1000000,1000000,-50000\n') + u'3,1,1000000,1000000,-50000\n' + u'4,3,1000000,1000000,-50000\n') recs = tc.Records(data=pd.read_csv(StringIO(input_csv)), start_year=refyear, gfactors=None, weights=None) @@ -169,15 +170,19 @@ def test_sub_effect_independence(): chg_funit1 = df2['c04800'][0] - df1['c04800'][0] # funit with RECID=1 chg_funit2 = df2['c04800'][1] - df1['c04800'][1] # funit with RECID=2 chg_funit3 = df2['c04800'][2] - df1['c04800'][2] # funit with RECID=3 + chg_funit4 = df2['c04800'][3] - df1['c04800'][3] # funit with RECID=3 del df1 del df2 # confirm reform reduces taxable income when assuming substitution effect assert chg_funit1 < 0 assert chg_funit2 < 0 assert chg_funit3 < 0 + assert chg_funit4 < 0 # confirm change in taxable income is same for all three filing units assert np.allclose(chg_funit2, chg_funit1) assert np.allclose(chg_funit3, chg_funit1) + assert np.allclose(chg_funit4, chg_funit1) del chg_funit1 del chg_funit2 del chg_funit3 + del chg_funit4 From 6e2726467c3424c0a1b7a2fb436363406b9077cf Mon Sep 17 00:00:00 2001 From: matthjensen Date: Thu, 14 Feb 2019 07:46:20 -0500 Subject: [PATCH 4/6] resolve test failures --- behresp/behavior.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/behresp/behavior.py b/behresp/behavior.py index ccf1f55..94ce8f0 100644 --- a/behresp/behavior.py +++ b/behresp/behavior.py @@ -203,7 +203,8 @@ def _mtr12(calc__1, calc__2, mtr_of='e00200p', tax_type='combined'): # Note: c04800 is filing unit's taxable income and # p23250 is filing units' long-term capital gains taxinc_less_ltcg = (calc1.array('c04800') - - np.maximum(-3000, calc1.array('p23250'))) + np.maximum(-3000/calc1.array('sep'), + calc1.array('p23250'))) sub = (pvalue['BE_sub'] * pch * taxinc_less_ltcg) # calculate magnitude of income effect if pvalue['BE_inc'] == 0.0: From a707180145362b462aaa660a1957d280da0286b0 Mon Sep 17 00:00:00 2001 From: matthjensen Date: Thu, 14 Feb 2019 07:56:17 -0500 Subject: [PATCH 5/6] strenghten but do not break test_sub_effect_independence --- behresp/tests/test_behavior.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/behresp/tests/test_behavior.py b/behresp/tests/test_behavior.py index f8880e3..c1f4458 100644 --- a/behresp/tests/test_behavior.py +++ b/behresp/tests/test_behavior.py @@ -147,11 +147,12 @@ def test_sub_effect_independence(): # specify input consisting of two filing units with high earnings, but # with one having large long-term capital gains and the other having # no long-term capital gains - input_csv = (u'RECID,MARS,e00200,e00200p,p23250\n' - u'1,1,1000000,1000000,0 \n' - u'2,1,1000000,1000000,500000\n' - u'3,1,1000000,1000000,-50000\n' - u'4,3,1000000,1000000,-50000\n') + input_csv = (u'RECID,MARS,e00200,e00200p,p23250,p22250\n' + u'1,1,1000000,1000000,0,0 \n' + u'2,1,1000000,1000000,500000,0\n' + u'3,1,1000000,1000000,-50000,0\n' + u'4,3,1000000,1000000,-50000,0\n' + u'5,1,1000000,1000000,-4000,-2000\n') recs = tc.Records(data=pd.read_csv(StringIO(input_csv)), start_year=refyear, gfactors=None, weights=None) @@ -170,7 +171,8 @@ def test_sub_effect_independence(): chg_funit1 = df2['c04800'][0] - df1['c04800'][0] # funit with RECID=1 chg_funit2 = df2['c04800'][1] - df1['c04800'][1] # funit with RECID=2 chg_funit3 = df2['c04800'][2] - df1['c04800'][2] # funit with RECID=3 - chg_funit4 = df2['c04800'][3] - df1['c04800'][3] # funit with RECID=3 + chg_funit4 = df2['c04800'][3] - df1['c04800'][3] # funit with RECID=4 + chg_funit5 = df2['c04800'][4] - df1['c04800'][4] # funit with RECID=5 del df1 del df2 # confirm reform reduces taxable income when assuming substitution effect @@ -178,11 +180,14 @@ def test_sub_effect_independence(): assert chg_funit2 < 0 assert chg_funit3 < 0 assert chg_funit4 < 0 + assert chg_funit5 < 0 # confirm change in taxable income is same for all three filing units assert np.allclose(chg_funit2, chg_funit1) assert np.allclose(chg_funit3, chg_funit1) assert np.allclose(chg_funit4, chg_funit1) + assert np.allclose(chg_funit5, chg_funit1) del chg_funit1 del chg_funit2 del chg_funit3 del chg_funit4 + del chg_funit5 From aaf16a8c7b1908bcc34e0c65253747642cbef763 Mon Sep 17 00:00:00 2001 From: matthjensen Date: Wed, 20 Feb 2019 16:12:01 -0500 Subject: [PATCH 6/6] improve docs --- behresp/tests/test_behavior.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/behresp/tests/test_behavior.py b/behresp/tests/test_behavior.py index c1f4458..a8b040b 100644 --- a/behresp/tests/test_behavior.py +++ b/behresp/tests/test_behavior.py @@ -144,9 +144,12 @@ def test_sub_effect_independence(): beh_json = """{ "BE_sub": {"2013": 0.25} }""" - # specify input consisting of two filing units with high earnings, but - # with one having large long-term capital gains and the other having - # no long-term capital gains + # specify high earning filing units with important charachteristics: + # Single without long-term capital gains + # Single with long-term capital gains + # Single with long-term capital loss + # Married filing separately with long-term capital loss + # Single with long-term capital loss and short-term capital loss input_csv = (u'RECID,MARS,e00200,e00200p,p23250,p22250\n' u'1,1,1000000,1000000,0,0 \n' u'2,1,1000000,1000000,500000,0\n' @@ -167,7 +170,7 @@ def test_sub_effect_independence(): df1, df2 = response(calc1, calc2, beh_dict) del calc1 del calc2 - # compute change in taxable income for each of the three filing units + # compute change in taxable income for each of the filing units chg_funit1 = df2['c04800'][0] - df1['c04800'][0] # funit with RECID=1 chg_funit2 = df2['c04800'][1] - df1['c04800'][1] # funit with RECID=2 chg_funit3 = df2['c04800'][2] - df1['c04800'][2] # funit with RECID=3 @@ -181,7 +184,7 @@ def test_sub_effect_independence(): assert chg_funit3 < 0 assert chg_funit4 < 0 assert chg_funit5 < 0 - # confirm change in taxable income is same for all three filing units + # confirm change in taxable income is same for all filing units assert np.allclose(chg_funit2, chg_funit1) assert np.allclose(chg_funit3, chg_funit1) assert np.allclose(chg_funit4, chg_funit1)