Sponsored jointly by the U.S. Census Bureau and the U.S. Bureau of Labor Statistics (BLS), the CPS-ASEC is the primary source of labor force statistics for the population of the United States.
This section downloads, imports, and prepares the most current microdata for analysis, then reproduces some statistics and margin of error terms from the U.S. Census Bureau.
Analysis Examples with the survey
library
Add new columns to the data set:
cps_design <-
update(
cps_design ,
one = 1 ,
a_maritl =
factor(
a_maritl ,
labels =
c(
"married - civilian spouse present" ,
"married - AF spouse present" ,
"married - spouse absent" ,
"widowed" ,
"divorced" ,
"separated" ,
"never married"
)
) ,
state_name =
factor(
gestfips ,
levels =
c(
1L,
2L,
4L,
5L,
6L,
8L,
9L,
10L,
11L,
12L,
13L,
15L,
16L,
17L,
18L,
19L,
20L,
21L,
22L,
23L,
24L,
25L,
26L,
27L,
28L,
29L,
30L,
31L,
32L,
33L,
34L,
35L,
36L,
37L,
38L,
39L,
40L,
41L,
42L,
44L,
45L,
46L,
47L,
48L,
49L,
50L,
51L,
53L,
54L,
55L,
56L
) ,
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"
)
) ,
male = as.numeric(a_sex == 1)
)
Count the unweighted number of records in the survey sample, overall and by groups:
sum( weights( cps_design , "sampling" ) != 0 )
svyby( ~ one , ~ state_name , cps_design , unwtd.count )
Count the weighted size of the generalizable population, overall and by groups:
svytotal( ~ one , cps_design )
svyby( ~ one , ~ state_name , cps_design , svytotal )
Calculate the mean (average) of a linear variable, overall and by groups:
svymean( ~ pearnval , cps_design )
svyby( ~ pearnval , ~ state_name , cps_design , svymean )
Calculate the distribution of a categorical variable, overall and by groups:
svymean( ~ a_maritl , cps_design )
svyby( ~ a_maritl , ~ state_name , cps_design , svymean )
Calculate the sum of a linear variable, overall and by groups:
svytotal( ~ pearnval , cps_design )
svyby( ~ pearnval , ~ state_name , cps_design , svytotal )
Calculate the weighted sum of a categorical variable, overall and by groups:
svytotal( ~ a_maritl , cps_design )
svyby( ~ a_maritl , ~ state_name , cps_design , svytotal )
Calculate the median (50th percentile) of a linear variable, overall and by groups:
svyquantile( ~ pearnval , cps_design , 0.5 )
svyby(
~ pearnval ,
~ state_name ,
cps_design ,
svyquantile ,
0.5 ,
ci = TRUE
)
Estimate a ratio:
svyratio(
numerator = ~ moop ,
denominator = ~ pearnval ,
cps_design
)
Restrict the survey design to persons aged 18-64:
sub_cps_design <- subset( cps_design , a_age %in% 18:64 )
Calculate the mean (average) of this subset:
svymean( ~ pearnval , sub_cps_design )
Extract the coefficient, standard error, confidence interval, and coefficient of variation from any descriptive statistics function result, overall and by groups:
this_result <- svymean( ~ pearnval , cps_design )
coef( this_result )
SE( this_result )
confint( this_result )
cv( this_result )
grouped_result <-
svyby(
~ pearnval ,
~ state_name ,
cps_design ,
svymean
)
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:
svyvar( ~ pearnval , cps_design )
Include the complex sample design effect in the result for a specific statistic:
# SRS without replacement
svymean( ~ pearnval , cps_design , deff = TRUE )
# SRS with replacement
svymean( ~ pearnval , cps_design , deff = "replace" )
Compute confidence intervals for proportions using methods that may be more accurate near 0 and 1. See ?svyciprop
for alternatives:
svyciprop( ~ male , cps_design ,
method = "likelihood" )
Perform a design-based t-test:
svyttest( pearnval ~ male , cps_design )
Perform a chi-squared test of association for survey data:
svychisq(
~ male + a_maritl ,
cps_design
)
Perform a survey-weighted generalized linear model:
glm_result <-
svyglm(
pearnval ~ male + a_maritl ,
cps_design
)
summary( glm_result )
Household Income
Limit the CPS-ASEC person-level design to the household reference person, then calculate the Gini coefficient with total household income:
cps_household_design <- subset(cps_design , a_exprrp %in% 1:2)
(cps_household_gini <- svygini( ~ htotval , cps_household_design))
## gini SE
## htotval 0.48846 0.002
# match 2022 household gini coefficient
# https://www2.census.gov/programs-surveys/cps/tables/time-series/historical-income-households/h04.xlsx
stopifnot(round(coef(cps_household_gini) , 3) == 0.488)
# match 2022 household gini margin of error
# https://www.census.gov/content/dam/Census/newsroom/press-kits/2023/iphi/20230912-iphi-slides-income.pdf#page=13
stopifnot(round(
coef(cps_household_gini) - confint(cps_household_gini , level = 0.9)[1] ,
4
) == 0.0033)
Calculate matching Theil and Atkinson measures:
cps_household_design <-
update(cps_household_design , htotval_ones = ifelse(htotval < 0 , NA , htotval))
cps_household_design <-
update(cps_household_design ,
htotval_ones = ifelse(htotval_ones < 1 , 1 , htotval_ones))
(cps_household_theil <-
svygei(~ htotval_ones , cps_household_design , na.rm = TRUE))
## gei SE
## htotval_ones 0.44013 0.0051
(
cps_household_atkinson <-
svyatk(
~ htotval_ones ,
cps_household_design ,
epsilon = 0.5 ,
na.rm = TRUE
)
)
## atkinson SE
## htotval_ones 0.20737 0.0017
# https://www2.census.gov/programs-surveys/cps/tables/time-series/historical-income-households/h04.xlsx
stopifnot(round(coef(cps_household_theil) , 3) == 0.440)
stopifnot(round(coef(cps_household_atkinson), 3) == 0.207)
Worker Earnings
The convey_prep()
function sets the population of reference for poverty threshold estimation. For relative poverty measures, it is important to think what should be the reference population for the poverty threshold. For instance, if one is interested is computing poverty rates across regions using a poverty line computed at a nationwide level (represented by a full sample design object), it is important to run convey_prep()
immediately after creating the full object. However, imagine that one wants to compute the poverty line using the annual earnings among only full-time, full year workers. In this case, subsetting the full object after running convey_prep()
will compute the poverty line using the entire sample, including the earnings of part-time workers, part year workers, and also zeroes for the non-working population. So in this (non-standard) case, we suggest subsetting the main object and then running convey_prep()
again to re-set the reference population:
Limit the CPS-ASEC person-level design to full-time, full year workers:
cps_ftfy_worker_design <- subset(cps_design , wewkrs %in% 1)
Re-set the population of reference for poverty threshold estimation:
cps_ftfy_worker_design <- convey_prep(cps_ftfy_worker_design)
Calculate the Gini coefficient with total earnings:
svygini( ~ pearnval , cps_ftfy_worker_design)
## gini SE
## pearnval 0.412 0.0026