Repository navigation
Add us_household_net_worth_2022.csv: SCF 2022 household net worth with survey weights - #144
Conversation
A trimmed extract of the Federal Reserve's 2022 Survey of Consumer Finances summary extract (rscfp2022.dta in scfp2022s.zip) for a new lecture on wealth taxation in lecture-python-intro (wealth_tax, in preparation). Four columns: yy1 (household id), y1 (household-implicate id), wgt and networth (2022 dollars); 22,975 rows = 4,595 households x 5 implicates. wgt is already divided by 5, so it sums to 131.3 million households over all rows. Stata's int16/int32 id columns are cast to int64. class: constructed, with builders/us_household_net_worth_2022.py (fetch -> pre-process -> validate -> write). The builder fetches the zip from federalreserve.gov (the server 403s Python's default user agent, so it sends a browser-like one), runs the shared manifest-driven validate() and asserts the household/implicate structure and the weight total. It reproduces the committed bytes under pandas 2.3.3 and 3.0.5. Named under the #113 policy: the variable, no source prefix. The survey year stays in the name because this is a closed survey wave, not a dynamic snapshot, and a later SCF wave would be a new vintage and so a new filename anyway. Licence: the Board's website policy states its information is in the public domain and may be copied and distributed without permission, with citation to the Board requested; the SCF pages add no terms for the public extract. Part of QuantEcon/meta#336 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
mmcky
left a comment
There was a problem hiding this comment.
Thanks @jstac, this is a really nice addition, and it fits the repo's conventions very cleanly. The manifest is thorough: the source.note caveats on the dual-frame sample and the Forbes exclusion are exactly what a reader needs before trusting the upper tail. The licence basis is quoted and dated, and the builder goes one better than its us_adult_heights.py model by also running the shared validate().
I re-ran the builder against the live Fed file under pandas 2.3.3 and 3.0.5. Both runs reproduced the committed hash (0283e50d…) byte for byte, and the upstream .dta matches the hash in the manifest too. As a sanity check, the pooled weighted median net worth comes out at $192,700, against the Fed's published $192,900 for 2022.
A few suggestions. Only the first is one I'd want sorted before merging:
1. Leave consumers: [] until wealth_tax merges. build_catalog.py counts consumers as "in use", so listing the lecture now makes the CATALOG.md headline say "41 read by lectures today" when no lecture reads the file yet. The Used-by link also points at a page that isn't on lecture-python-intro's main yet. And it gives up naming rule 6's "rename freely while consumers: []" window during lecture review, which is when the name is most likely to come up. The repo has done this before: epl_match_goals.csv and japan_earthquakes.csv (#31) landed ahead of their lecture with consumers: [] and a short comment. Then 6cd8f49 added the consumer and moved migration.yml to repointed once QuantEcon/lecture-python-intro#814 merged. The same two steps work here, and the follow-up is needed anyway, because the strict audit fails a landed record once a lecture reads the file. After the change, a regenerated CATALOG.md should read "45 datasets · 40 read by lectures today, 5 awaiting repoint".
2. Pin the upstream .dta hash in the builder (optional). The manifest notes that the Fed has re-issued this extract before, and it records the .dta sha256, but only in prose. bbh_macro_quarterly.py checks its upstream file's hash in fetch() and stops with a clear message on a mismatch. Doing the same here would make a future re-issue announce itself when the builder fetches, pointing at the decision between a correction in place and a new vintage, rather than showing up as a red consumed-files check with no obvious cause.
3. A descriptive user agent instead of Mozilla/5.0 (optional). I tried the Fed server: the default Python-urllib agent gets a 403, but QuantEcon-data-lectures-builder/1.0 (+https://github.com/QuantEcon/data-lectures) is accepted. So the builder doesn't need to present itself as a browser.
4. Tiny nit: source.note has a stray line break mid-sentence (above $1 / million) and some / extreme…). It renders fine; the source just reads a little ragged.
I'm happy to help with any of these. If it's easiest, I can push the changes to this branch myself; just let me know.
What
A new constructed dataset,
lectures/us_household_net_worth_2022.csv, with its manifest and builder: a four-column extract of the Federal Reserve Board's 2022 Survey of Consumer Finances (SCF) summary extract public data.yy1y110 * yy1 + implicate(1–5); uniquewgtnetworth22,975 rows = 4,595 households x 5 implicates, no nulls, sorted by
y1. Sum ofwgtover all rows = 131,306,389 (about 131.3 million US households). 872 KB, plain git.Why
For a new lecture,
wealth_tax, in QuantEcon/lecture-python-intro (in preparation, not yet merged). It needs weighted household net worth, including the upper tail, which the SCF's list sample is designed to capture. Listed inconsumerswith a note saying the lecture is not merged yet;migration.ymlrecords the dataset aslanded(pilot: P5,prior_pattern: none) until that lecture merges.Source
rscfp2022.dta. Archive sha2563bb4d890…9cc9d80,.dtasha2566b8dd2d9…4aa4bafd1(both recorded in full in the manifest).source.note, taken from the codebook: dual-frame sample (area-probability plus an IRS SOI list sample that oversamples wealthy families); the Forbes 400 are excluded by design, and 7 respondents at or above the Forbes cutoff were removed from the public file (4,602 -> 4,595); dollar items are rounded (randomized, mean-preserving; to the nearest $10k above $1M), and some cases were blurred or re-imputed for disclosure; there are five implicates per household.Licence
The Board's website policy (https://www.federalreserve.gov/disclaimer.htm, "Copyright/trademark") says: "Unless otherwise indicated, information on Board's website is in the public domain and may be copied and distributed without permission. Please cite to the Board as the source of the information." The SCF pages publish the summary extract for public download and add no further terms. Their restrictions cover the confidential internal data only. Recorded as
US Government work — public domain,redistribution: permitted,verified: 2026-09-29, with the quoted basis inlicense.note.Naming
Named under the #113 policy: the variable (
household_net_worth) with aus_qualifier, and noscf_source prefix. The survey year is kept in the name because this is a closed survey wave (constructed, not a dynamic snapshot). A later SCF wave would count as a new vintage and get a new filename anyway ("Corrections vs vintages"). The SCF's unit is the "family" (primary economic unit). The manifest says that "household" follows the lectures' usage.How it was built and validated
builders/us_household_net_worth_2022.py: fetch -> pre-process -> validate -> write. The Fed server returns 403 to Python's default urllib user agent, so the fetch sendsUser-Agent: Mozilla/5.0. Stata storesyy1as int16 andy1as int32; both are cast to int64 before any arithmetic._validate.validate()and then checks exactly 22,975 rows, 4,595 households with 5 implicates each,y1 = 10*yy1 + implicate, unique and sortedy1, positive weights, and a weight total between 130M and 133M.0283e50d…7b17a106a). The values also match the.dtaexactly foryy1,y1andnetworth. Forwgt, pandas' default CSV float parser differs by up to 4e-12.scripts/validate_datasets.pyunder both pandas versions (45/45 pass);.github/scripts/check_consumed_files.py(0 errors);scripts/build_catalog.py(CATALOG.md regenerated and committed); andscripts/build_audit.py all --strictagainst fresh shallow clones of the 8 lecture repos (exit 0, no warnings).validate_datasets.py --buildersfails locally only becausewbgapiis not installed there, and that check does not touch this dataset.Also updated: the
builders/README.mdcoverage table and the dataset count in theAGENTS.mdrepo map.migration.ymlgets its new record, which carries this PR's number.Consumer URL (CPython):
https://github.com/QuantEcon/data-lectures/raw/main/lectures/us_household_net_worth_2022.csvPart of QuantEcon/meta#336
🤖 Generated with Claude Code