Working With Census API and ACS 5-year data

've just started working with Census APIs, and so far I'm loving what this can do to improve my work flow when working with American Community Survey Data.

For most of the data work I'm doing, my primary geographic level is the county subdivision. BUT, I also like to include data for each of the counties I'm working with, and the state level.

I know how to access EACH of those three levels, but I'm not sufficiently familiar with JSON programming protocols to know how (or whether) I can combine multiple geographic LEVELS in a single API data call?

I have been looking at the EXAMPLES found here [https://api.census.gov/data/2019/acs/acs5/examples.html], and don't see any that combine multiple geographic levels, but I strongly suspect this is something I should be able to do?

Thanks for any assistance folks can offer.

Cheers, Doug.

P.S FYI, this is me here: www.twitter.com/DougHallPhd and here: https://www.linkedin.com/in/douglashallphd/ 

Parents
  • tidycensus has lots more to recommend it--more output options, getting spatial data in the same query, etc. And if you want block group data, which needs to be queried county-by-county, tidycensus will do this in one query and combine the results. 

    There's also the censusapi package, which allows access to a wider variety of datasets but is more stripped-down in that you need to format arguments exactly as the API requires--for example, using FIPS codes directly instead of having tidycensus translate state/county abbreviations/names for you). The advantage is that censusapi tends to be around 25%-50% faster in my experience, though I haven't done any formal benchmarking. In absolute terms, this doesn't matter much--only 1-3 seconds per query--but that can still result in substantial time savings if you need data for several tables and/or geographic levels.

    I know this isn't an R forum, but since you expressed interest: working with the Census Bureau API really helped me learn more R, especially in writing functions and understanding the many capabilities of the purrr package. In addition to map_dfr(), which Matt H used above to append data for multiple geographic levels, map_dfc() will join data for multiple tables (but to be on the safe side, you'll want to make sure whatever function you're using will sort the data that map_dfc() combines, because you can't specify a join-by variable).

    Good luck!

    ~~~ Edit 15 minutes later: I just realized that it's now possible to put wildcard characters in the query, which (for example) will let you get block groups for an entire state at once rather than county-by-county. This seems to magnify the time savings of censusapi over tidycensus. It doesn't solve the initial problem of combining data from multiple geographic levels, but it seemed worth mentioning.

  • Interesting about the speed difference between tidycensus and censusapi. I wonder if that is in the parsing of the API response -- if I have some time, I'll check it out. 

    As to wildcards for all block groups, we got an issue tracking that and hope to implement it at some point soon!

Reply Children
No Data