Skip to content

Collect ACS margins of error (redo of #173) - #177

Merged
iansargent merged 5 commits into
mainfrom
db/acs-moe-collection
Nov 3, 2026
Merged

iansargent merged 5 commits into
mainfrom
db/acs-moe-collection

Conversation

@duaneatat

Copy link
Copy Markdown
Collaborator

This is the same change Ian approved in #173, unchanged. #173 merged into its stacked base branch (db/backend-test-suite) instead of main, so its commits never reached main. This PR puts the same four commits on main; the only addition is a merge of main to bring the branch up to date. See #173 for the description.

The B-table scrapers (demographics, economic, education, housing) kept
Census annotation codes such as -666666666 as real numbers and filled
missing components with 0 before summing. Tiny towns like Averill and
Glastenbury ended up with a median household income of -666,666,666,
and a sum could include a sentinel or skip a missing part.

Negative estimates are now missing, and a sum with any missing
component is null rather than partial. Also points test_base.py at
data_collection.base; it imported the deleted data_collection_OLD and
could not be collected.
The B-table scrapers fetched only estimates. They now request each
table with group(), which returns every estimate and margin of error and
stays under the API's 50-variable limit (B01001 alone needs 49 codes),
and each tidy row gains Value_MOE and Percent_MOE (percentage points).

Margins follow the Census approximations: root sum of squares for sums,
counting only the largest margin among zero estimates, and the
proportion formula for percents, with the ratio form when the term under
the root is negative or zero (a 100% share). -555555555 margins count as
zero; other negative codes are missing.
group(DPxx) already returns each estimate's margin (M) and each
percent's margin (PM), but the profile variables.json lists only E and
PE codes, so the tidy merge dropped them. Each tidy row now carries its
margin as MOE. They're a column rather than rows of their own so that
selectors on Measure (e.g. ILIKE 'Percent%') don't pick them up.
@duaneatat
duaneatat requested review from FWJK1 and iansargent and removed request for iansargent November 2, 2026 15:59
@duaneatat duaneatat changed the title Collect ACS margins of error (re-land of #173) Collect ACS margins of error (redo of #173) Nov 2, 2026
@duaneatat
duaneatat requested a review from iansargent November 2, 2026 18:44
@iansargent
iansargent merged commit 5b56f81 into main Nov 3, 2026
4 checks passed
@duaneatat
duaneatat deleted the db/acs-moe-collection branch November 3, 2026 13:49
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.

2 participants