National Survey of Family Growth (NSFG)
The principal survey to measure reproductive behavior in the United States population.
Female and male tables with one row per respondent, and a separate one row per pregnancy table.
A complex sample survey designed to generalize to the 15-49 year old US population by gender.
Released every couple of years since 1973.
Administered by the Centers for Disease Control and Prevention, data collection managed by RTI.
Recommended Reading
Four Example Strengths & Limitations:
✔️ Detailed questions about fertility and relationship history
✔️ Face-to-face fieldwork conducted by female interviewers
❌ Abortions under-reported in demographic surveys
❌ Sample sizes too small for state-level or single year estimates
Three Example Findings:
One out of five mothers with a college degree had a nonmarital first birth during 2015-2017.
The rate of unintended pregnancy in the US declined substantially between 2008 and 2011.
During 2022-2023, 36% of females 15-49 received a family planning service in the past 12 months.
Two Methodology Documents:
Public-Use Data File Documentation: 2022-2023 National Survey of Family Growth
One Haiku:
Download, Import, Preparation
library(haven)
sas_url <-
"https://ftp.cdc.gov/pub/Health_Statistics/NCHS/NSFG/NSFG-2022-2023-FemRespPUFData.sas7bdat"
nsfg_tbl <- read_sas( sas_url )
nsfg_df <- data.frame( nsfg_tbl )
names( nsfg_df ) <- tolower( names( nsfg_df ) )
Save Locally
Save the object at any point:
# nsfg_fn <- file.path( path.expand( "~" ) , "NSFG" , "this_file.rds" )
# saveRDS( nsfg_df , file = nsfg_fn , compress = FALSE )
Load the same object:
Variable Recoding
Add new columns to the data set:
nsfg_design <-
update(
nsfg_design ,
one = 1 ,
birth_control_pill = as.numeric( constat1 == 6 ) ,
age_categories =
factor( findInterval( ager , c( 15 , 20 , 25 , 30 , 35 , 40 ) ) ,
labels = c( '15-19' , '20-24' , '25-29' , '30-34' , '35-39' , '40-49' ) ) ,
marstat =
factor( marstat , levels = c( 1:6 , 8:9 ) ,
labels = c(
"Married to a person of the opposite sex" ,
"Not married but living together with a partner of the opposite sex" ,
"Widowed" ,
"Divorced or annulled" ,
"Separated, because you and your spouse are not getting along" ,
"Never been married" ,
"Refused" ,
"Don't know" )
)
)
Analysis Examples with the survey
library
Unweighted Counts
Count the unweighted number of records in the survey sample, overall and by groups:
Descriptive Statistics
Calculate the mean (average) of a linear variable, overall and by groups:
svymean( ~ pregnum , nsfg_design , na.rm = TRUE )
svyby( ~ pregnum , ~ age_categories , nsfg_design , svymean , na.rm = TRUE )
Calculate the distribution of a categorical variable, overall and by groups:
Calculate the sum of a linear variable, overall and by groups:
svytotal( ~ pregnum , nsfg_design , na.rm = TRUE )
svyby( ~ pregnum , ~ age_categories , nsfg_design , svytotal , na.rm = TRUE )
Calculate the weighted sum of a categorical variable, overall and by groups:
Calculate the median (50th percentile) of a linear variable, overall and by groups:
svyquantile( ~ pregnum , nsfg_design , 0.5 , na.rm = TRUE )
svyby(
~ pregnum ,
~ age_categories ,
nsfg_design ,
svyquantile ,
0.5 ,
ci = TRUE , na.rm = TRUE
)
Estimate a ratio:
Subsetting
Restrict the survey design to Ever Cohabited with a Non-Marital Male Partner:
Calculate the mean (average) of this subset:
Measures of Uncertainty
Extract the coefficient, standard error, confidence interval, and coefficient of variation from any descriptive statistics function result, overall and by groups:
this_result <- svymean( ~ pregnum , nsfg_design , na.rm = TRUE )
coef( this_result )
SE( this_result )
confint( this_result )
cv( this_result )
grouped_result <-
svyby(
~ pregnum ,
~ age_categories ,
nsfg_design ,
svymean ,
na.rm = TRUE
)
coef( grouped_result )
SE( grouped_result )
confint( grouped_result )
cv( grouped_result )
Calculate the degrees of freedom of any survey design object:
Calculate the complex sample survey-adjusted variance of any statistic:
Include the complex sample design effect in the result for a specific statistic:
# SRS without replacement
svymean( ~ pregnum , nsfg_design , na.rm = TRUE , deff = TRUE )
# SRS with replacement
svymean( ~ pregnum , nsfg_design , na.rm = TRUE , deff = "replace" )
Compute confidence intervals for proportions using methods that may be more accurate near 0 and 1. See ?svyciprop
for alternatives:
Replication Example
This example matches the Variance Estimates for Percentages using SAS (9.4) and STATA (18):
Match the sum of the weights:
result <- svytotal( ~ one , nsfg_design )
stopifnot( round( coef( result ) , 0 ) == 74936918 )
stopifnot( round( SE( result ) , 0 ) == 2910451 )
Match row percentages of women currently using the pill by age:
row_percents <- c( 14.2348 , 18.9586 , 14.6057 , 10.1973 , 7.8114 , 6.8632 )
std_err_row_percents <- c( 1.6792 , 2.0226 , 1.8889 , 1.3836 , 1.1050 , 0.7961 )
results <- svyby( ~ birth_control_pill , ~ age_categories , nsfg_design , svymean )
stopifnot( all( round( coef( results ) * 100 , 4 ) == row_percents ) )
stopifnot( all( round( SE( results ) * 100 , 4 ) == std_err_row_percents ) )
Analysis Examples with srvyr
The R srvyr
library calculates summary statistics from survey data, such as the mean, total or quantile using dplyr-like syntax. srvyr allows for the use of many verbs, such as summarize
, group_by
, and mutate
, the convenience of pipe-able functions, the tidyverse
style of non-standard evaluation and more consistent return types than the survey
package. This vignette details the available features. As a starting point for NSFG users, this code replicates previously-presented examples:
Calculate the mean (average) of a linear variable, overall and by groups: