Description Usage Arguments Details Value Note
View source: R/acs_functions.R
This function wraps around the tidycensus get_acs()
function to quietly collect 1-year ACS data for a set of counties, a set of peer MSAs, and the country. It collects data for a range of years, and if asked can iterate through racially-specific detailed census tables. It tracks suppressed data, and attempts to replace suppressed 1-year data with data from the 5-year ACS. Finally, it sums or calculates a weighted average for the set of counties. It defaults to CMAP's 7 county region, but this can be overridden for use by other regions.
1 2 3 4 |
table |
The ACS table to pull. This can be a regular (e.g. |
variables |
The ACS variable(s) to pull. This can be one (e.g. |
years |
The year (e.g. |
peers |
A tibble representing the list of MSAs to pull. This tibble must have a numeric variable |
racial |
Set to |
race |
Typically left as null. Can be used to attempt to overwrite the character value stored in the variable |
try_suppressed |
If |
avg_weight |
This function adds a summary row for data pulled at the county level. If |
state_fips |
Defaults to |
counties |
A vector of 3 digit FIPS codes representing counties. Defaults to the 7 county CMAP region unless overridden. |
racecode |
Ignore this variable. It is used in the recursive process when |
Requires packages tidyverse
and tidycensus
.
A tibble.
The output includes rows for GEOG = c("county", "MSA", "country")
. County rows are repeated by SURVEY = c("acs1", "acs5")
if suppressed 1-year data was replaced with 5-year data. A summary row (GEOG = "region"
) includes either sums or weighted averages for all variables. Note that 5-year data is used in calulating the summary row for ALL years for a given county if it is suppressed for even one year. The above rows are repeated for each YEAR
and each RACE
if racial = TRUE
.
The output includes columns for all specified variables, and their margins of error. The variable SUPPRESSED
represents the number of variables with suppressed data for the given geography and year. COUNT
is only populated for the regional summary row, and represents the number of non-suppressed counties feeding into the summary. If try_suppressed = TRUE
, COUNT
should equal len(counties)
but SURVEY
may equal "acs1,acs5" indicating some 5-year data was used. If try_suppressed = FALSE
, COUNT
may be less than the number of counties.
Any ACS table or vintage available on data.census.gov should be available through tidyverse and this function. As of tidycensus v0.9, there is an artificial limitation that prevents accessing 2010 and 2011 ACS data. This can be removed by deleting lines 45 to 48 in tidycensus::get_acs
. You can edit the function with the command trace("get_acs", edit=TRUE)
.
# The table B23001 for range of years data <- assemble_peer_acs("B23001", years = c(2014:2017))
# the racially-specific table B23002 for just one year assemble_peer_acs("B23002", years = 2015, racial=TRUE, try_suppressed = FALSE)
# a selection of variables for a range of years data <- assemble_peer_acs(variables = c("B23001_001", "B23001_002", "B23001_003"), years = 2014:2017)
# a selection of variables for a range of years, by race, with a weighted average data <- assemble_peer_acs(variables = c("B19013_001", "B01001_001"), years = 2014:2015, racial = TRUE, avg_weight = "B01001_001")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.