Comparing ACS estimates for multiple years
The American Community Survey is updated every year, which allows researchers to use ACS datasets to study demographic changes over time.
In this exercise, you'll learn how to use the tidyverse function map_df()
to work with multi-year ACS data. map_df()
helps analysts iterate through a sequence of values, compute a process for each of those values, then combine the results into a single data frame. You'll be using map_df()
in this way with ACS data, as you iterate through a vector of years, retrieve ACS data for each year, and combine the results. This will allow you to view how ACS estimates have changed over time.
This exercise is part of the course
Analyzing US Census Data in R
Exercise instructions
- Use the tidyverse
map_df()
function to specify that you'll be iterating through the vector of years2012:2016
. - Specify the survey as
"acs1"
to get data from the 1-year ACS. - Use the
mutate()
function to calculate a new column which will store the survey year in your output data frame.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Map through ACS1 estimates to see how they change through the years
mi_cities <- ___(2012:2016, function(x) {
get_acs(geography = "place",
variables = c(totalpop = "B01003_001"),
state = "MI",
survey = ___,
year = x) %>%
___(year = x)
})
mi_cities %>% arrange(NAME, year)