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

smaller geographies "unknown/unsupported" #489

Closed sjcromer closed 1 year ago

sjcromer commented 1 year ago

Hello! Thank you for this great package which I found from watching your Youtube tutorial.

I'm just getting started with ACS data and immediately encountered an issue with get_decennial() and get_acs(), both recognizing larger geographies (state, county, zcta) but not smaller geographies (tract, block). I am using the geography names you outlined here: https://walker-data.com/tidycensus/articles/basic-usage.html#geography-in-tidycensus Any advice?

Thanks for your help!

ct_race <- get_decennial(geography='zcta',variables='P013001',year=2010) Getting data from the 2010 decennial Census Using Census Summary File 1 ct_race

A tibble: 33,120 x 4

GEOID NAME variable value

1 77477 ZCTA5 77477 P013001 31.6 2 77478 ZCTA5 77478 P013001 44.3 3 77479 ZCTA5 77479 P013001 39 4 77480 ZCTA5 77480 P013001 39.6 5 77481 ZCTA5 77481 P013001 52.3 6 77482 ZCTA5 77482 P013001 40.3 7 77483 ZCTA5 77483 P013001 39.8 8 77484 ZCTA5 77484 P013001 37.7 9 77485 ZCTA5 77485 P013001 42.2 10 77486 ZCTA5 77486 P013001 40 # ... with 33,110 more rows ct_race <- get_decennial(geography='tract',variables='P013001',year=2010) Getting data from the 2010 decennial Census Error : Your API call has errors. **The API message returned is error: unknown/unsupported geography heirarchy.** Using Census Summary File 1 Error in UseMethod("gather") : no applicable method for 'gather' applied to an object of class "character"
walkerke commented 1 year ago

Thanks! If you get the hierarchy error, it means that your requested geography is not available at that hierarchy. In this case, tract-level data are available by state, but you haven't supplied a state. So this works:

library(tidycensus)

ct_race <- get_decennial(
  geography = 'tract',
  state = 'CT',
  variables = 'P013001',
  year = 2010
)
#> Getting data from the 2010 decennial Census
#> Using Census Summary File 1

ct_race
#> # A tibble: 833 × 4
#>    GEOID       NAME                                             variable value
#>    <chr>       <chr>                                            <chr>    <dbl>
#>  1 09009150300 Census Tract 1503, New Haven County, Connecticut P013001   43.3
#>  2 09009150600 Census Tract 1506, New Haven County, Connecticut P013001   42.5
#>  3 09009150700 Census Tract 1507, New Haven County, Connecticut P013001   42.6
#>  4 09009150900 Census Tract 1509, New Haven County, Connecticut P013001   45.1
#>  5 09009151000 Census Tract 1510, New Haven County, Connecticut P013001   46.2
#>  6 09009151100 Census Tract 1511, New Haven County, Connecticut P013001   44.2
#>  7 09009151200 Census Tract 1512, New Haven County, Connecticut P013001   46.2
#>  8 09009154100 Census Tract 1541, New Haven County, Connecticut P013001   35  
#>  9 09009154200 Census Tract 1542, New Haven County, Connecticut P013001   32.9
#> 10 09009154500 Census Tract 1545, New Haven County, Connecticut P013001   33.5
#> # … with 823 more rows

Created on 2022-12-07 with reprex v2.0.2

ZCTAs can be requested for the entire US, so that's why the result is different.

I'd recommend reading the following section of my book for more info on this topic: https://walker-data.com/census-r/an-introduction-to-tidycensus.html#geography-and-variables-in-tidycensus