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

Failure for tract-level estimate from 1990 census #76

Closed mattwilliamson13 closed 5 years ago

mattwilliamson13 commented 6 years ago

Hello, I have been attempting to download median income values for Miami-Dade County, FL (previously Dade County) from the 1990 Decennial Census using:

e.1990 = reduce(
     map(cty, function(x) {
     tidycensus::get_decennial(geography = "tract", year=1990, variables="P080A001", 
          state="FL", county = "025")
    }), rbind)

This returns the following error:

Getting data from the 1990 decennial Census
Using FIPS code '12' for state 'FL'
Error : Result 1 is not a length 1 atomic vector
In addition: Warning messages:
1: '025' is not a valid FIPS code for counties in Florida
2: '025' is not a valid FIPS code for counties in Florida
Error in gather_(data, key_col = compat_as_lazy(enquo(key)), value_col = compat_as_lazy(enquo(value)),  :
  unused argument (-NAME)

I assume this has something to do with the change from Dade County (FIPS 12025) to Miami-Dade County (FIPS 12086); however, attempting to use the new FIPS code also fails. Moreover, if I insert the codes in the Census API link, I can see the data exists there. I'm not sure if there is some sort of internal check in tidycensus that is causing it to throw an error before checking the API or if the problem is deeper than that. Any thoughts would be most appreciated.

walkerke commented 6 years ago

That's a bug. I'll put it on my to-do list.

mattwilliamson13 commented 6 years ago

The same thing happens for MT (20) Yellowstone National Park (113) and VA (51) Clifton Forge City (560). I also get the

Error : Result 1 is not a length 1 atomic vector

for NJ, but it does not identify the county that is causing the problem.

walkerke commented 6 years ago

Thanks, that's helpful! The issue is that tidycensus validates state/county requests before passing them to the Census API; this is how users can pass county names instead of FIPS codes. I have some county changes caught in there but not the ones that go back to 1990.

As an FYI it probably won't be until the 2nd week of June that I can put some serious dev time into tidycensus and resolve these issues, as I have other work responsibilities until then. If you need the data right away, I'd recommend the censusapi package (https://github.com/hrecht/censusapi) which accepts rawer input to the Census API.

Here's how:

library(censusapi)

key <- Sys.getenv("CENSUS_API_KEY") # using the stored tidycensus API key

dade <- getCensus(name = "sf3", 
                  vintage = 1990, 
                  key = key, 
                  vars = "P080A001", 
                  region = "tract:*", 
                  regionin = "state:12+county:025")
rhaefer commented 5 years ago

Has there been any progress made on this issue? I still get an error when using get_decennial to access 1990 tract level data for a list of counties in California. Thanks!

walkerke commented 5 years ago

This is fixed temporarily as of https://github.com/walkerke/tidycensus/commit/dff3b656991c1078448a48c87e5540b47a6b5b10. I still don't have capacity to put in 1990 names and convert them to FIPS codes. However, if you have the 1990 FIPS codes, it will work.

drewcanf commented 5 years ago

I am still finding the Miami-Dade County issue when trying to get 2012 5-year estimates at the block group level. Was this ever resolved?

This is what I'm using:

get_acs(geography = "block group", variables = "B19013_001", state = "FL", county = "Miami-Dade County", geometry = TRUE, year= 2012,

mfherman commented 4 years ago

This is a different issue -- block groups are not currently available for years before 2013 via the API. If you look at the available geographies, you don't find block group for 2012: https://api.census.gov/data/2012/acs/acs5/examples.html

This call works for 2013 and later:

library(tidycensus)
get_acs(geography = "block group",
        variables = "B19013_001",
        state = "FL",
        county = "Miami-Dade County",
        geometry = FALSE,
        year= 2013
        )
#> Getting data from the 2009-2013 5-year ACS
#> # A tibble: 1,594 x 5
#>    GEOID      NAME                                     variable  estimate    moe
#>    <chr>      <chr>                                    <chr>        <dbl>  <dbl>
#>  1 120860001… Block Group 1, Census Tract 1.07, Miami… B19013_0…    87885 174277
#>  2 120860001… Block Group 2, Census Tract 1.07, Miami… B19013_0…    50256   5792
#>  3 120860001… Block Group 1, Census Tract 1.09, Miami… B19013_0…    29563   4409
#>  4 120860001… Block Group 1, Census Tract 1.13, Miami… B19013_0…    75375  25789
#>  5 120860001… Block Group 2, Census Tract 1.13, Miami… B19013_0…    30938  18562
#>  6 120860001… Block Group 3, Census Tract 1.13, Miami… B19013_0…    52130  17108
#>  7 120860001… Block Group 4, Census Tract 1.13, Miami… B19013_0…    50658  29866
#>  8 120860001… Block Group 5, Census Tract 1.13, Miami… B19013_0…    71279  61897
#>  9 120860001… Block Group 1, Census Tract 1.15, Miami… B19013_0…    68528   5218
#> 10 120860001… Block Group 2, Census Tract 1.15, Miami… B19013_0…   129583  39169
#> # … with 1,584 more rows

Created on 2019-11-17 by the reprex package (v0.3.0)

corybriar commented 4 years ago

I've been having similar problems recently:

get_decennial(geography = "tract", variables = c(population = "POP100"), state = state_fips, year = 1990, geometry = T, output = "wide") returns

Error : Your API call has errors. The API message returned is <html><head><title>Error report</title></head><body><h1>HTTP Status 404 - /data/1990/sf3</h1></body></html>. Error in UseMethod("select_") : no applicable method for 'select_' applied to an object of class "character"

I know that having the wrong variable names can trigger this warning, but I'm using variable that worked a few months ago. Now they aren't. I've also been having trouble getting load_variables(1990,"sf3") to run (as well as with sf1), I mentioned this in a separate comment board (#189 ).

mfherman commented 4 years ago

Unfortunately, 1990 SF1/SF3 and 2000 SF3 are still not available via API from the Census. See #293 for more discussion.