Preserve authoritative SPM unit ids through synthesis (#113)#118
Merged
Conversation
SPM unit ids from the source are eCPS-quality (~1.04 units/household). The old all-or-nothing preservation discarded the whole column if ANY id was missing, collapsing to one SPM unit per household (~1.00) -- a large share of the #113 SPM gap. Add _preserve_present_group_ids: keep every present id's grouping, fold missing rows into their household's existing unit (never fabricating one), and give fully-missing households a single fallback unit. Tax-unit ids are NOT preserved -- they are reconstructed (they are unreliable; see #113). Validated on real CPS ASEC: spm/hh stays ~1.04 with present ids and degrades gracefully with missing ones (vs 1.00 before). 5 tests. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
… preservation Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #113. Implements the maintainer directive: keep the source SPM unit ids; tax-unit ids are reconstructed (unreliable) not preserved.
The bug
The source records carry eCPS-quality authoritative entity ids — measured on the real CPS ASEC cache:
spm_unit_id= 1.0428 units/household,tax_unit_id= 1.3746. But_assign_family_and_spm_unitspreservedspm_unit_idonly when the column was completely present (_normalized_complete_existing_group_idsreturnsNoneon any missing id). Synthesis leaves some records without an id, so the whole column was discarded and SPM units were regenerated as one per household (~1.00/hh) — a large share of the #113 SPM gap (output measured at 1.005–1.015/hh).The fix
_preserve_present_group_ids: keep every present id's grouping; fold rows with a missing id into their household's existing unit (never fabricating a spurious one); give fully-missing households a single fallback unit. SPM assignment now uses it; tax-unit construction is unchanged (reconstructed, not preserved).Validation (real CPS ASEC, 55,762 households)
Present households keep 1.04; only genuinely-missing ones degrade — no inflation, no collapse.
Tests
5 new (
test_us_spm_preservation.py): present preserved, missing folds (not split), fully-missing→fallback, all-missing→None, end-to-end partial preservation.🤖 Generated with Claude Code