Skip to content

Instantly share code, notes, and snippets.

@FeelingMathy
Forked from mfherman/healthcare_race_pums.R
Created August 2, 2020 20:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FeelingMathy/dc7d26e6032c0075dcbe7cd07eae8fcd to your computer and use it in GitHub Desktop.
Save FeelingMathy/dc7d26e6032c0075dcbe7cd07eae8fcd 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