Browsed by
Tag: nsfg

Still Marrying Later: Update With New Data

Still Marrying Later: Update With New Data

In December 2024 I wrote that young Americans are marrying later, or never, based on the National Survey of Family Growth (NSFG) from 1982 through 2022–2023. The National Center for Health Statistics has now released the 2024–2025 survey, so I ran the analysis again. The new data lets us follow people born in the 1990s into their mid-thirties for the first time.

What changed, besides the data

Since the last update, there are two changes in the analysis:

  • First, the data now comes from pdt-nsfg, which reads the NSFG public-use files, gives each variable one name across all eleven surveys, and documents what changed from one survey to the next. This new repository is part of the Public Data Toolkit (more about that below).
  • Second, the shaded intervals are now computed from the survey design. The NSFG samples clusters of households within strata, and samples some groups at higher rates than others. My earlier intervals came from resampling respondents in proportion to their weights. That gets the estimates right, but the intervals were too narrow, because they ignored the effect of clustering and effective sample size. The new intervals account for both, so they are about 50% wider. The estimates themselves are about the same.

The results

In the figures, each colored line is the estimated percentage of people in a birth cohort who have ever married, by age, with a shaded 90% interval. The gray lines are the previous estimates, from the 1982–2023 data.

Women: percent ever married, previous and new estimates

For women, the gray lines are mostly hidden under the new ones, because the estimates agree: where both exist, they differ by less than a point at almost every age. The largest difference, 2.5 points, is near the end of the 1980s curve, where few respondents remain. What’s new is at the right-hand ends of the youngest cohorts. The curve for women born in the 1990s used to stop at age 32; now it reaches 35.

By age 35, 63% of women born in the 1990s had married. For the 1980s cohort, the figure at the same age is 70%; for the 1970s cohort, 77%; and for the 1950s cohort, 87%.

The youngest cohort, women born in the 2000s, can now be followed to almost 23. By 22, 7.5% of them had married (5.0 to 10), compared with 12% of the 1990s cohort and 18% of the 1980s cohort at the same age.

Men: percent ever married, previous and new estimates

The pattern for men is similar. By age 34, 57% of men born in the 1990s had married (53 to 62), compared with 61% of the 1980s cohort and 68% of the 1970s cohort. The intervals for the 1990s and 1980s overlap, so the data can’t yet distinguish those two cohorts at that age.

For men born in the 2000s, the new estimate is higher than the old one: 6.1% married by age 23 (3.5 to 8.7), where the previous estimate was 3.3%. That cohort is still small and young, and the estimate rests on a few dozen marriages, so I would not read much into the change except that the earlier number was probably too low.

Caveats

Since 2015, the public-use files report the year of first marriage and age in whole years, not exact dates, so ages at marriage for recent surveys are known only to within about two years. The estimates account for that by repeatedly drawing plausible dates within each respondent’s range; that uncertainty is part of the intervals.

Each curve stops where the estimate becomes unreliable. The right-hand ends of the youngest cohorts are the least certain parts of each figure.

Finally, these are cohorts that have not finished marrying. A lower curve at 35 doesn’t mean the same share will never marry; it means fewer have married by 35. Some people marry after 35; women born in the 1980s went from 70% married at 35 to 76% at 40. But each recent cohort has reached 40 further behind than the one before: 87% of women born in the 1960s had married by 40, 81% of the 1970s cohort, and 76% of the 1980s cohort.

The analysis, data processing, and figures are in the MarriageNSFG repository.

The Public Data Toolkit

Many important public datasets are hard to use. Variable names and codings change from one release to the next, the metadata lives in PDF codebooks, conventions for missing values vary, and analysis code ends up tied to the details of each release. The NSFG is a good example: over ten years, my repository accumulated a separate reader for every survey, each one a small archive of things learned the hard way.

The Public Data Toolkit is my attempt to address this problem in a way that works for many datasets. It doesn’t hold any data itself. It holds instructions and skills that an AI agent follows to turn a messy public dataset into a well-documented, stable repository. The result contains the data, published as a release when the terms of use allow it, and the dataset’s metadata, collected from the codebooks and documentation, with corrections and a record of where each fact came from. The metadata is available in three forms: pages for people to browse, a programming interface for analysis code, and an index that AI agents can search.

