|
10 | 10 | from policyengine_us_data.datasets.puf import PUF, PUF_2024 |
11 | 11 | from policyengine_us_data.storage import STORAGE_FOLDER |
12 | 12 | from policyengine_us_data.utils.mortgage_interest import ( |
| 13 | + STRUCTURAL_MORTGAGE_VARIABLES, |
13 | 14 | convert_mortgage_interest_to_structural_inputs, |
14 | 15 | impute_tax_unit_mortgage_balance_hints, |
15 | | - supports_structural_mortgage_inputs, |
16 | 16 | ) |
| 17 | +from policyengine_us_data.utils.policyengine import has_policyengine_us_variables |
17 | 18 | from policyengine_us_data.utils.retirement_limits import ( |
18 | 19 | get_retirement_limits, |
19 | 20 | get_se_pension_limits, |
20 | 21 | ) |
21 | 22 |
|
22 | 23 | logger = logging.getLogger(__name__) |
23 | 24 |
|
| 25 | + |
| 26 | +def _supports_structural_mortgage_inputs() -> bool: |
| 27 | + return has_policyengine_us_variables(*STRUCTURAL_MORTGAGE_VARIABLES) |
| 28 | + |
| 29 | + |
24 | 30 | # CPS-only variables that should be QRF-imputed for the PUF clone half |
25 | 31 | # instead of naively duplicated from the CPS donor. These are |
26 | 32 | # income-correlated variables that exist only in the CPS; demographics, |
@@ -450,14 +456,15 @@ def generate(self): |
450 | 456 | ) |
451 | 457 |
|
452 | 458 | new_data = self._rename_imputed_to_inputs(new_data) |
453 | | - new_data = impute_tax_unit_mortgage_balance_hints( |
454 | | - new_data, |
455 | | - self.time_period, |
456 | | - ) |
457 | | - new_data = convert_mortgage_interest_to_structural_inputs( |
458 | | - new_data, |
459 | | - self.time_period, |
460 | | - ) |
| 459 | + if _supports_structural_mortgage_inputs(): |
| 460 | + new_data = impute_tax_unit_mortgage_balance_hints( |
| 461 | + new_data, |
| 462 | + self.time_period, |
| 463 | + ) |
| 464 | + new_data = convert_mortgage_interest_to_structural_inputs( |
| 465 | + new_data, |
| 466 | + self.time_period, |
| 467 | + ) |
461 | 468 | new_data = self._drop_formula_variables(new_data) |
462 | 469 | self.save_dataset(new_data) |
463 | 470 |
|
@@ -492,7 +499,7 @@ def _rename_imputed_to_inputs(cls, data): |
492 | 499 | @classmethod |
493 | 500 | def _keep_formula_vars(cls): |
494 | 501 | keep = set(cls._KEEP_FORMULA_VARS) |
495 | | - if not supports_structural_mortgage_inputs(): |
| 502 | + if not _supports_structural_mortgage_inputs(): |
496 | 503 | keep.add("interest_deduction") |
497 | 504 | return keep |
498 | 505 |
|
|
0 commit comments