Skip to content

Add us_household_net_worth_2022.csv: SCF 2022 household net worth with survey weights - #144

Merged
jstac merged 2 commits into
mainfrom
add-us-household-net-worth-2022
Sep 30, 2026
Merged

jstac merged 2 commits into
mainfrom
add-us-household-net-worth-2022

Conversation

@jstac

@jstac jstac commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

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.

column dtype meaning
yy1 int64 household id (repeated across its five implicates)
y1 int64 household-implicate id, 10 * yy1 + implicate (1–5); unique
wgt float64 survey weight, already divided by 5
networth float64 net worth, 2022 dollars (can be negative)

22,975 rows = 4,595 households x 5 implicates, no nulls, sorted by y1. Sum of wgt over 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 in consumers with a note saying the lecture is not merged yet; migration.yml records the dataset as landed (pilot: P5, prior_pattern: none) until that lecture merges.

Source

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 in license.note.

Naming

Named under the #113 policy: the variable (household_net_worth) with a us_ qualifier, and no scf_ 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 sends User-Agent: Mozilla/5.0. Stata stores yy1 as int16 and y1 as int32; both are cast to int64 before any arithmetic.
  • The validate stage runs the shared manifest-driven _validate.validate() and then checks exactly 22,975 rows, 4,595 households with 5 implicates each, y1 = 10*yy1 + implicate, unique and sorted y1, positive weights, and a weight total between 130M and 133M.
  • The builder was run against the live Fed URL under pandas 2.3.3 and 3.0.5. Both runs gave identical bytes (sha256 0283e50d…7b17a106a). The values also match the .dta exactly for yy1, y1 and networth. For wgt, pandas' default CSV float parser differs by up to 4e-12.
  • Local checks, all green: scripts/validate_datasets.py under both pandas versions (45/45 pass); .github/scripts/check_consumed_files.py (0 errors); scripts/build_catalog.py (CATALOG.md regenerated and committed); and scripts/build_audit.py all --strict against fresh shallow clones of the 8 lecture repos (exit 0, no warnings). validate_datasets.py --builders fails locally only because wbgapi is not installed there, and that check does not touch this dataset.

Also updated: the builders/README.md coverage table and the dataset count in the AGENTS.md repo map. migration.yml gets 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.csv

Part of QuantEcon/meta#336

🤖 Generated with Claude Code

jstac and others added 2 commits September 29, 2026 11:04
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]>

@mmcky mmcky left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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