pdt-nsfg is the toolkit applied to the NSFG. It covers eleven surveys, from 1982 to 2024–2025: the female respondent file of every survey, the male file from 2002, and pregnancies for the three most recent. Where there are errors in NCHS’s documentation, the repository records a correction along with the evidence for it. And where an analysis needs something that isn’t a single variable in every survey, like the date of first marriage, pdt-nsfg provides it as a named concept or a derived variable.

With the toolkit installed, getting the data looks like this:

from pdt import load

result = load(
    "AllenDowney/pdt-nsfg",
    ["FMARNO", "AGEBABY1"],
    table="female",
    version="data-2026-12-01.1",
)
result.data  # one row per respondent, every survey stacked

The result also includes a report that says, for every column, which of NCHS’s variables each survey supplied, what was done to the values, and what changed from one survey to the next.

Both projects are new, started in November 2026, and the toolkit’s proposal and draft standard are open for review. If you work with the NSFG, or with another public dataset that has the same problems, I would like to hear from you.

An Agentic Data Science Story

An Agentic Data Science Story

For a recent collaboration with AIBM, I found myself working with data from the National Survey of Family Growth (NSFG), which I used in several examples in Think Stats. I was reminded of the technical debt I have accumulated while working with this data, and the dread I feel getting back to it. So I decided to make it a case study in agentic data science.

I asked Claude Code to take inventory of the repository, reorganize it, and rebuild the analysis pipeline. Then I asked it to generate a blog post about the process, which is what follows, with my revisions.

The project

Since 2015 I have kept a repository that does one thing: take the National Survey of Family Growth — a large, repeated, nationally representative survey run by the National Center for Health Statistics — and harmonize it across survey cycles so that marriage patterns can be compared over time.

If you want to learn to work this way, PyMC Labs offers a live workshop, Master Agentic Data Science, on building AI agent workflows while keeping your analysis rigorous and reproducible.

That is more work than it sounds like. The obvious problem is that the variables move around. A variable that exists in one cycle may be absent from the next, renamed in the one after, or recoded onto a different scale without changing its name. That is tedious but tractable.

The less obvious problem is that the file format and the metadata format both change across cycles, and not in step with each other. Across ten cycles there are two data formats and three ways of describing them:

cyclesdatametadatahow the code reads it
1982, 1988, 1995fixed-width textSAS setup file (.sas)column positions hardcoded by hand
2002–2019fixed-width textStata dictionary (.dct)dictionary parsed at run time
2022–2023SAS binary (.sas7bdat)embedded in the filepyreadstat

The early cycles are the awkward ones. NCHS distributes a SAS setup file — a program, not a data structure, full of PROC FORMAT blocks — and the repository does not read it. Someone [Allen], years ago, opened that file and transcribed the column positions into a Python list by hand:

colspecs = [
    (976 - 1, 982),
    (1001 - 1, 1002),
    (1268 - 1, 1271),
    ...
]

The - 1 on each start position converts from the one-based columns the SAS file uses to the zero-based ones pandas wants. There are dozens of these, and nothing checks them against the setup file they came from.

Then there are the one-off quirks. The 1988 respondent file, as published, contains no line breaks at all — it is a single unbroken run of 30,022,850 bytes, which is 8,450 records of 3,553 characters each. Reading it requires splitting it into records first. And in the 2022–2023 file every variable name is uppercase except one, agebaby1, which is lowercase for no reason anyone has recorded.

The repository grew one cycle at a time. Each new release meant a new loading function — ReadFemResp2002, ReadFemResp2010, and so on — that knew the quirks of that cycle and mapped them onto a common set of columns. Ten cycles for women, seven for men: seventeen loading functions, each a small archive of things learned the hard way.

The output is a survival analysis. For each decade-of-birth cohort, it estimates the fraction who have ever married, as a function of age. Those curves are the reason the project exists, and they show something clear:

Percent ever married, women, as published in December 2024

Each successive cohort marries later than the one before, and the more recent cohorts look likely to end up with a larger share never marrying at all. That figure, and its male counterpart, appeared in a post in December 2024.

How it accumulated

