United States Decennial Census Public Use Microdata Sample (USPUMS)
The Long-Form Decennial Census of the United States.
One table with one row per household and a second table with one row per individual within each household. 1990 and 2000 include both 1% and 5% samples. 2010 contains only a 10% sample.
An enumeration of the civilian population of the United States.
Released decennially by the United States Census Bureau since 1990, however earlier extracts are available from IPUMS International.
Administered by the US Census Bureau.
Simplified Download and Importation
The R lodown
package easily downloads and imports all available USPUMS microdata by simply specifying "uspums"
with an output_dir =
parameter in the lodown()
function. Depending on your internet connection and computer processing speed, you might prefer to run this step overnight.
library(lodown)
lodown( "uspums" , output_dir = file.path( path.expand( "~" ) , "USPUMS" ) )
lodown
also provides a catalog of available microdata extracts with the get_catalog()
function. After requesting the USPUMS catalog, you could pass a subsetted catalog through the lodown()
function in order to download and import specific extracts (rather than all available extracts).
library(lodown)
# examine all available USPUMS microdata files
uspums_cat <-
get_catalog( "uspums" ,
output_dir = file.path( path.expand( "~" ) , "USPUMS" ) )
# 2000 1% sample only
uspums_cat <- subset( uspums_cat , year == 2000 & percent == 1 )
# download the microdata to your local computer
uspums_cat <- lodown( "uspums" , uspums_cat )
Analysis Examples with the survey
library
Construct a database-backed complex sample survey design:
library(DBI)
library(RSQLite)
library(survey)
options( survey.lonely.psu = "adjust" )
uspums_design <- readRDS( file.path( path.expand( "~" ) , "USPUMS" , "pums_2000_1_m.rds" ) )
uspums_design <- open( uspums_design , driver = SQLite() )
Variable Recoding
Add new columns to the data set:
uspums_design <-
update(
uspums_design ,
age_categories = factor( 1 + findInterval( age , c( 18 , 35 , 65 ) ) , labels = c( "under 18" , "18-34" , "35-64" , "65+" ) ) ,
married = as.numeric( marstat == 1 ) ,
poverty_status = ifelse( poverty == 0 , NA , poverty ) ,
unemployed = as.numeric( esr %in% 3 ) ,
labor_force = as.numeric( esr %in% 1:5 ) ,
employment_status =
factor(
esr ,
levels = 0:6 ,
labels =
c(
"NIU" ,
"Employed, at work" ,
"Employed, with a job but not at work" ,
"Unemployed" ,
"Armed Forces, at work" ,
"Armed Forces, with a job but not at work" ,
"Not in labor force"
)
) ,
state_name =
factor(
state ,
levels =
c(1, 2, 4, 5, 6, 8, 9, 10, 11, 12, 13, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
37, 38, 39, 40, 41, 42, 44, 45, 46, 47, 48, 49, 50, 51, 53, 54,
55, 56, 66, 72, 78) ,
labels =
c("ALABAMA", "ALASKA", "ARIZONA", "ARKANSAS", "CALIFORNIA",
"COLORADO", "CONNECTICUT", "DELAWARE", "DISTRICT OF COLUMBIA",
"FLORIDA", "GEORGIA", "HAWAII", "IDAHO", "ILLINOIS", "INDIANA",
"IOWA", "KANSAS", "KENTUCKY", "LOUISIANA", "MAINE", "MARYLAND",
"MASSACHUSETTS", "MICHIGAN", "MINNESOTA", "MISSISSIPPI",
"MISSOURI", "MONTANA", "NEBRASKA", "NEVADA", "NEW HAMPSHIRE",
"NEW JERSEY", "NEW MEXICO", "NEW YORK", "NORTH CAROLINA",
"NORTH DAKOTA", "OHIO", "OKLAHOMA", "OREGON", "PENNSYLVANIA",
"RHODE ISLAND", "SOUTH CAROLINA", "SOUTH DAKOTA", "TENNESSEE",
"TEXAS", "UTAH", "VERMONT", "VIRGINIA", "WASHINGTON",
"WEST VIRGINIA", "WISCONSIN", "WYOMING", "GUAM", "PUERTO RICO",
"U.S. VIRGIN ISLANDS")
)
)
Unweighted Counts
Count the unweighted number of records in the survey sample, overall and by groups:
sum( weights( uspums_design , "sampling" ) != 0 )
svyby( ~ one , ~ state_name , uspums_design , unwtd.count )
Weighted Counts
Count the weighted size of the generalizable population, overall and by groups:
svytotal( ~ one , uspums_design )
svyby( ~ one , ~ state_name , uspums_design , svytotal )
Descriptive Statistics
Calculate the mean (average) of a linear variable, overall and by groups:
svymean( ~ poverty_status , uspums_design , na.rm = TRUE )
svyby( ~ poverty_status , ~ state_name , uspums_design , svymean , na.rm = TRUE )
Calculate the distribution of a categorical variable, overall and by groups:
svymean( ~ employment_status , uspums_design )
svyby( ~ employment_status , ~ state_name , uspums_design , svymean )
Calculate the sum of a linear variable, overall and by groups:
svytotal( ~ poverty_status , uspums_design , na.rm = TRUE )
svyby( ~ poverty_status , ~ state_name , uspums_design , svytotal , na.rm = TRUE )
Calculate the weighted sum of a categorical variable, overall and by groups:
svytotal( ~ employment_status , uspums_design )
svyby( ~ employment_status , ~ state_name , uspums_design , svytotal )
Calculate the median (50th percentile) of a linear variable, overall and by groups:
svyquantile( ~ poverty_status , uspums_design , 0.5 , na.rm = TRUE )
svyby(
~ poverty_status ,
~ state_name ,
uspums_design ,
svyquantile ,
0.5 ,
ci = TRUE ,
keep.var = TRUE ,
na.rm = TRUE
)
Estimate a ratio:
svyratio(
numerator = ~ unemployed ,
denominator = ~ labor_force ,
uspums_design ,
na.rm = TRUE
)
Subsetting
Restrict the survey design to females:
sub_uspums_design <- subset( uspums_design , sex == 2 )
Calculate the mean (average) of this subset:
svymean( ~ poverty_status , sub_uspums_design , na.rm = TRUE )
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( ~ poverty_status , uspums_design , na.rm = TRUE )
coef( this_result )
SE( this_result )
confint( this_result )
cv( this_result )
grouped_result <-
svyby(
~ poverty_status ,
~ state_name ,
uspums_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:
degf( uspums_design )
Calculate the complex sample survey-adjusted variance of any statistic:
svyvar( ~ poverty_status , uspums_design , na.rm = TRUE )
Include the complex sample design effect in the result for a specific statistic:
# SRS without replacement
svymean( ~ poverty_status , uspums_design , na.rm = TRUE , deff = TRUE )
# SRS with replacement
svymean( ~ poverty_status , uspums_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:
svyciprop( ~ married , uspums_design ,
method = "likelihood" , na.rm = TRUE )
Regression Models and Tests of Association
Perform a design-based t-test:
svyttest( poverty_status ~ married , uspums_design )
Perform a chi-squared test of association for survey data:
svychisq(
~ married + employment_status ,
uspums_design
)
Perform a survey-weighted generalized linear model:
glm_result <-
svyglm(
poverty_status ~ married + employment_status ,
uspums_design
)
summary( glm_result )
Poverty and Inequality Estimation with convey
The R convey
library estimates measures of income concentration, poverty, inequality, and wellbeing. This textbook details the available features. As a starting point for USPUMS users, this code calculates the gini coefficient on complex sample survey data:
library(convey)
uspums_design <- convey_prep( uspums_design )
svygini( ~ hinc , uspums_design , na.rm = TRUE )