Sort the benunit table by benunit_id in create_frs - #462
Merged
Conversation
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>
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.
Fixes #461.
From the 2024-25 FRS release the raw tables are no longer ordered by sernum.
create_frssorts 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 — includingbenunit_iditself — therefore landed on the wrong benefit unit.Verified on the published
frs_2024_25.h5:calculate("benunit_id", map_to="person")disagrees withperson_benunit_idfor 99.99% of persons before the fix and 0% after; sorting changeswould_claim_ucfor 50% of benunits,would_claim_pcfor 42%,is_marriedfor 38%, among others. Person→benunit aggregation was structurally correct throughout (driven byperson_benunit_id).Also switches the
is_marriedassignment to read from the sorted frame rather thanfrs["benunit"]directly.The 2024-25 datasets need rebuilding once this merges.
🤖 Generated with Claude Code