cps_label: Apply factor levels to raw CPS data

Description Usage Arguments Value Examples

View source: R/cps_label.R

Description

The CPS publishes their data in a numeric format, with a separate PDF codebook (not machine readable) describing factor values. This function labels the raw numeric CPS data according to a supplied factor key. Codes that appear in a given year and are not included in factors will be recoded as NA.

Usage

1
2
3
4
5
6
7
8
9
cps_label(
  data,
  factors = cpsvote::cps_factors,
  names_col = "new_name",
  na_vals = c("-1", "BLANK", "NOT IN UNIVERSE"),
  expand_year = TRUE,
  rescale_weight = TRUE,
  toupper = TRUE
)

Arguments

data

The raw CPS data that factors should be applied to

factors

A data frame containing the label codes to be applied

names_col

Which column of factors contains the column names of data

na_vals

Which character values should be considered "missing" across the dataset and be set to NA after labelling

expand_year

Whether to change the two-digit year listed in earlier surveys (94, 96) into a four-digit year (1994, 1996)

rescale_weight

Whether to rescale the weight, dividing by 10,000. The CPS describes the given weight as having "four implied decimals", so this rescaling adjusts the weight to produce sensible population totals.

toupper

Whether to convert all factor levels to uppercase

Value

CPS data with factor labels in place of the raw numeric data

Examples

1

cpsvote documentation built on Nov. 8, 2020, 4:27 p.m.