Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to pull state-wide 2017 ACS5 tract data via get_acs. #139

Closed
larcat opened this issue Dec 12, 2018 · 4 comments
Closed

Unable to pull state-wide 2017 ACS5 tract data via get_acs. #139

larcat opened this issue Dec 12, 2018 · 4 comments

Comments

@larcat
Copy link

larcat commented Dec 12, 2018

Still works fine for 2016, etc. See below. Dunno if this is a census issue or a tidycensus issue.

> test <- get_acs(table = "B01001",
+                 state = "KY",
+                 year = 2017,
+                 geography = "tract",
+                 cache_table = TRUE,
+                 geometry = FALSE)
Getting data from the 2013-2017 5-year ACS
Loading ACS5 variables for 2017 from table B01001 and caching the dataset for faster future access.
Using FIPS code '21' for state 'KY'
Error: Your API call has errors.  The API message returned is error: unknown/unsupported geography heirarchy.
> test <- get_acs(table = "B01001",
+                 state = "KY",
+                 year = 2016,
+                 geography = "tract",
+                 cache_table = TRUE,
+                 geometry = FALSE)
Getting data from the 2012-2016 5-year ACS
Loading ACS5 variables for 2016 from table B01001 and caching the dataset for faster future access.
Using FIPS code '21' for state 'KY'
Using FIPS code '21' for state 'KY'
Using FIPS code '21' for state 'KY'
> head(test)
# A tibble: 6 x 5
  GEOID       NAME                                      variable   estimate   moe
  <chr>       <chr>                                     <chr>         <dbl> <dbl>
1 21001970100 Census Tract 9701, Adair County, Kentucky B01001_001    1538.  178.
2 21001970100 Census Tract 9701, Adair County, Kentucky B01001_002     809.  104.
3 21001970100 Census Tract 9701, Adair County, Kentucky B01001_003      89.   41.
4 21001970100 Census Tract 9701, Adair County, Kentucky B01001_004      59.   35.
@walkerke
Copy link
Owner

@larcat it's an API-level issue. The new 5-year ACS release is currently restricted to tract queries within counties. I'm going to see if Census will resolve this - otherwise I'll have to handle this internally within the package.

@mfherman
Copy link
Collaborator

Until the Census API is fixed, you could use a workaround similar to the one described here #136 (comment) and #121 (comment). Basically, you loop through each of the counties, repeating your get_acs() call each time. For brevity sake, I pulled just B01001_001 instead of the entire table in the example below:

library(tidyverse)
library(tidycensus)

test <- map_dfr(
  filter(fips_codes, state == "KY")$county_code, 
  ~get_acs(
    variable = "B01001_001",
    state = "KY",
    county = .x,
    year = 2017,
    geography = "tract",
    geometry = FALSE,
    cache_table = TRUE
    )
  )
#> Getting data from the 2013-2017 5-year ACS

head(test)
#> # A tibble: 6 x 5
#>   GEOID      NAME                                  variable  estimate   moe
#>   <chr>      <chr>                                 <chr>        <dbl> <dbl>
#> 1 210019701… Census Tract 9701, Adair County, Ken… B01001_0…     1630   204
#> 2 210019702… Census Tract 9702, Adair County, Ken… B01001_0…     1846   202
#> 3 210019703… Census Tract 9703, Adair County, Ken… B01001_0…     3159   351
#> 4 210019704… Census Tract 9704.01, Adair County, … B01001_0…     4657   413
#> 5 210019704… Census Tract 9704.02, Adair County, … B01001_0…     4174   378
#> 6 210019705… Census Tract 9705, Adair County, Ken… B01001_0…     2271   247

Created on 2018-12-12 by the reprex package (v0.2.1)

@walkerke
Copy link
Owner

Your code now works as of this morning, @larcat.

@larcat
Copy link
Author

larcat commented Dec 13, 2018

Thank you all for the responses!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants