knitr::opts_chunk$set(
  echo = FALSE,
  message = FALSE,
  warning = FALSE,
  collapse = TRUE,
  comment = "#>"
)
library(cwi)
library(dplyr)
library(purrr)
compare_yrs <- function(yr, ret = FALSE) {
  yrs <- rlang::set_names(c(yr - 1, yr))
  short_yrs <- rlang::set_names(substr(yrs, 3, 4), sprintf("%s$", seq_along(yrs)))
  tbls <- purrr::map(yrs, cwi:::clean_acs_vars, "acs5")
  tbls <- purrr::map(tbls, mutate, table_num = stringr::str_remove(name, "_.+$"))
  tbls <- purrr::map(tbls, distinct, concept, table_num)
  tbls <- purrr::map(tbls, mutate, concept = stringr::str_squish(tolower(stringr::str_replace_all(concept, "20\\d{2}", "20xx"))))

  purrr::map(tbls, ~paste("Number of rows:", nrow(.)))

  out <- purrr::reduce(tbls, dplyr::full_join, by = "table_num", suffix = as.character(c(1, 2)))
  out <- dplyr::filter(out, concept1 != concept2 | is.na(concept1) | is.na(concept2))
  out <- dplyr::rename_with(out, ~stringr::str_replace_all(., short_yrs), .cols = dplyr::matches("concept\\d"))

  print(knitr::kable(out))

  if (ret) {
    return(out)
  }
}

2022 ACS

compare_yrs(2022)

2021 ACS

compare_yrs(2021)

2020 ACS

compare_yrs(2020)

Not a lot new in the 2020 ACS.


2019 ACS

New tables

The 2019 ACS included reengineering of a few tables, and a few new additions. Some are clarifications of phrasing to both questions and tables, such as time leaving home for work. More substantial are the changes in how family structure has been phrased to be more inclusive of same-sex and unmarried couples--see the most recent working paper on this.

This is just a quick check of what's new or changed.

change19 <- compare_yrs(2019, ret = TRUE)

Variables in the tables related to gender & family structure:

acs19 <- cwi:::clean_acs_vars(2019, "acs5") |>
  mutate(table_num = stringr::str_remove(name, "_.+$"))
change19 |>
  filter(grepl("(HOUSEHOLD|SPOUSE)", concept19)) |>
  inner_join(acs19, by = "table_num") |>
  split(~table_num) |>
  purrr::map(function(x) split(x, x$concept)) |>
  purrr::map_depth(2, separate_acs) |>
  purrr::map_depth(2, select, variable = name, matches("^x\\d+")) |>
  purrr::map_depth(2, knitr::kable)


CT-Data-Haven/cwi documentation built on July 1, 2024, 7:45 a.m.