Username
Username

Reputation: 3663

error: unknown/unsupported geography heirarchy when querying data for all ZCTA5s

I'm trying to query data with the R package "censusapi."

The following code...

getCensus(
     name = "sf1",
     vars = c("P0010001"),
     region = "zip code tabulation area:*",
     vintage = 2010,
     key = Sys.getenv("CENSUS_KEY")
 )

...throws this error... Error: error: unknown/unsupported geography heirarchy.

Any idea what I need to fix here so I can get 2010 population data for every ZCTA5? Replacing "zip code tabulation area:*" with `"county:*" works fine, by the way...

Upvotes: 1

Views: 3526

Answers (1)

camille
camille

Reputation: 16871

Take a look at the Census API documentation. ZCTA is nested under states in the geography hierarchy. Seems a little odd, since normally ZCTAs are supposed to be independent of states or counties. The more "pure" ZCTA has a level number 860; the one nested under states has level 871. I have no idea how much they may differ.

So for ZCTAs, you need to give it a state in regionin, like:

censusapi::getCensus("sf1", 
    vars = c("P0010001"), 
    region = "zip code tabulation area:*", 
    vintage = 2010, 
    key = Sys.getenv("CENSUS_KEY"), 
    regionin = "state:09")

If you needed zips for every state, you might be stuck applying or mapping over all states' FIPS codes and plugging into regionin.

Upvotes: 1

Related Questions