Skip to content

Commit

Permalink
Merge pull request #169 from PSLmodels/enhance-taxexp-output
Browse files Browse the repository at this point in the history
Include baseline iitax and paytax comparisons in test_tax_expenditure.py
  • Loading branch information
martinholmer authored Aug 28, 2024
2 parents 23b1fee + d5d8c6d commit 140f588
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
2 changes: 2 additions & 0 deletions tests/expected_tax_expenditures
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
YR,KIND,EST= 2023 paytax 1523.8
YR,KIND,EST= 2023 iitax 2210.2
YR,KIND,EST= 2023 ctc 129.2
YR,KIND,EST= 2023 eitc 75.8
Expand All @@ -6,6 +7,7 @@ YR,KIND,EST= 2023 niit -57.0
YR,KIND,EST= 2023 cgqd_tax_preference 234.5
YR,KIND,EST= 2023 qbid 57.0
YR,KIND,EST= 2023 salt 20.7
YR,KIND,EST= 2026 paytax 1767.4
YR,KIND,EST= 2026 iitax 2785.9
YR,KIND,EST= 2026 ctc 46.8
YR,KIND,EST= 2026 eitc 84.8
Expand Down
18 changes: 6 additions & 12 deletions tests/test_tax_expenditures.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ def test_tax_expenditures_differences(
tmd_weights_path,
tmd_growfactors_path,
):
abstol = 0.11 # absolute np.allclose tolerance in billions of dollars
reltol = 0.003 # relative np.allclose tolerance
_ = get_tax_expenditure_results(
tmd_variables,
2021, # input variables year
2021, # input variables data year
2023, # simulation year for tax expenditure estimates
tmd_weights_path,
tmd_growfactors_path,
)
_ = get_tax_expenditure_results(
tmd_variables,
2021, # input variables year
2021, # input variables data year
2026, # simulation year for tax expenditure estimates
tmd_weights_path,
tmd_growfactors_path,
Expand All @@ -37,13 +37,9 @@ def test_tax_expenditures_differences(
exp_path = tests_folder / "expected_tax_expenditures"
actdf = pd.read_csv(act_path, sep=" ", header=None)
expdf = pd.read_csv(exp_path, sep=" ", header=None)

actdf = actdf[actdf.iloc[:, 2] != "iitax"]
expdf = expdf[expdf.iloc[:, 2] != "iitax"]

actval = actdf.iloc[:, 3]
expval = expdf.iloc[:, 3]
same = np.allclose(actval, expval, rtol=0.0, atol=abstol)
actval = actdf.iloc[:, 3].to_numpy(dtype=np.float64)
expval = expdf.iloc[:, 3].to_numpy(dtype=np.float64)
same = np.allclose(actval, expval, atol=0.0, rtol=reltol)
if same:
return
# if same is False
Expand All @@ -57,7 +53,5 @@ def test_tax_expenditures_differences(
if len(diffs) > 0:
emsg = "\nThere are actual vs expect tax expenditure differences:\n"
for line in diffs:
if "iitax" in line:
continue
emsg += line
raise ValueError(emsg)
9 changes: 6 additions & 3 deletions tmd/utils/taxcalc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ def get_tax_expenditure_results(
weights=weights_file_path,
growfactors=growfactors_file_path,
)
tax_revenue_baseline = (baseline.iitax * baseline.s006).sum() / 1e9
itax_baseline = (baseline.iitax * baseline.s006).sum() / 1e9
ptax_baseline = (baseline.payrolltax * baseline.s006).sum() / 1e9

te_results = {}
for reform_name, reform in te_reforms.items():
Expand All @@ -137,7 +138,7 @@ def get_tax_expenditure_results(
tax_revenue_reform = (
reform_results.iitax * reform_results.s006
).sum() / 1e9
revenue_effect = tax_revenue_baseline - tax_revenue_reform
revenue_effect = itax_baseline - tax_revenue_reform
te_results[reform_name] = round(-revenue_effect, 1)

taxexp_path = STORAGE_FOLDER / "output" / "tax_expenditures"
Expand All @@ -147,7 +148,9 @@ def get_tax_expenditure_results(
open_mode = "a"
year = simulation_year
with open(taxexp_path, open_mode) as tefile:
res = f"YR,KIND,EST= {year} iitax {tax_revenue_baseline:.1f}\n"
res = f"YR,KIND,EST= {year} paytax {ptax_baseline:.1f}\n"
tefile.write(res)
res = f"YR,KIND,EST= {year} iitax {itax_baseline:.1f}\n"
tefile.write(res)
for reform, estimate in te_results.items():
res = f"YR,KIND,EST= {year} {reform} {estimate}\n"
Expand Down

0 comments on commit 140f588

Please sign in to comment.