hrecht / censusapi

R package to retrieve U.S. Census data and metadata via API
https://www.hrecht.com/censusapi/
169 stars 31 forks source link

Issue Calling on Zip Code Tabulation Areas in a County #26

Closed mrworthington closed 7 years ago

mrworthington commented 7 years ago

Hey! This is an amazing tool, but am running into a snag when I start looking up zip codes within a given county for ACS 2015, 5-Year Estimates. When I called on available geographies, it said zip code tabulation areas are one of them. As I began calling on state data and then Texas county data, everything populated correctly. As I called on zip codes in Bexar County, that's when errors started popping up. Specifically, the errors read, Error: error: unknown/unsupported geography heirarchy and I cannot figure out why. I've looked everywhere in the documentation, but can't seem to figure out why this error is generating. Also, in place of my API key, I have written key="REMOVED".

# County-Level Data
ed25TXcounty <- getCensus(name="acs5", vintage = "2015",
vars=c("NAME", "B15003_001E", "B15003_002E", "B15003_003E", "B15003_004E", "B15003_005E", "B15003_006E", "B15003_007E", "B15003_008E", "B15003_009E", "B15003_010E", "B15003_011E", "B15003_012E", "B15003_013E", "B15003_014E", "B15003_015E", "B15003_016E", "B15003_017E", "B15003_018E", "B15003_019E", "B15003_020E", "B15003_021E", "B15003_022E", "B15003_023E", "B15003_024E", "B15003_025E"), 
region="county:*", regionin="state:48",
key="REMOVED")
# Bexar County Data
ed25Bexarcounty <- getCensus(name="acs5", vintage = "2015",
vars=c("NAME", "B15003_001E", "B15003_002E", "B15003_003E", "B15003_004E", "B15003_005E", "B15003_006E", "B15003_007E", "B15003_008E", "B15003_009E", "B15003_010E", "B15003_011E", "B15003_012E", "B15003_013E", "B15003_014E", "B15003_015E", "B15003_016E", "B15003_017E", "B15003_018E", "B15003_019E", "B15003_020E", "B15003_021E", "B15003_022E", "B15003_023E", "B15003_024E", "B15003_025E"), 
region="zip code tabulation area:*", regionin="state:48+county:029", key="REMOVED")
hrecht commented 7 years ago

Hi @mrworthington, thanks for the detailed example. The ACS API appears to be down right now so I can't verify but I'm nearly certain that the issue is the spaces in region="zip code tabulation area:*"

Try replacing those spaces with + : so region="zip+code+tabulation+area:*" If that works, I'll add a note on using plus signs to the documentation - it should definitely be mentioned.

hrecht commented 7 years ago

Spoke too soon. It appears that the issue is actually like the error message states, that zip code within county isn't an available geography hierarchy. If you check out the geography for acs5 by running listCensusMetadata("acs5", 2015, "geography") ZCTA appears to be only available as a geography on its own, not within states or counties.

Running this works:

ed25TXzip <- getCensus(name="acs5", vintage = "2015",
vars=c("NAME", "B15003_001E", "B15003_002E", "B15003_003E", "B15003_004E", "B15003_005E", "B15003_006E", "B15003_007E", "B15003_008E", "B15003_009E", "B15003_010E", "B15003_011E", "B15003_012E", "B15003_013E", "B15003_014E", "B15003_015E", "B15003_016E", "B15003_017E", "B15003_018E", "B15003_019E", "B15003_020E", "B15003_021E", "B15003_022E", "B15003_023E", "B15003_024E", "B15003_025E"), 
region="zip code tabulation area:*")

But adding regionin=="state:48" gives the same error: unknown/unsupported geography heirarchy. You can also see that by viewing http://api.census.gov/data/2015/acs5?get=NAME,B01001_001E&for=zip+code+tabulation+area:*&in=state:48

So, you could get your data for all ZCTAs instead or if you have a list of zip codes you could specify those as region=zip code tabulation area:XXXXX,YYYYY,ZZZZ. Hope that helps!

This "unsupported geography" error message from the APIs would be good to supplement in censusapi with some instructions. I'll open that as a new issue.

mrworthington commented 7 years ago

Ah, I see. My initial concern was that I seem to have overlooked the "required" column tht explains dependents, given that I had tried adding the + operators after getting the error. I'll just get a list of zip codes and pull it that way. Thanks!