Due 2/9 by the start of class.
This week you’re going to try pulling American Community Survey data
from the census using tidycensus – this turns out to be a
very useful resource so I want everyone to have some experience with
it!
The goal is to create a dataset that helps us understand the prevalence of children in in limited English speaking households for all counties in Virginia.
Start an instance of RStudio using the project file inside your
learningR folder. Start a new script (saved in your scripts folder) that
loads tidyverse and tidycensus and then does
the following:
Run the following code chunk to acquire estimates of the population of school-aged children (5 to 17) within each county/locality in Virginia from the ACS 2017-2021 survey. This will provide a denominator so you can generate a percent later.
popvars <- c(b59 = "B01001_004",
b1014 = "B01001_005",
b1517 = "B01001_006",
g59 = "B01001_028",
g1014 = "B01001_029",
g1517 = "B01001_030")
pop517 <- get_acs(geography = "county",
state = "51",
year = 2021,
survey = "acs5",
var = popvars,
output = "tidy")
pop517 <- pop517 %>%
group_by(GEOID, NAME) %>%
summarize(pop517 = sum(estimate)) %>%
ungroup()
Now write your own code to download data from Table B16003 on the number of children aged 5 to 17 in limited English speaking households for all counties in Virginia from the ACS 2017-2021 survey. It might help you to have a look at the table before hand (linked above) and to scan the explanation of this set of tables at Census Reporter.
detail_vars <- load_variables(2021, "acs5", cache = TRUE)
will load a list of variables in the ACS as a data frame. You can
View() the data frame and search for the B16003 variable
IDs to find specific cell names. I would definitely start by creating a
vector of variables to pull.output = "tidy" as in the population
code chunk above.Get familiar with both newly downloaded data sets with some combination of glimpse or str, head or tail, and summary. What’s the smallest number of children aged 5-17 in a county? The largest?
Create a new data frame that sums up the number of children in households across all language categoried provided (that is, generate the total number of children in each county in limited Enlish speaking households using the data you’ve already pulled).
Join the population data to both of your language data sets (the
one containing the totals and the one disaggregating by language
categories) with the following command (change df to the
names of your data frames):
df <- df %>%
left_join(pop517)
For both data sets (the one containing totals for all counties and the one containing the number in each language category for all countes) generate a new variable called percent that is the percent of children in a county in a limited English speaking household/specific language speaking household.
Practice using the dplyr functions to explore the data containing the total number of children in any non-English speaking household.
Practice using dplyr functions to explore the data containing the numbero f children in non-English speaking households by language group.
variable, unless you
changed the column name along the way).Save the script into the scripts folder of your learningR folder.
When complete, submit this file to me via direct message on slack (give
it a name like week3_mpc.R as I’ll be adding everyone’s to
the same script folder in my own version of this folder!)
For the coming week, teams should start the following (I’ll send more specific feedback to your initial work on Friday):
This work should be submitted to the stepping stones channel in slack so we can better learn from one another.
Artwork by @allison_horst