Skip to content

Instantly share code, notes, and snippets.

@chuckpurvis
chuckpurvis / lehdr_explore_2.r
Created March 29, 2022 21:31
Use the R package lehdr to explore the residence area charactieristics and work area characteristics of the Census Bureau LEHD / LODES databases.
####################################################################
## lehdr_explore_2.r
##
## Stage 2: Explore the Residence Area Characteristics (RAC) and
## Work Area Characteristics (WAC) files
##
## Explore the New (2/4/22) lehdr package.
## This package grabs and aggregates LEHD/LODES datasets
##
## Use purrr package to iterate on multiple years!
@chuckpurvis
chuckpurvis / ACS_AllYears_Journey2Work_purrr_revd.r
Last active March 17, 2022 20:45
R-script using tidycensus, purrr and dplyr to pull American Community Survey data for single years (2006-2019) and for 3 nonoverlapping 5-year periods: 2006-2010, 2011-2015, 2016-2020. The 2016-2020 5-year ACS data was released today, March 17, 2022. Note that the geographic boundaries from the 2016-2020 data are Census 2020 geographies. All oth…
########################################################################
# ACS_AllYears_Journey2Work_purrr_revd.r
# Use the purrr function map_dfr to iterate tidycensus call for 1-year, 5-year ACS data.
# Data on Means of Transportation to Work Variables, All ACS years
# Nation and US States and counties and places (added 1/28/22)
#
# American Community Survey, 1-year, 2005-2019 data
# ACS 5-year data: 2005-2009, 2010-2014, 2015-2019
# ACS 5-year data: 2006-2010, 2010-2014, 2015-2019 (this works for B08006....)
## ACS 5-year data: 2006-2010, 2011-2015, 2016-2020 @@ should work after 3/17/22.
@chuckpurvis
chuckpurvis / PL94171_Pennsyl_MCD_20002020.r
Created March 15, 2022 23:46
Use R package TIDYCENSUS to pull Decennial Census Data (2000, 2010, 2020) for Pennsylvania County Subdivisions, also known as Minor Civil Divisions, also known as Townships, Boroughs and Cities. Also, calculate a Shannon Diversity index for the 2020 MCDs in Pennsylvania
###################################################################
# PL94171_Pennsyl_MCD_20002020.r
# Use the R-package TIDYCENSUS to extract PL 94-171
# data from the Year 2000-2020 Decennial Censuses
# ALL Pennsylvania MCDs, 2000-2020
# -- March 15, 2022 --
###################################################################
# install the current working version of tidycensus
# remotes::install_github("walkerke/tidycensus")
@chuckpurvis
chuckpurvis / CTPPr_1216_Vermont_county2county.R
Created March 15, 2022 19:31
Analyze Vermont State tract-to-tract, MCD-to-MCD, and county-to-county total commuters from 2012-2016 CTPP. MCD = minor civil divisions, also more commonly known as "towns" in New England
##################################################################
# CTPPr_1216_Vermont_county2county.r
# Use the package CTPPr to get table A302100 from the
# 2012-2016 CTPP.
# Vermont
# County-to-County, and tract-to-tract summarized at County level
# -- March 15, 2022 --
##################################################################
# Install CTPPr onto local computer.. Just need to do once!
@chuckpurvis
chuckpurvis / CTPPr_1216_Delaware_county2county.R
Created March 14, 2022 19:41
Use the R package CTPPr to retrieve Delaware, intra-state, county-to-county commuters, and compare to tract-to-tract commuters (summed to county-to-county level)
##################################################################
# CTPPr_1216_Delaware_county2county.r
# Use the package CTPPr to get table A302100 from the
# 2012-2016 CTPP.
# Delaware
# County-to-County, and tract-to-tract summarized at County level
# -- February 21, 2022 --
##################################################################
# Install CTPPr onto local computer.. Just need to do once!
@chuckpurvis
chuckpurvis / CTPPr_1216_Alaska_county2county.R
Last active March 17, 2022 20:41
Use the web software Beyond 2020 to pull ACS-based CTPP 2012-2016 data for intra-state, Alaska, comparing county-to-county to tract-to-tract(summed to county-to-county level). The AASHTO site for retrieving the CTPP data is: http://data5.ctpp.transportation.org
##################################################################
# CTPPr_1216_Alaska_county2county.r
# Use Beyond2020 on the web to get table A302100 from the
# 2012-2016 CTPP.
# Alaska -- For whatever reason, CTPPr doesn't work for Alaska.....
# County-to-County, and tract-to-tract summarized at County level
# -- March 14, 2022 --
##################################################################
# Install CTPPr onto local computer.. Just need to do once!
# I'm just not sure about etiquette for updating packages!
@chuckpurvis
chuckpurvis / CTPPr_1216_Idaho_county2county.R
Created March 14, 2022 19:38
Compares county-to-county, intra-state, Idaho, from the ACS-based CTPP 2012-2016, at the county-to-county summary level, compared to tract-to-tract summary level summed to county-to-county
##################################################################
# CTPPr_1216_Idaho_county2county.r
# Use the package CTPPr to get table A302100 from the
# 2012-2016 CTPP.
# Idaho
# County-to-County, and tract-to-tract summarized at County level
# -- March 14, 2022 --
##################################################################
# Install CTPPr onto local computer.. Just need to do once!
@chuckpurvis
chuckpurvis / lehdr_explore_1.r
Created March 5, 2022 22:35
R script to pull Census Bureau LEHD/LODES data on commuting for California, Nevada using new package lehdr, and utilizing tidyverse packages purrr and dplyr.
####################################################################
## lehdr_explore_1.r
## Explore the New (2/4/22) lehdr package.
## This package grabs and aggregates LEHD/LODES datasets
##
## Use purrr package to iterate on multiple years!
## Use dplyr package to sort dataframe and re-order columns
##
## Now I know my ABCs....
## LED = Local Employment Dynamics
@chuckpurvis
chuckpurvis / CTPPr_1216_Calif_Place_VHH_HHSize_Tenure.r
Last active March 5, 2022 21:51
Extract a Data Table from the American Community Survey-based Census Transportation Planning Package, 2012-2016, using the R package CTPPr, and analyze using TIDYVERSE tools like dplyr. https://ctpp.transportation.org/
#########################################################
# CTPPr_1216_Calif_Place_VHH_HHSize_Tenure.r
# Use the package CTPPr to get table A112309 from the
# 2012-2016 CTPP. This is used instead of going to
# Beyond 2020 to download a CSV file.....
#
# "Three-Way CTPP Table"
#
# A112309 = Households by Household Size (5) by
# Vehicles Available (5) by
@chuckpurvis
chuckpurvis / ACS_AllYears_Journey2Work_purrr.r
Created February 21, 2022 20:07
American Community Survey, Multiple Years, Example using purrr and tidycensus, journey-to-work
########################################################################
# ACS_AllYears_Journey2Work_purrr.r
# Use the purrr function map_dfr to iterate tidycensus call for 1-year, 5-year ACS data.
# Data on Means of Transportation to Work Variables, All ACS years
# Nation and US States and counties and places (added 1/28/22)
#
# American Community Survey, 1-year, 2005-2019 data
# ACS 5-year data: 2005-2009, 2010-2014, 2015-2019
# ACS 5-year data: 2006-2010, 2010-2014, 2015-2019 (this works for B08006....)
## ACS 5-year data: 2006-2010, 2011-2015, 2016-2020 @@ should work after 3/17/22.