Look at the tract level, and the cbsa level
library(tidycensus)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
Census_2010 <- load_variables(2010, "acs5", cache = TRUE)
Census_2010 %>% filter(grepl("industry|occupation|employment", label, ignore.case = TRUE))
B24124 B24125 B24126 C24050 C24060 maybe are the variables we are interested in.
head(Census_2010 %>%
filter(grepl("^B24124", name)))
head(Census_2010 %>%
filter(grepl("^B24125", name)))
head(Census_2010 %>%
filter(grepl("^B24126", name)))
head(Census_2010 %>%
filter(grepl("^C24050", name)))
head(Census_2010 %>%
filter(grepl("^C24060", name)))
Get Tract data
library(purrr)
library(tidyr)
tables <- c("C24050", "C24060")
tract_MI <- map_dfr(
tables,
~ get_acs(
geography = "tract",
table = .x,
year = 2014,
survey = "acs5",
state = "MI"
) %>%
mutate(table = .x)
)
## Getting data from the 2010-2014 5-year ACS
## Warning: • You have not set a Census API key. Users without a key are limited to 500
## queries per day and may experience performance limitations.
## ℹ For best results, get a Census API key at
## http://api.census.gov/data/key_signup.html and then supply the key to the
## `census_api_key()` function to use it throughout your tidycensus session.
## This warning is displayed once per session.
## Getting data from the 2010-2014 5-year ACS
dplyr::glimpse(tract_MI)
## Rows: 337,560
## Columns: 6
## $ GEOID <chr> "26001000100", "26001000100", "26001000100", "26001000100", "…
## $ NAME <chr> "Census Tract 1, Alcona County, Michigan", "Census Tract 1, A…
## $ variable <chr> "C24050_001", "C24050_002", "C24050_003", "C24050_004", "C240…
## $ estimate <dbl> 483, 3, 49, 52, 13, 53, 43, 8, 27, 38, 108, 61, 14, 14, 131, …
## $ moe <dbl> 54, 5, 18, 21, 9, 20, 25, 8, 13, 15, 29, 28, 13, 11, 33, 5, 7…
## $ table <chr> "C24050", "C24050", "C24050", "C24050", "C24050", "C24050", "…
library(glue)
states_50dc <- c(state.abb, "DC")
safe_get_acs <- purrr::possibly(
.f = function(...) {
Sys.sleep(0.25)
get_acs(..., cache_table = TRUE)
},
otherwise = tibble()
)
acs5_year <- 2014
tract_all <- map_dfr(
states_50dc,
\(st) {
message(glue("Running state: {st}"))
map_dfr(
tables,
\(tb) {
message(glue(" table: {tb}"))
safe_get_acs(
geography = "tract",
table = tb,
year = 2014,
survey = "acs5",
state = st
) %>%
mutate(state = st, table = tb)
}
)
}
)
## Running state: AL
## table: C24050
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24050 and caching the dataset for faster future access.
## table: C24060
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24060 and caching the dataset for faster future access.
## Running state: AK
## table: C24050
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24050 and caching the dataset for faster future access.
## table: C24060
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24060 and caching the dataset for faster future access.
## Running state: AZ
## table: C24050
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24050 and caching the dataset for faster future access.
## table: C24060
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24060 and caching the dataset for faster future access.
## Running state: AR
## table: C24050
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24050 and caching the dataset for faster future access.
## table: C24060
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24060 and caching the dataset for faster future access.
## Running state: CA
## table: C24050
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24050 and caching the dataset for faster future access.
## table: C24060
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24060 and caching the dataset for faster future access.
## Running state: CO
## table: C24050
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24050 and caching the dataset for faster future access.
## table: C24060
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24060 and caching the dataset for faster future access.
## Running state: CT
## table: C24050
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24050 and caching the dataset for faster future access.
## table: C24060
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24060 and caching the dataset for faster future access.
## Running state: DE
## table: C24050
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24050 and caching the dataset for faster future access.
## table: C24060
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24060 and caching the dataset for faster future access.
## Running state: FL
## table: C24050
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24050 and caching the dataset for faster future access.
## table: C24060
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24060 and caching the dataset for faster future access.
## Running state: GA
## table: C24050
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24050 and caching the dataset for faster future access.
## table: C24060
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24060 and caching the dataset for faster future access.
## Running state: HI
## table: C24050
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24050 and caching the dataset for faster future access.
## table: C24060
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24060 and caching the dataset for faster future access.
## Running state: ID
## table: C24050
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24050 and caching the dataset for faster future access.
## table: C24060
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24060 and caching the dataset for faster future access.
## Running state: IL
## table: C24050
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24050 and caching the dataset for faster future access.
## table: C24060
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24060 and caching the dataset for faster future access.
## Running state: IN
## table: C24050
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24050 and caching the dataset for faster future access.
## table: C24060
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24060 and caching the dataset for faster future access.
## Running state: IA
## table: C24050
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24050 and caching the dataset for faster future access.
## table: C24060
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24060 and caching the dataset for faster future access.
## Running state: KS
## table: C24050
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24050 and caching the dataset for faster future access.
## table: C24060
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24060 and caching the dataset for faster future access.
## Running state: KY
## table: C24050
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24050 and caching the dataset for faster future access.
## table: C24060
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24060 and caching the dataset for faster future access.
## Running state: LA
## table: C24050
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24050 and caching the dataset for faster future access.
## table: C24060
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24060 and caching the dataset for faster future access.
## Running state: ME
## table: C24050
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24050 and caching the dataset for faster future access.
## table: C24060
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24060 and caching the dataset for faster future access.
## Running state: MD
## table: C24050
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24050 and caching the dataset for faster future access.
## table: C24060
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24060 and caching the dataset for faster future access.
## Running state: MA
## table: C24050
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24050 and caching the dataset for faster future access.
## table: C24060
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24060 and caching the dataset for faster future access.
## Running state: MI
## table: C24050
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24050 and caching the dataset for faster future access.
## table: C24060
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24060 and caching the dataset for faster future access.
## Running state: MN
## table: C24050
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24050 and caching the dataset for faster future access.
## table: C24060
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24060 and caching the dataset for faster future access.
## Running state: MS
## table: C24050
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24050 and caching the dataset for faster future access.
## table: C24060
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24060 and caching the dataset for faster future access.
## Running state: MO
## table: C24050
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24050 and caching the dataset for faster future access.
## table: C24060
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24060 and caching the dataset for faster future access.
## Running state: MT
## table: C24050
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24050 and caching the dataset for faster future access.
## table: C24060
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24060 and caching the dataset for faster future access.
## Running state: NE
## table: C24050
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24050 and caching the dataset for faster future access.
## table: C24060
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24060 and caching the dataset for faster future access.
## Running state: NV
## table: C24050
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24050 and caching the dataset for faster future access.
## table: C24060
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24060 and caching the dataset for faster future access.
## Running state: NH
## table: C24050
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24050 and caching the dataset for faster future access.
## table: C24060
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24060 and caching the dataset for faster future access.
## Running state: NJ
## table: C24050
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24050 and caching the dataset for faster future access.
## table: C24060
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24060 and caching the dataset for faster future access.
## Running state: NM
## table: C24050
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24050 and caching the dataset for faster future access.
## table: C24060
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24060 and caching the dataset for faster future access.
## Running state: NY
## table: C24050
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24050 and caching the dataset for faster future access.
## table: C24060
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24060 and caching the dataset for faster future access.
## Running state: NC
## table: C24050
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24050 and caching the dataset for faster future access.
## table: C24060
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24060 and caching the dataset for faster future access.
## Running state: ND
## table: C24050
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24050 and caching the dataset for faster future access.
## table: C24060
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24060 and caching the dataset for faster future access.
## Running state: OH
## table: C24050
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24050 and caching the dataset for faster future access.
## table: C24060
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24060 and caching the dataset for faster future access.
## Running state: OK
## table: C24050
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24050 and caching the dataset for faster future access.
## table: C24060
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24060 and caching the dataset for faster future access.
## Running state: OR
## table: C24050
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24050 and caching the dataset for faster future access.
## table: C24060
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24060 and caching the dataset for faster future access.
## Running state: PA
## table: C24050
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24050 and caching the dataset for faster future access.
## table: C24060
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24060 and caching the dataset for faster future access.
## Running state: RI
## table: C24050
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24050 and caching the dataset for faster future access.
## table: C24060
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24060 and caching the dataset for faster future access.
## Running state: SC
## table: C24050
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24050 and caching the dataset for faster future access.
## table: C24060
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24060 and caching the dataset for faster future access.
## Running state: SD
## table: C24050
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24050 and caching the dataset for faster future access.
## table: C24060
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24060 and caching the dataset for faster future access.
## Running state: TN
## table: C24050
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24050 and caching the dataset for faster future access.
## table: C24060
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24060 and caching the dataset for faster future access.
## Running state: TX
## table: C24050
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24050 and caching the dataset for faster future access.
## table: C24060
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24060 and caching the dataset for faster future access.
## Running state: UT
## table: C24050
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24050 and caching the dataset for faster future access.
## table: C24060
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24060 and caching the dataset for faster future access.
## Running state: VT
## table: C24050
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24050 and caching the dataset for faster future access.
## table: C24060
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24060 and caching the dataset for faster future access.
## Running state: VA
## table: C24050
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24050 and caching the dataset for faster future access.
## table: C24060
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24060 and caching the dataset for faster future access.
## Running state: WA
## table: C24050
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24050 and caching the dataset for faster future access.
## table: C24060
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24060 and caching the dataset for faster future access.
## Running state: WV
## table: C24050
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24050 and caching the dataset for faster future access.
## table: C24060
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24060 and caching the dataset for faster future access.
## Running state: WI
## table: C24050
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24050 and caching the dataset for faster future access.
## table: C24060
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24060 and caching the dataset for faster future access.
## Running state: WY
## table: C24050
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24050 and caching the dataset for faster future access.
## table: C24060
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24060 and caching the dataset for faster future access.
## Running state: DC
## table: C24050
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24050 and caching the dataset for faster future access.
## table: C24060
## Getting data from the 2010-2014 5-year ACS
## Loading ACS5 variables for 2014 from table C24060 and caching the dataset for faster future access.
cbsa_all <- map_dfr(
tables,
~ get_acs(
geography = "cbsa",
table = .x,
year = 2014,
survey = "acs5"
) %>% mutate(table = .x)
)
## Getting data from the 2010-2014 5-year ACS
## Getting data from the 2010-2014 5-year ACS
glimpse(cbsa_all)
## Rows: 111,480
## Columns: 6
## $ GEOID <chr> "10100", "10100", "10100", "10100", "10100", "10100", "10100"…
## $ NAME <chr> "Aberdeen, SD Micro Area", "Aberdeen, SD Micro Area", "Aberde…
## $ variable <chr> "C24050_001", "C24050_002", "C24050_003", "C24050_004", "C240…
## $ estimate <dbl> 22721, 1545, 1328, 2887, 757, 2881, 825, 431, 1068, 1206, 551…
## $ moe <dbl> 436, 228, 246, 359, 156, 342, 181, 149, 196, 262, 444, 279, 2…
## $ table <chr> "C24050", "C24050", "C24050", "C24050", "C24050", "C24050", "…
#write.csv(tract_MI,"tract_MI.csv")
#write.csv(cbsa_all,"cbsa_all.csv")
#write.csv(tract_all,"tract_all.csv")