get_co_puma: See which PUMAs intersect which counties.

View source: R/get_co_puma.R

get_co_pumaR Documentation

See which PUMAs intersect which counties.

Description

This function defines the county associated with a PUMA. In some cases, multiple PUMAs fall within one county, such as in urban areas. In other situations, multiple counties may fall within one PUMA, such as in rural situations. Tracts nest within PUMAs so this

Usage

get_co_puma(st, yr = NULL, ...)

Arguments

st

Study state or states

yr

PUMA year Default "NULL"

...

Other keyword arguments

Value

A data frame of PUMA and county FIPS codes

Examples

## Not run: 
devtools::install_github("timathomas/neighborhood", ref = "main")
#
# Pull PUMS data
# --------------------------------------------------------------------------

pums_var <- pums_variables %>% filter(year == 2021, survey == "acs5")
pums_var %>%
  distinct(var_code, var_label, data_type, level) %>%
  filter(level == "housing") %>%
  select(-level) %>%
  arrange(var_code) %>%
  data.frame()

pums_var %>% filter(grepl("AGE", var_code)) %>% data.frame()
pums_var %>% filter(grepl("code", var_label)) %>% count(var_label) %>% data.frame()
pums_var %>% count(var_label) %>% data.frame()

#
# Create PUMS dataset with PUMA, Sex, Age, Race, Hispanicity, and Tenure in
# our study area.
# --------------------------------------------------------------------------

study_pumas <- get_co_puma("OR", 2021)

pums <-
  get_pums(
    variables = c("PUMA", "SEX", "AGEP", "RAC1P", "HISP", "HHT"),
    state = "OR",
    survey = "acs5",
    year = 2021,
    variables_filter = list(
      # SPORDER = 1, # first person in house
      TEN = 3 # renters
    ),
    recode = TRUE
  )

#
# PUMS by Householder (i.e., head)
#
study_pums <-
  left_join(study_pumas, pums, by = c("PUMACE10" = "PUMA")) %>%
  mutate(
    race_eth = case_when(
      HISP != "01" ~ "Latine",
      HISP == "01" & RAC1P == "1" ~ "White",
      HISP == "01" & RAC1P == "2" ~ "Black",
      HISP == "01" & RAC1P == "6" ~ "Other", # for OR, Asian is other
      TRUE ~ "Other")
  ) %>%
  filter(AGEP >= 18, SPORDER == "1") %>%
  count(county, sex = SEX_label, race = race_eth, wt = WGTP) %>%
  group_by(county) %>%
  mutate(pums_total = sum(n))

data.frame(study_pums)

study_pums_head <-
  left_join(
    study_pums %>%
      group_by(county, race) %>%
      reframe(n = sum(n), pums_total = unique(pums_total)) %>%
      pivot_wider(names_from = race, values_from = n, names_prefix = "pums_"),
    study_pums %>%
      group_by(county, sex) %>%
      reframe(n = sum(n), pums_total = unique(pums_total)) %>%
      pivot_wider(names_from = sex, values_from = n, names_prefix = "pums_")
  ) %>%
  left_join(
    study_pums %>%
      group_by(county) %>%
      pivot_wider(names_from = c(race, sex), values_from = n, names_prefix = "pums_")
  )
data.frame(study_pums_head)

## End(Not run)

timathomas/neighborhood documentation built on Feb. 17, 2024, 11:44 a.m.