Eighty-five commits over eleven years, in bursts: seventeen in 2015, then a handful a year, then a flurry whenever a new cycle landed. Between bursts the repository sat untouched for months at a time.

This is how a lot of real analysis code lives; here’s what it looked like after a decade:

  • About 150 files in a single directory. Raw survey data, derived data, 49 loose figures, notebooks, and the source of a 2015-era statistics library pasted into the repo rather than installed, all side by side.
  • git status reported 78 untracked files and 13 modified ones. At that point Git stops being useful: a real change is invisible in the noise.
  • Seventeen months of uncommitted work, including a 1.8 MB notebook that produced eleven published figures and had never been committed at all.
  • Two parallel codebases. A modern one using lifelines and empiricaldist, and a legacy one using the pasted-in library — joined at exactly one function call, which kept 116 KB of 2015 code loaded on every run.
  • Data committed to version control. Several hundred megabytes of survey microdata in git-LFS — which NSFG’s data user agreement does not permit redistributing.

None of this was the result of carelessness [Thanks, Claude, but that is far too generous]. Each piece was a reasonable local decision: commit the data so the analysis is reproducible; keep a private copy of the library so it does not break; add a loader for the new cycle in the same style as the last one. The problems are emergent. No single commit introduced them.

The audit

Claude recently worked through the repository, with a simple standing rule: any change that was supposed to be behavior-preserving had to prove it. Before and after every structural change, the pipeline was re-run and the output compared. That rule turned out to matter more than any of the cleanup.

A one-year error in the headline variable

From cycle 10 (2015–2017) onward, the NSFG public-use files stopped publishing century-month dates of birth and marriage. What they publish instead is the year of first marriage and the integer age at interview. The loading code reconstructed the missing century months by taking midpoints:

cmbirth  = cmintvw - ager * 12 + 6      # female respondent file
cmmarrhx = (mardat01 - 1900) * 12 + 6

The marriage line is right. mardat01 is a year with no month, so mid-year is the best guess, and + 6 moves the date six months later within that year.

The birth line is not: Someone who reports age 30 at interview is somewhere between 30 and 31 — so the best single guess is 30.5 years old — half a year older than the integer they reported. To turn that into a birth date you go back thirty years and six further months from the interview. Going back six extra months is what - 6 does: it makes the person older, not younger.

The published code had + 6, which goes six months the other way. Concretely: for someone interviewed in January 2020 who reports age 30, - 6 gives a birth date of July 1989 and an implied age of 30.5 — the midpoint, as it should be. The + 6 gives July 1990 and an implied age of 29.5, which is younger than the age the respondent reported.

Measured against cycle 9, the last cycle that still publishes a real date of birth:

formulabiasRMSE
+6 (female respondent file)+0.998 yr1.039
0 (male respondent file)+0.498 yr0.576
−6 (correct)−0.002 yr0.290

The consequence: age at first marriage was a year too low in the three most recent cycles, and correct in all the earlier ones. That distorted the trend in precisely the direction that matters. In the old data, age at first marriage fell between cycle 9 and cycle 10 — from 24.27 to 23.55 for women — a visible dip suggesting people had started marrying younger again. That dip was entirely an artifact. Corrected, the series rises monotonically across all ten cycles.

The error survived for years because it hid well. The code for the female and male respondent files was wrong in different ways that produced the same agemarry, so the two pipelines agreed with each other. And the + 6 cancels between cmbirth and cmmarrhx when you take the difference — so the headline variable looked plausible even though the birth dates underneath it were infeasible.

What found it was not reading the code. It was a sweep comparing every derived variable across every cycle boundary, looking for discontinuities.

Why the tail is hard

Now the more interesting problem, and the one that took the longest to get right.

A survival curve for a birth cohort answers: of people born in this decade, what fraction had married by each age? For the 1950s cohort that is easy — everyone in it has passed age 45, and the survey has observed them doing so.

For the 2000s cohort it is not. In the 2022–2023 survey, the oldest of them are 23. Nobody has been observed at 30. No estimator can say what fraction of them will have married by 30, because no data about it exists. This is right-censoring, and it is unavoidable — it is a property of time, not of the method.

