Skip to content

Instantly share code, notes, and snippets.

@mfherman
Last active August 7, 2020 20:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mfherman/d16df6748700ba47ba2298a0f39fb7e3 to your computer and use it in GitHub Desktop.
Save mfherman/d16df6748700ba47ba2298a0f39fb7e3 to your computer and use it in GitHub Desktop.
Estimate race and ethnicity of health care workers by PUMA using PUMS data
## Estimate race and ethnicity of health care workers by PUMA
# NOTE: this requires the github version of tidycensus
# remotes::install_github("walkerke/tidycensus")
library(tidycensus)
library(tidyverse)
# get industry and race vars from census api
ind_pums <- get_pums(
variables = c("PUMA", "INDP", "RAC1P", "HISP"),
state = c("ME", "NH", "VT"),
recode = TRUE
)
# only keep those working in medical industry
# create new race/ethnicity recoded variable
# and get estimate by state and PUMA
ind_pums %>%
filter(str_starts(INDP_label, "MED")) %>%
mutate(
race_eth = case_when(
HISP != "01" ~ "Latino",
RAC1P == 1 ~ "White",
RAC1P == 2 ~ "Black",
RAC1P %in% c(3, 4, 5, 7) ~ "Native American",
RAC1P == 6 ~ "Asian",
TRUE ~ "Other"
)
) %>%
count(ST_label, PUMA, race_eth, wt = PWGTP)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment