This loads ACS counts via tidycensus and gives them additional labels and renames some variables to later merge with CCES-based regression models.
get_acs_cces(
varlist,
varlab_df = ccesMRPprep::acscodes_df,
year = 2018,
states = NULL,
dataset = "acs1",
geography = "congressional district"
)
a vector of variable codes to pull
a dataframe that appends the categories based on the varcode
The year of the ACS to get. Because of data availability limitations, this is capped to 2010-2018.
A vector of states to subset to. Gets passed onto the new state
argument in tidycensus::get_acs()
, which defaults to NULL.
Which type of ACS to get. Defaults to "acs1"
for ACS-5 year.
Use "acs5"
for 5-year.
the type of geography to pull. Currently only supports
"congressional district"
.
To run this, you need to have a API token to run get_acs. See census_api_key for details.
get_acs_cces
if (FALSE) { # \dontrun{
fm_brm <- yes | responses(n_cell) ~ age + gender + educ + pct_trump + (1|cd)
acs_tab <- get_acs_cces(
varlist = acscodes_age_sex_educ,
varlab_df = acscodes_df,
year = 2018)
# year cd gender age educ race count count_moe
# <dbl> <chr> <fct> <fct> <fct> <fct> <dbl> <dbl>
# 1 2018 AL-01 Male 18 to 24 years HS or Less NA 703 240
# 2 2018 AL-01 Male 18 to 24 years HS or Less NA 5665 581
# 3 2018 AL-01 Male 18 to 24 years HS or Less NA 11764 747
# 4 2018 AL-01 Male 18 to 24 years Some College NA 9528 750
# 5 2018 AL-01 Male 18 to 24 years Some College NA 1389 355
# 6 2018 AL-01 Male 18 to 24 years 4-Year NA 1519 276
poststrat <- get_poststrat(acs_tab, cd_info_2018, fm_brm)
} # }