What a Kaplan–Meier estimator does at the end of such a cohort’s range is specific and worth understanding. It tracks a risk set: the people still unmarried and still under observation. As age increases, people leave the risk set by marrying or by running out of observation. Near the end, the risk set becomes very small. When one person remains and that person marries, the estimated survival drops to zero — the curve says 100% married on the strength of a single respondent.

Look closely at the right-hand end of the 2000s curve in the published figure above and you can see the machinery straining: short, steep steps where a smooth curve should be.

The coarse dates made it worse

Here is where the missing century months come back. In the cycles that publish real dates, age at marriage takes about 300 distinct values and age at interview about 360 — month-level resolution. In cycles 10–12, age at interview takes 36 distinct values, every one a whole number, because the file reports an integer age.

That means every censored respondent in those cycles lands on one of a dozen integer ages. The risk set does not decline smoothly; it falls off a cliff twelve times. For the 1990s cohort, 97 people are censored at age 32.000000 exactly, dropping the risk set from 131 to 34 in a single instant. Every marriage after that point moves the curve by 1.3 percentage points instead of 0.1.

So the visible spikes have two causes stacked on each other: a genuinely exhausted risk set, and an artificial one created by rounding.

What the pipeline was asserting

Step back and the deeper problem is clearer. The midpoint convention produces a number — say, age at marriage of 24.83 — and every downstream step treats that as an exactly observed time. But for cycles 10–12 both endpoints are known only to the year, so age at first marriage is genuinely uncertain by about two years.

The pipeline was reporting to the month a quantity known to within two years. The spiking tails were a symptom of that, not the disease.

What we tried

Option 1: a floor on the risk set

Stop drawing the curve once the risk set falls below some number. This is what the project was effectively doing, and it works in the narrow sense that the spikes disappear.

It has two problems. The threshold is arbitrary — I picked 10 because the figures looked right. And it treats the symptom: the curve still claims month-level precision everywhere it is drawn.

Option 2: Turnbull’s estimator

The textbook answer for interval-censored data is the Turnbull estimator, a non-parametric maximum likelihood fit that takes an interval per observation rather than a point. lifelines implements it. It is, in a real sense, the correct estimator for data of this shape.

We tried it, and rejected it for two reasons.

It does not fix the tail. On the 2000s cohort it reads 12.88% at age 23.2 and then jumps to 100% — the same degeneracy as Kaplan–Meier, for the same reason. When the risk set is exhausted, the likelihood puts all remaining mass in the last interval. Being correct about the censoring structure buys nothing once the data runs out.

And it does not scale. It took 1.1 seconds on a cohort of 2,140 and more than five minutes on one of 16,169 without finishing. Inside a bootstrap, where it would run hundreds of times, that is not viable.

Option 3: multiple imputation

Instead of collapsing each interval to its midpoint, draw a value from inside it. Draw the birth date uniformly within the year it could have been; draw the marriage date uniformly within its year; compute age at marriage from the draws. Repeat.

This is the option we adopted, but the reason is not the one I expected. It does not smooth the curve — individual draws still spike. What it does is make the instability visible. Five draws for the 2000s cohort gave final estimates of 100%, 17%, 13%, 12% and 11%.

That is a ninety-point spread on identical data, because at that age the answer turns on whether one person’s imputed marriage date happens to fall before or after their imputed censoring date. The midpoint convention picks one of those numbers and reports it without a warning. The imputation reports the spread, which is the honest answer: at this age, this data cannot tell you.

The rule we settled on

That spread becomes the stopping rule. Fit the curve to many draws, report the mean, and stop where the draws stop agreeing. Getting the criterion right took two failures, and both are instructive.

An absolute threshold does not work. Stop where the spread exceeds two percentage points, and a small cohort loses everything: 322 men born in the 1950s have a bootstrap spread near two points at every age, simply because the cohort is small. The rule truncated that curve at age 21 and discarded it.

A purely relative threshold does not work either. Stop where the spread exceeds three times the cohort’s own median, and precision is punished: the 1990s cohort has a median spread of 0.4 points, so it trips at 1.2 points — an entirely reportable estimate.

Neither criterion alone separates “the tail has degenerated” from “this cohort is small”. Together they do. A point is dropped only if it is anomalous for its own cohort and imprecise in absolute terms: drop where sd>max(floor,k×median(sd))

