From 85c63eb451cbd4583702f795dea100f5a17d9a8a Mon Sep 17 00:00:00 2001 From: martinholmer Date: Fri, 2 Mar 2018 11:28:34 -0500 Subject: [PATCH 1/3] Add three ALD amounts into expanded_income --- taxcalc/functions.py | 12 +- taxcalc/tests/test_utils.py | 265 ++++++++++++++++++------------------ taxcalc/utils.py | 2 + 3 files changed, 138 insertions(+), 141 deletions(-) diff --git a/taxcalc/functions.py b/taxcalc/functions.py index 47b9ae89d..b4d6af524 100644 --- a/taxcalc/functions.py +++ b/taxcalc/functions.py @@ -245,16 +245,12 @@ def Adj(e03150, e03210, c03260, (1. - ALD_Tuition_hc) * e03230 + (1. - ALD_DomesticProduction_hc) * e03240 + (1. - ALD_HSADeduction_hc) * e03290 + + (1. - ALD_SelfEmp_HealthIns_hc) * e03270 + + (1. - ALD_IRAContributions_hc) * e03150 + + (1. - ALD_KEOGH_SEP_hc) * e03300 + care_deduction) # add in Form 1040 adjustments that are not included in expanded income: - c02900 = c02900_in_ei + ((1. - ALD_SelfEmp_HealthIns_hc) * e03270 + - # deductible IRA contributions - (1. - ALD_IRAContributions_hc) * e03150 + - (1. - ALD_KEOGH_SEP_hc) * e03300) - # FUTURE: move e03270 term into c02900_in_ei after - # health-insurance-premium imputations are available - # FUTURE: move e03150 and e03300 term into c02900_in_ei after - # pension-contribution imputations are available + c02900 = c02900_in_ei return (c02900, c02900_in_ei) diff --git a/taxcalc/tests/test_utils.py b/taxcalc/tests/test_utils.py index 39607ed1e..49b0d99ef 100644 --- a/taxcalc/tests/test_utils.py +++ b/taxcalc/tests/test_utils.py @@ -89,14 +89,14 @@ def test_create_tables(cps_subsample): expected = [0.00, 0.02, 0.58, - 0.73, - 0.66, - 0.77, + 0.72, + 0.67, 0.78, + 0.77, 0.64, 0.56, - 0.18, - 0.54] + 0.17, + 0.53] tabcol = 'perc_aftertax' if not np.allclose(diff[tabcol].values, expected, atol=0.005, rtol=0.0, equal_nan=True): @@ -114,16 +114,16 @@ def test_create_tables(cps_subsample): expected = [0.00, 0.02, 0.58, - 0.73, - 0.66, - 0.77, + 0.72, + 0.67, 0.78, + 0.77, 0.64, 0.56, 0.22, 0.08, 0.06, - 0.54] + 0.53] tabcol = 'perc_aftertax' if not np.allclose(diff[tabcol].values, expected, atol=0.005, rtol=0.0, equal_nan=True): @@ -142,12 +142,12 @@ def test_create_tables(cps_subsample): 0.01, 0.03, 0.24, - 0.79, - 0.65, - 0.80, + 0.78, 0.66, - 0.77, + 0.76, + 0.67, 0.78, + 0.77, 0.64, 0.56, 0.22, @@ -156,8 +156,8 @@ def test_create_tables(cps_subsample): 0.07, 0.05, 0.03, - np.nan, - 0.54] + 0.00, + 0.53] tabcol = 'perc_aftertax' if not np.allclose(diff[tabcol].values, expected, atol=0.005, rtol=0.0, equal_nan=True): @@ -173,18 +173,18 @@ def test_create_tables(cps_subsample): tax_to_diff='combined') assert isinstance(diff, pd.DataFrame) expected = [171711, - 15109090, - 27004501, - 32822520, - 47104116, - 58462176, - 76622420, - 80620671, - 99816224, - 97243336, + 15725179, + 26767322, + 33151429, + 47689055, + 59102568, + 75654358, + 79779908, + 99445733, + 97489502, 534976765, - 57762030, - 33535321, + 59878155, + 31665362, 5945985] tabcol = 'tot_change' if not np.allclose(diff[tabcol].values, expected, @@ -194,18 +194,18 @@ def test_create_tables(cps_subsample): for val in diff[tabcol].values: print('{:.0f},'.format(val)) expected = [0.03, - 2.82, - 5.05, - 6.14, - 8.80, - 10.93, - 14.32, - 15.07, - 18.66, - 18.18, + 2.94, + 5.00, + 6.20, + 8.91, + 11.05, + 14.14, + 14.91, + 18.59, + 18.22, 100.00, - 10.80, - 6.27, + 11.19, + 5.92, 1.11] tabcol = 'share_of_change' if not np.allclose(diff[tabcol].values, expected, @@ -215,18 +215,18 @@ def test_create_tables(cps_subsample): for val in diff[tabcol].values: print('{:.2f},'.format(val)) expected = [0.02, - 0.61, - 0.74, - 0.68, - 0.76, + 0.63, + 0.72, + 0.69, + 0.77, 0.75, - 0.76, - 0.64, - 0.60, + 0.75, + 0.62, + 0.59, 0.28, - 0.54, - 0.50, - 0.25, + 0.53, + 0.52, + 0.23, 0.06] tabcol = 'perc_aftertax' if not np.allclose(diff[tabcol].values, expected, @@ -236,18 +236,18 @@ def test_create_tables(cps_subsample): for val in diff[tabcol].values: print('{:.2f},'.format(val)) expected = [-0.02, - -0.61, - -0.74, - -0.68, - -0.76, + -0.63, + -0.72, + -0.69, + -0.77, + -0.75, -0.75, - -0.76, - -0.64, - -0.60, + -0.62, + -0.59, -0.28, - -0.54, - -0.50, - -0.25, + -0.53, + -0.52, + -0.23, -0.06] tabcol = 'pc_aftertaxinc' if not np.allclose(diff[tabcol].values, expected, @@ -264,21 +264,20 @@ def test_create_tables(cps_subsample): income_measure='expanded_income', result_type='weighted_sum') assert isinstance(dist, pd.DataFrame) - - expected = [-58221935, - -72550146, - -56958990, - 38876843, - 189178617, - 299215426, - 520668197, - 866858949, - 1486189581, - 6748125761, + expected = [-58122959, + -69644449, + -67116585, + 47133880, + 186484505, + 300964154, + 525599694, + 853149215, + 1490980322, + 6751954525, 9961382302, - 1476862581, - 2137976810, - 3133286370] + 1541661847, + 2070553973, + 3139738705] tabcol = 'iitax' if not np.allclose(dist[tabcol].values, expected, atol=0.5, rtol=0.0): @@ -287,19 +286,19 @@ def test_create_tables(cps_subsample): for val in dist[tabcol].values: print('{:.0f},'.format(val)) expected = [1202, - 14310, - 21578, - 26595, - 49679, - 60867, - 77467, - 83957, - 111739, - 127988, + 13625, + 22333, + 27220, + 48414, + 61445, + 77306, + 83710, + 111716, + 128409, 575381, - 61931, - 52382, - 13675] + 63631, + 51016, + 13762] tabcol = 'num_returns_ItemDed' if not np.allclose(dist[tabcol].tolist(), expected, atol=0.5, rtol=0.0): @@ -307,20 +306,20 @@ def test_create_tables(cps_subsample): print('dist', tabcol) for val in dist[tabcol].values: print('{:.0f},'.format(val)) - expected = [793298613, - 2606927283, - 3921552647, - 5234890176, - 6984210711, - 8827091362, - 11573522927, - 14704490902, - 19948800733, - 44383647223, - 118978432576, - 14316131353, - 16939951346, - 13127564524] + expected = [795716514, + 2643384899, + 3946422611, + 5277286335, + 6986771067, + 8949450219, + 11620796703, + 14774819651, + 20030445723, + 44540701033, + 119565794755, + 14429028533, + 16881618277, + 13230054223] tabcol = 'expanded_income' if not np.allclose(dist[tabcol].tolist(), expected, atol=0.5, rtol=0.0): @@ -328,20 +327,20 @@ def test_create_tables(cps_subsample): print('dist', tabcol) for val in dist[tabcol].values: print('{:.0f},'.format(val)) - expected = [778462286, - 2446216964, - 3640553049, - 4767206919, - 6159451280, - 7728716178, - 10019716982, - 12603485296, - 16644494387, - 34439181731, - 99227485071, - 11465891027, - 13515531036, - 9457759669] + expected = [782122416, + 2478134056, + 3682019346, + 4789142820, + 6179678305, + 7842560545, + 10063413839, + 12700737393, + 16714200777, + 34582837753, + 99814847249, + 11476106014, + 13555463283, + 9551268456] tabcol = 'aftertax_income' if not np.allclose(dist[tabcol].tolist(), expected, atol=0.5, rtol=0.0): @@ -355,18 +354,18 @@ def test_create_tables(cps_subsample): income_measure='expanded_income', result_type='weighted_sum') assert isinstance(dist, pd.DataFrame) - expected = [-103177, - -46726448, - -84362194, - -56072508, - 28797483, - 209682662, - 709220403, - 926584358, - 2937485333, - 2601205994, - 913118778, - 1822551618, + expected = [0, + -46738401, + -83257646, + -56815812, + 32360096, + 201111211, + 710727824, + 914390328, + 2944626799, + 2600275783, + 919111563, + 1825590555, 9961382302] tabcol = 'iitax' if not np.allclose(dist[tabcol], expected, @@ -377,16 +376,16 @@ def test_create_tables(cps_subsample): print('{:.0f},'.format(val)) expected = [0, 1202, - 14310, - 26531, - 31239, - 49201, - 112790, - 96381, - 174803, - 60795, - 5214, - 2914, + 13625, + 27007, + 31380, + 47533, + 113117, + 95870, + 176376, + 61053, + 5289, + 2928, 575381] tabcol = 'num_returns_ItemDed' if not np.allclose(dist[tabcol].tolist(), expected, diff --git a/taxcalc/utils.py b/taxcalc/utils.py index 8b96075e7..b06a20dfd 100644 --- a/taxcalc/utils.py +++ b/taxcalc/utils.py @@ -533,7 +533,9 @@ def weighted_share_of_total(gpdf, colname, total): res2['atinc2'] = res2['aftertax_income'] diffs = diff_table_stats(res2, groupby, baseline_income_measure) diffs['perc_aftertax'] = diffs['tot_change'] / diffs['atinc1'] + diffs['perc_aftertax'].replace(to_replace=np.nan, value=0, inplace=True) diffs['pc_aftertaxinc'] = (diffs['atinc2'] / diffs['atinc1']) - 1.0 + diffs['pc_aftertaxinc'].replace(to_replace=np.nan, value=0, inplace=True) # delete intermediate atinc1 and atinc2 columns del diffs['atinc1'] del diffs['atinc2'] From 27acb6b1154d6349dbcd8df6d7b733b9e0cbb1cb Mon Sep 17 00:00:00 2001 From: martinholmer Date: Fri, 2 Mar 2018 11:32:39 -0500 Subject: [PATCH 2/3] Add three ALD amounts into expanded_income --- taxcalc/functions.py | 44 ++++++++++++++++------------------ taxcalc/records_variables.json | 7 +----- 2 files changed, 21 insertions(+), 30 deletions(-) diff --git a/taxcalc/functions.py b/taxcalc/functions.py index b4d6af524..eb2ab5b77 100644 --- a/taxcalc/functions.py +++ b/taxcalc/functions.py @@ -170,7 +170,7 @@ def Adj(e03150, e03210, c03260, ALD_EarlyWithdraw_hc, ALD_AlimonyPaid_hc, ALD_AlimonyReceived_hc, ALD_EducatorExpenses_hc, ALD_HSADeduction_hc, ALD_IRAContributions_hc, ALD_DomesticProduction_hc, ALD_Tuition_hc, - c02900, c02900_in_ei): + c02900): """ Adj calculates Form 1040 AGI adjustments (i.e., Above-the-Line Deductions) @@ -231,27 +231,23 @@ def Adj(e03150, e03210, c03260, Returns ------- c02900 : total Form 1040 adjustments, which are not included in AGI - - c02900_in_ei : total adjustments included in expanded income """ # Form 2555 foreign earned income deduction is assumed to be zero # Form 1040 adjustments that are included in expanded income: - c02900_in_ei = ((1. - ALD_StudentLoan_hc) * e03210 + - c03260 + - (1. - ALD_EarlyWithdraw_hc) * e03400 + - (1. - ALD_AlimonyPaid_hc) * e03500 + - (1. - ALD_AlimonyReceived_hc) * e00800 + - (1. - ALD_EducatorExpenses_hc) * e03220 + - (1. - ALD_Tuition_hc) * e03230 + - (1. - ALD_DomesticProduction_hc) * e03240 + - (1. - ALD_HSADeduction_hc) * e03290 + - (1. - ALD_SelfEmp_HealthIns_hc) * e03270 + - (1. - ALD_IRAContributions_hc) * e03150 + - (1. - ALD_KEOGH_SEP_hc) * e03300 + - care_deduction) - # add in Form 1040 adjustments that are not included in expanded income: - c02900 = c02900_in_ei - return (c02900, c02900_in_ei) + c02900 = ((1. - ALD_StudentLoan_hc) * e03210 + + c03260 + + (1. - ALD_EarlyWithdraw_hc) * e03400 + + (1. - ALD_AlimonyPaid_hc) * e03500 + + (1. - ALD_AlimonyReceived_hc) * e00800 + + (1. - ALD_EducatorExpenses_hc) * e03220 + + (1. - ALD_Tuition_hc) * e03230 + + (1. - ALD_DomesticProduction_hc) * e03240 + + (1. - ALD_HSADeduction_hc) * e03290 + + (1. - ALD_SelfEmp_HealthIns_hc) * e03270 + + (1. - ALD_IRAContributions_hc) * e03150 + + (1. - ALD_KEOGH_SEP_hc) * e03300 + + care_deduction) + return c02900 @iterate_jit(nopython=True) @@ -273,7 +269,7 @@ def CapGains(p23250, p22250, sep, ALD_StudentLoan_hc, ALD_InvInc_ec_rt, invinc_ec_base, ALD_InvInc_ec_base_RyanBrady, e00200, e00300, e00600, e00650, e00700, e00800, CG_nodiff, CG_ec, CG_reinvest_ec_rt, - ALD_BusinessLosses_c, MARS, c02900_in_ei, + ALD_BusinessLosses_c, MARS, c02900, e00900, e01100, e01200, e01400, e01700, e02000, e02100, e02300, e00400, e02400, c02900, e03210, e03230, e03240, c01000, c23650, ymod, ymod1, invinc_agi_ec): @@ -306,7 +302,7 @@ def CapGains(p23250, p22250, sep, ALD_StudentLoan_hc, max(e00900 + e02000, -ALD_BusinessLosses_c[MARS - 1])) # compute business loss excluded from ymod1 but included in expanded_income excluded_loss = min(e00900 + e02000 + ALD_BusinessLosses_c[MARS - 1], 0.) - c02900_in_ei += excluded_loss + c02900 += excluded_loss if CG_nodiff: # apply QDIV+CG exclusion if QDIV+LTCG receive no special tax treatment qdcg_pos = max(0., e00650 + c01000) @@ -318,7 +314,7 @@ def CapGains(p23250, p22250, sep, ALD_StudentLoan_hc, ymod2 = e00400 + (0.50 * e02400) - c02900 ymod3 = (1. - ALD_StudentLoan_hc) * e03210 + e03230 + e03240 ymod = ymod1 + ymod2 + ymod3 - return (c01000, c23650, ymod, ymod1, invinc_agi_ec, c02900_in_ei) + return (c01000, c23650, ymod, ymod1, invinc_agi_ec, c02900) @iterate_jit(nopython=True) @@ -1812,7 +1808,7 @@ def LumpSumTax(DSI, num, XTOT, @iterate_jit(nopython=True) def ExpandIncome(c00100, ptax_was, e02300, e02400, c02500, benefit_value_total, - c02900_in_ei, e00400, invinc_agi_ec, cmbtp, nontaxable_ubi, + c02900, e00400, invinc_agi_ec, cmbtp, nontaxable_ubi, e01500, e01700, expanded_income): """ ExpandIncome function calculates and returns expanded_income. @@ -1827,7 +1823,7 @@ def ExpandIncome(c00100, ptax_was, e02300, e02400, c02500, benefit_value_total, benefits_value = benefit_value_total - e02300 - e02400 # compute expanded income as AGI plus several additional amounts expanded_income = (c00100 + # adjusted gross income, AGI - c02900_in_ei + # ajustments to AGI + c02900 + # ajustments to AGI e00400 + # non-taxable interest income invinc_agi_ec + # AGI-excluded taxable invest income cmbtp + # AMT taxable income items from Form 6251 diff --git a/taxcalc/records_variables.json b/taxcalc/records_variables.json index 6857f3d90..2046eb1c4 100644 --- a/taxcalc/records_variables.json +++ b/taxcalc/records_variables.json @@ -714,14 +714,9 @@ }, "c02900": { "type": "float", - "desc": "Total of all income adjustments to get AGI", + "desc": "Total of all 'above the line' income adjustments to get AGI", "form": {"2013-2016": "1040 line 36"} }, - "c02900_in_ei": { - "type": "float", - "desc": "search taxcalc/functions.py for how calculated and used", - "form": {"2013-20??": "calculated variable"} - }, "c03260": { "type": "float", "desc": "search taxcalc/functions.py for how calculated and used", From 98ab4936f4cc1b3bb816ca53623cd2bc2b274197 Mon Sep 17 00:00:00 2001 From: martinholmer Date: Fri, 2 Mar 2018 11:56:57 -0500 Subject: [PATCH 3/3] Fix test result caused by adding three ALD amounts to expanded_income --- taxcalc/functions.py | 2 +- taxcalc/tests/reforms.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/taxcalc/functions.py b/taxcalc/functions.py index eb2ab5b77..9919066bf 100644 --- a/taxcalc/functions.py +++ b/taxcalc/functions.py @@ -269,7 +269,7 @@ def CapGains(p23250, p22250, sep, ALD_StudentLoan_hc, ALD_InvInc_ec_rt, invinc_ec_base, ALD_InvInc_ec_base_RyanBrady, e00200, e00300, e00600, e00650, e00700, e00800, CG_nodiff, CG_ec, CG_reinvest_ec_rt, - ALD_BusinessLosses_c, MARS, c02900, + ALD_BusinessLosses_c, MARS, e00900, e01100, e01200, e01400, e01700, e02000, e02100, e02300, e00400, e02400, c02900, e03210, e03230, e03240, c01000, c23650, ymod, ymod1, invinc_agi_ec): diff --git a/taxcalc/tests/reforms.json b/taxcalc/tests/reforms.json index c1263d779..6e2684f33 100644 --- a/taxcalc/tests/reforms.json +++ b/taxcalc/tests/reforms.json @@ -639,7 +639,7 @@ "name": "Repeal TCJA chained CPI indexing", "output_type": "iitax", "compare_with": {}, - "expected": "Tax-Calculator,0.0,-30.2,-32.5,-36.8" + "expected": "Tax-Calculator,0.0,-46.3,-48.7,-53.4" }, "59": {