# Current Population Survey - Annual Social and Economic Supplement (CPSASEC)

The March Current Population Survey Annual Social and Economic Supplement has supplied the statistics for the US Census Bureauâ€™s report on income, poverty, and health insurance coverage since 1948.

One table with one row per sampled household, a second table with one row per family within each sampled household, and a third table with one row per individual within each of those families.

A complex sample survey designed to generalize to the civilian non-institutional population of the United States

Released annually since 1998.

Administered jointly by the US Census Bureau and the Bureau of Labor Statistics.

## Simplified Download and Importation

The R `lodown`

package easily downloads and imports all available CPSASEC microdata by simply specifying `"cpsasec"`

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( "cpsasec" , output_dir = file.path( path.expand( "~" ) , "CPSASEC" ) )
```

`lodown`

also provides a catalog of available microdata extracts with the `get_catalog()`

function. After requesting the CPSASEC 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 CPSASEC microdata files
cpsasec_cat <-
get_catalog( "cpsasec" ,
output_dir = file.path( path.expand( "~" ) , "CPSASEC" ) )
# 2016 only
cpsasec_cat <- subset( cpsasec_cat , year == 2016 )
# download the microdata to your local computer
lodown( "cpsasec" , cpsasec_cat )
```

## Analysis Examples with the `survey`

library

Construct a complex sample survey design:

```
options( survey.replicates.mse = TRUE )
library(survey)
cpsasec_df <-
readRDS( file.path( path.expand( "~" ) , "CPSASEC" , "2016 cps asec.rds" ) )
variables_to_keep <-
c( 'a_maritl' , 'gestfips' , 'a_sex' , 'ptotval' , 'moop' , 'a_age' , 'htotval' ,
'one' , 'a_exprrp' , 'marsupwt' ,
grep( "pwwgt" , names( cpsasec_df ) , value = TRUE ) )
cpsasec_df <- cpsasec_df[ variables_to_keep ] ; gc()
cpsasec_design <-
svrepdesign(
weights = ~ marsupwt ,
repweights = "pwwgt[1-9]" ,
type = "Fay" ,
rho = ( 1 - 1 / sqrt( 4 ) ) ,
data = cpsasec_df ,
combined.weights = TRUE
)
```

### Variable Recoding

Add new columns to the data set:

```
cpsasec_design <-
update(
cpsasec_design ,
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 )
)
```

### Unweighted Counts

Count the unweighted number of records in the survey sample, overall and by groups:

```
sum( weights( cpsasec_design , "sampling" ) != 0 )
svyby( ~ one , ~ state_name , cpsasec_design , unwtd.count )
```

### Weighted Counts

Count the weighted size of the generalizable population, overall and by groups:

```
svytotal( ~ one , cpsasec_design )
svyby( ~ one , ~ state_name , cpsasec_design , svytotal )
```

### Descriptive Statistics

Calculate the mean (average) of a linear variable, overall and by groups:

```
svymean( ~ ptotval , cpsasec_design )
svyby( ~ ptotval , ~ state_name , cpsasec_design , svymean )
```

Calculate the distribution of a categorical variable, overall and by groups:

```
svymean( ~ a_maritl , cpsasec_design )
svyby( ~ a_maritl , ~ state_name , cpsasec_design , svymean )
```

Calculate the sum of a linear variable, overall and by groups:

```
svytotal( ~ ptotval , cpsasec_design )
svyby( ~ ptotval , ~ state_name , cpsasec_design , svytotal )
```

Calculate the weighted sum of a categorical variable, overall and by groups:

```
svytotal( ~ a_maritl , cpsasec_design )
svyby( ~ a_maritl , ~ state_name , cpsasec_design , svytotal )
```

Calculate the median (50th percentile) of a linear variable, overall and by groups:

```
svyquantile( ~ ptotval , cpsasec_design , 0.5 )
svyby(
~ ptotval ,
~ state_name ,
cpsasec_design ,
svyquantile ,
0.5 ,
ci = TRUE ,
keep.var = TRUE
)
```

Estimate a ratio:

```
svyratio(
numerator = ~ moop ,
denominator = ~ ptotval ,
cpsasec_design
)
```

### Subsetting

Restrict the survey design to persons aged 18-64:

`sub_cpsasec_design <- subset( cpsasec_design , a_age %in% 18:64 )`

Calculate the mean (average) of this subset:

`svymean( ~ ptotval , sub_cpsasec_design )`

### 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( ~ ptotval , cpsasec_design )
coef( this_result )
SE( this_result )
confint( this_result )
cv( this_result )
grouped_result <-
svyby(
~ ptotval ,
~ state_name ,
cpsasec_design ,
svymean
)
coef( grouped_result )
SE( grouped_result )
confint( grouped_result )
cv( grouped_result )
```

Calculate the degrees of freedom of any survey design object:

`degf( cpsasec_design )`

Calculate the complex sample survey-adjusted variance of any statistic:

`svyvar( ~ ptotval , cpsasec_design )`

Include the complex sample design effect in the result for a specific statistic:

```
# SRS without replacement
svymean( ~ ptotval , cpsasec_design , deff = TRUE )
# SRS with replacement
svymean( ~ ptotval , cpsasec_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 , cpsasec_design ,
method = "likelihood" )
```

### Regression Models and Tests of Association

Perform a design-based t-test:

`svyttest( ptotval ~ male , cpsasec_design )`

Perform a chi-squared test of association for survey data:

```
svychisq(
~ male + a_maritl ,
cpsasec_design
)
```

Perform a survey-weighted generalized linear model:

```
glm_result <-
svyglm(
ptotval ~ male + a_maritl ,
cpsasec_design
)
summary( glm_result )
```

## 0.13 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 CPSASEC users, this code calculates the gini coefficient on complex sample survey data:

```
library(convey)
cpsasec_design <- convey_prep( cpsasec_design )
sub_cpsasec_design <-
subset(
cpsasec_design ,
a_exprrp %in% 1:2
)
svygini( ~ htotval , sub_cpsasec_design )
```