Happy Labor Day!
I was wondering if the CTPP API could be used for CTPP data other than the most recent
2017-2021 release. The short answer is: yes.
It’s important to keep the CTPP Data Portal website open, to check the various tables for
the various packages. Be careful, since table numbering is different with the four
different packages.
The API works flawlessly for the year 2000 decennial census CTPP, and the three ACS-based
packages: 2006-2010, 2012-2016 and 2017-2021.
I’ve included R scripts that pull the county-to-county by detailed means of
transportation, for California, from the four packages.
https://github.com/chuckpurvis/r_scripts/blob/main/ctpp_multi_calif_b302103…
r_scripts/ctpp_multi_calif_b302103_county2county_1.R at main · chuckpurvis/r_scripts
github.com
https://github.com/chuckpurvis/r_scripts/blob/main/ctpp_multi_calif_county2…
r_scripts/ctpp_multi_calif_county2county_cleanup.R at main · chuckpurvis/r_scripts
github.com
Another concern was how to extract data from more than one state. The modification to my
California script was very simple. My example is the three state/district region of the
District of Columbia, Maryland State and Virginia State.
# CTPP 2017-2021. Table B302103. Flow of Workers by Means of Transportation (18) by
# county-to-county flows within DC + MD + VA
query01 <- list('get'='group(B302103)',
'in'='state:11,24,51', # DC +
MD + VA
'for'='county:*', # All DC +
MD + VA Counties of RESIDENCE
'd-in'='state:11,24,51', # DC +
MD + VA workplace
'd-for'='county:*', # All DC +
MD + VA Counties of WORKPLACE
'size'=5000,'page'=1) # limit to the first 5,000
county-to-county records
x <- httr::GET(url21, add_headers('x-api-key' = api_key),query=query01) #
httr function to call CTPP API
c <- rawToChar(x$content) # base R function to convert object to character....
r <- jsonlite::fromJSON(c) # jsonlite function to convert from JSON format to large
list
dataframe_1721 <-r$data # convert from list to data frame.
https://github.com/chuckpurvis/r_scripts/blob/main/ctpp_multi_mwcog_county2…
r_scripts/ctpp_multi_mwcog_county2county_1.R at main · chuckpurvis/r_scripts
github.com
I hope this is of interest.
Chuck Purvis
Hayward, California
# # #