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

Variables not available for ACS 2005-2009 #424

Closed wzpeve closed 2 years ago

wzpeve commented 2 years ago

I get the "unknown variable" error when trying to get data from 2005-2009 ACS, although the variables clearly exist for this survey and I could pull the data from census API directly. For example:

df <- get_acs(geography = "tract",
              variables = c("B08101_001"),
              year = 2009,
              state = "NY",
              output = "wide")

Error: Your API call has errors.  The API message returned is error: error: unknown variable 'B08101_001E'.
Traceback:

1. get_acs(geography = "tract", variables = c("B08101_001"), year = 2009, 
 .     state = "NY", output = "wide", geometry = FALSE)
2. suppressWarnings(load_data_acs(geography, vars, key, year, state, 
 .     county, zcta, survey, show_call = show_call))
3. withCallingHandlers(expr, warning = function(w) if (inherits(w, 
 .     classes)) tryInvokeRestart("muffleWarning"))
4. load_data_acs(geography, vars, key, year, state, county, zcta, 
 .     survey, show_call = show_call)
5. stop(sprintf("Your API call has errors.  The API message returned is %s.", 
 .     msg), call. = FALSE)

The same code runs with no problem for 2015-2019 ACS. So far I've run into this issue for tables B08101, B21005, B08126, B12006 but there could be more. I wonder if this is a known issue?

walkerke commented 2 years ago

Could you share the direct API call that is working for you? I see at https://api.census.gov/data/2009/acs/acs5?get=NAME,B08101_001E&for=state:* the error message you shared.

wzpeve commented 2 years ago

This is what I just tried:

https://api.census.gov/data/2009/acs5?get=B08101_001E,NAME&for=tract&in=state:01

Edit: it seems like the /acs part after 2009 is the problem? But it only affects some variables in 2009 - odd! Also for the variable list: https://api.census.gov/data/2009/acs5/variables.html

walkerke commented 2 years ago

Hmm - we had this discussion years ago: https://github.com/walkerke/tidycensus/issues/122 and https://github.com/walkerke/tidycensus/issues/227.

Census was supposed to have removed that endpoint and it appears that it did so for 2010 and later, but did not for 2009. I'll cross-reference this issue over on the Census's issue tracker. I'm not going to do a temporary fix as we can see with #227 that it creates downstream problems for other queries, so Census will need to fix on their end In the meantime you may want to consider the censusapi package (https://github.com/hrecht/censusapi) which allows for more custom construction of API calls.

wzpeve commented 2 years ago

Okay, thank you & happy new year!