Skip to content

Commit d6ebf70

Browse files
authored
Merge pull request #574 from PolicyEngine/fix-employment-income-zero
Fix employment_income zeroed out in published H5 datasets
2 parents 2755fab + e855342 commit d6ebf70

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

policyengine_us_data/datasets/cps/extended_cps.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,31 @@ def _drop_formula_variables(cls, data):
6464
Variables with formulas, ``adds``, or ``subtracts`` are
6565
recomputed by the simulation engine, so storing them wastes
6666
space and can mislead validation.
67+
68+
Aggregate variables whose ``adds`` include a behavioral-
69+
response input (e.g. ``employment_income_before_lsr``) are
70+
renamed to that input before dropping so the raw data is
71+
preserved under the correct input-variable name.
6772
"""
6873
from policyengine_us import CountryTaxBenefitSystem
6974

7075
tbs = CountryTaxBenefitSystem()
76+
77+
_RESPONSE_SUFFIXES = ("_before_lsr", "_before_response")
78+
for name, var in tbs.variables.items():
79+
if name not in data:
80+
continue
81+
for add_var in getattr(var, "adds", None) or []:
82+
if any(add_var.endswith(s) for s in _RESPONSE_SUFFIXES):
83+
if add_var not in data:
84+
logger.info(
85+
"Renaming %s -> %s before drop",
86+
name,
87+
add_var,
88+
)
89+
data[add_var] = data.pop(name)
90+
break
91+
7192
formula_vars = {
7293
name
7394
for name, var in tbs.variables.items()

policyengine_us_data/datasets/cps/small_enhanced_cps.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,13 @@ def create_sparse_ecps():
125125
if values is not None:
126126
data[variable][time_period] = values
127127

128-
if len(data[variable]) == 0:
129-
del data[variable]
128+
if len(data[variable]) == 0:
129+
del data[variable]
130130

131131
# Validate critical variables exist before writing
132132
critical_vars = [
133133
"household_weight",
134-
"employment_income",
134+
"employment_income_before_lsr",
135135
"household_id",
136136
"person_id",
137137
]

0 commit comments

Comments
 (0)