walkerke / tidycensus

Load US Census boundary and attribute data as 'tidyverse' and 'sf'-ready data frames in R
https://walker-data.com/tidycensus
Other
639 stars 100 forks source link

urban area not working for get_acs #306

Closed JoshRoll closed 4 years ago

JoshRoll commented 4 years ago

Hi there, Trying to get urban area level geography out of get_acs and getting the message & error: Getting data from the 2014-2018 5-year ACS Using FIPS code '41' for state 'OR' Error: Your API call has errors. The API message returned is error: unknown/unsupported geography heirarchy.

I am supplying the following as a call to the API: Load_Census.. <- get_acs(geography = "urban area", variables ="B17001_001", state = "OR", output = "wide", year = 2018, geometry = F, key = Developer_Key)

Based on this link it appears "urban area" is a valid geography so hopefully its not jsut my other query elements that are the problem, though this was working for county, tract, and block group. Either way i have not seen an example anywhere of someone using get_acs with urban area so maybe any answer here will be of use to the larger community.

szimmer commented 4 years ago

Urban areas are not within states. If you look at the table you linked, you'll see "urban area" is not available by state. You could try to filter to only areas that involve Oregon as I show below:

library(tidycensus)
library(tidyverse)

pull <- get_acs(geography = "urban area", variables ="B17001_001", output = "wide", year = 2018, geometry = FALSE, show_call = TRUE)
#> Getting data from the 2014-2018 5-year ACS
#> Census API call: https://api.census.gov/data/2018/acs/acs5?get=B17001_001E%2CB17001_001M%2CNAME&for=urban%20area%3A%2A

pull_or <- pull %>%
  separate(NAME, into=c("ClusterCity", "Tail"), sep=",", remove=FALSE) %>%
  mutate(Tail=str_trim(Tail)) %>%
  separate(Tail, into=c("States", "U", "AC", "Year"), sep=" ") %>%
  filter(str_detect(States, "OR")) %>%
  select(-c(U, AC, Year))

pull_or %>% count(States)
#> # A tibble: 5 x 2
#>   States     n
#>   <chr>  <int>
#> 1 ID--OR     1
#> 2 OR        64
#> 3 OR--ID     1
#> 4 OR--WA     3
#> 5 WA--OR     2

Created on 2020-10-06 by the reprex package (v0.3.0)

JoshRoll commented 4 years ago

Oh shoot i didn't see that urban areas are not within state, its the only one in the mess of geographies where state is available in that list. This is very helpful and i will close this.