Skip to content

Sort the benunit table by benunit_id in create_frs - #462

Merged
vahid-ahmadi merged 3 commits into
mainfrom
fix/sort-benunit-table
Aug 18, 2026
Merged

Sort the benunit table by benunit_id in create_frs#462
vahid-ahmadi merged 3 commits into
mainfrom
fix/sort-benunit-table

Conversation

@vahid-ahmadi

Copy link
Copy Markdown
Collaborator

Fixes #461.

From the 2024-25 FRS release the raw tables are no longer ordered by sernum. create_frs sorts the household table to handle this, but the benunit table kept its raw TSV order while the model declares benunit entities in sorted-id order (np.unique(benunit_id)). Every benunit-level variable — including benunit_id itself — therefore landed on the wrong benefit unit.

Verified on the published frs_2024_25.h5: calculate("benunit_id", map_to="person") disagrees with person_benunit_id for 99.99% of persons before the fix and 0% after; sorting changes would_claim_uc for 50% of benunits, would_claim_pc for 42%, is_married for 38%, among others. Person→benunit aggregation was structurally correct throughout (driven by person_benunit_id).

Also switches the is_married assignment to read from the sorted frame rather than frs["benunit"] directly.

The 2024-25 datasets need rebuilding once this merges.

🤖 Generated with Claude Code

vahid-ahmadi and others added 2 commits August 18, 2026 12:32
From the 2024-25 FRS release the raw tables are no longer ordered by
sernum. The household table is already sorted for this reason, but the
benunit table was not, so every benunit-level variable (including
benunit_id itself) was assigned to the wrong benefit unit relative to
the model's sorted entity order.

Fixes #461

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@vahid-ahmadi
vahid-ahmadi requested a review from MaxGhenis August 18, 2026 11:32
@vahid-ahmadi
vahid-ahmadi merged commit 6591b70 into main Aug 18, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Benunit table not sorted by benunit_id, scrambling all benunit-level variables (2024-25 FRS onward)

1 participant