The diagnostic below shows it working. Each line is one cohort’s bootstrap spread divided by its own median — solid for women, dashed for men — and the dotted line is the relative threshold. The 1930s women’s curve peaks at 2.2× around age 20 and is kept, because in absolute terms it is still precise. The 1990s and 2000s curves climb past the threshold and are cut.

Where each estimate stops being reportable

The result

Estimation is now a bootstrap that resamples respondents within cycle by sampling weight and then draws from each respondent’s interval, so the spread across iterations carries sampling variability and date coarseness together.

In the figures below, the shaded band around each curve is a 90% bootstrap interval, and the dot marks the age past which the data no longer supports an estimate — the point where the stopping rule cuts the curve off.

Percent ever married, women, by decade of birth
Percent ever married, men, by decade of birth

The substantive story is unchanged: each cohort still marries later than the last, and the recent cohorts still look likely to end with a larger share never married. An audit that overturned the finding would be a bigger story; this one did not.

But some of the numbers changed. For women in the 1990s cohort the old pipeline reported about 62% ever married by age 33; the new one reports 56.5% by 32. Most of that gap is the censoring correction: retiring people from the risk set half a year too early removes them before marriages they may have had, which inflates the estimate.

What I take from this

The valuable output was not the cleanup. Reorganizing 150 files into directories, purging the data from git history, converting notebooks to markdown, retiring the pasted-in library — all worth doing, none of it interesting. The valuable output was three bugs and a method, and every one of them came from the same discipline: check that the thing you believe is true.

Verification is what made the agentic part work. The rule that every supposedly behavior-preserving change had to produce a byte-identical result is what made it safe to delete 253 lines of unreachable code, retire a library that had been pasted in a decade ago, rename 39 functions, and move every file in the repository. It is also what caught the errors. Only one of them had reached the published figures — the reconstructed date of birth, wrong since 2019 — and it was found by a sweep comparing derived variables across cycle boundaries, not by anybody reading the code. The rest were Claude’s, made and caught within the session, before they could change a number.

Coarsened data deserves explicit handling. When NSFG stopped publishing century-month dates, the pipeline papered over it with a midpoint and carried on. That was the single decision that caused both the year-long bias and the spiking tails. The honest move — say what you know, which is an interval — was available the whole time.

Some questions have no answer, and saying so is the finding. No estimator can tell you what fraction of people born in the 2000s will have married by 30. The best a method can do is be clear about where its knowledge ends. A curve that stops, with a dot, is more informative than one that continues into a spike.


The code is at AllenDowney/MarriageNSFG. The estimation lives in nsfg/intervals.py and scripts/estimate_marriage.py; the figures come from scripts/plot_marriage.py.

Note for AI text detectors: Yes, most of this post was generated by Claude, as acknowledged in the introduction.

Are men getting married later or never? Both.

Are men getting married later or never? Both.

Last week I wrote about marriage patterns for women in the U.S. Now let’s see what’s happening with men.

Again, I’m working with data from the National Survey of Family Growth, which surveyed 29,192 men in the U.S. between 2002 and 2017. I used Kaplan–Meier estimation to compute “survival” curves for the time until first marriage. The following figure shows the results for men grouped by decade of birth:


The colored lines show the estimated curves; the gray lines show projections based on moderate assumptions about future marriage rates. Two trends are apparent:

  • From one generation to the next, men have been getting married later. The median age at first marriage for men born in the 1950s was 26; for men born in the 1980s is it 30, and for men born in the 1990s, it is projected to be 35.
  • The fraction of men never married at age 44 was 18% for men born in the 1950s, 1960s, and 1970s. It is projected to increase to 30% for men born in the 1980s and 37% for men born in the 1990s.

Of course, thing could change in the future and make these projections wrong. But marriage rates in the last 5 years have been very low for both men and women. In order to catch up to previous generations, young men would have to start marrying at unprecedented rates, and they would have to start soon.

For details of the methods I used for this analysis, you can read my paper from SciPy 2015.

And for even more details, you can read this Jupyter notebook.

As always, thank you to the good people who run the NSFG for making this data available.