Skip to contents

Retrieves and processes ACS race data for survey race imputation, supporting custom and collapsed race categories. Uses explicit regex patterns to match and collapse race categories to target levels. Use for imputing race in survey data using ACS reference.

Usage

get_acs_race(settings, year = NULL)

Arguments

settings

list. Settings object with ACS configs. Required keys:

  • acs_tables[['race']] — ACS table name for race

  • acs_year — ACS year

  • targets[['p_race']]$levels — target race levels

year

integer(1), optional. ACS year for imputation. Defaults to acs_year in settings.

Value

data.table. Block group GEOID and race fraction columns. Columns:

  • bg_geoid — block group GEOID

  • f_* — fraction of households in each race bin (e.g., f_white, f_afam) Rows: one per block group. Keys: (bg_geoid).

Details

  • Fetches ACS table for race using settings and ACS year.

  • Collapses and recodes race categories to match target levels using regex patterns:

    • str_detect(label, "white alone") → "white"

    • str_detect(label, "black or african american alone") → "afam"

    • str_detect(label, "american indian and alaska native alone") → "native"

    • str_detect(label, "asian alone") → "asian"

    • str_detect(label, "native hawaiian and other pacific islander alone") → "pacific"

    • str_detect(label, "some other race alone|not listed above") → "other"

    • str_detect(label, "two or more races:$") → "multiple"

    • str_detect(label, "estimate!!total:$") → "total"

  • Collapses unmatched categories into 'other'.

  • Matches target levels using regex: str_detect(rl, label2) for each target level rl.

  • Returns data.table with block group GEOID and race fraction columns (e.g., f_white, f_afam).

  • Assumes settings include ACS tables and target levels; errors if required columns are missing.

Settings

  • acs_year (direct): ACS year for race table. Default from settings.

  • acs_tables[['race']] (direct): ACS table name for race. Default from settings.

  • targets[['p_race']]$levels (direct): Target race levels for collapsing categories.

Examples

## Not run:
get_acs_race(settings)
#> Error: object 'settings' not found
## End(Not run)