get_acs_cces: Obtain a ACS tabulation from tidycensus

View source: R/get_acs-poststrat.R

get_acs_ccesR Documentation

Obtain a ACS tabulation from tidycensus

Description

This loads ACS counts via tidycensus and gives them additional labels and renames some variables to later merge with CCES-based regression models.

Usage

get_acs_cces(
  varlist,
  varlab_df = ccesMRPprep::acscodes_df,
  year = 2018,
  states = NULL,
  dataset = "acs1",
  geography = "congressional district"
)

Arguments

varlist

a vector of variable codes to pull

varlab_df

a dataframe that appends the categories based on the varcode

year

The year of the ACS to get. Because of data availability limitations, this is capped to 2010-2018.

states

A vector of states to subset to. Gets passed onto the new state argument in tidycensus::get_acs(), which defaults to NULL.

dataset

Which type of ACS to get. Defaults to "acs1" for ACS-5 year. Use "acs5" for 5-year.

geography

the type of geography to pull. Currently only supports "congressional district".

Details

To run this, you need to have a API token to run get_acs. See census_api_key for details.

See Also

get_acs_cces

Examples

## Not run: 
 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)

## End(Not run)


kuriwaki/ccesMRPprep documentation built on July 27, 2023, 3:34 a.m.