Skip to content

UI-Research/crosswalk

Repository files navigation

crosswalk

R-CMD-check

An R package for translating data across space and time.

Overview

Census geographies change across time (tracts are redrawn every decade; counties are occasionally renamed, merged, or split), and many analyses need to move data between geographies that don’t nest within one another (ZCTAs to PUMAs, tracts to places). crosswalk provides a consistent interface for fetching the crosswalks that relate these geographies and for applying them to your data – adjusting source values by crosswalk weights to produce estimates for the target geography and year, with diagnostics describing the quality of the join between your data and the crosswalk.

Crosswalks are sourced from:

  • Geocorr (Missouri Census Data Center) – same-year crosswalks between geographies (Geocorr 2022 for 2020s geography; Geocorr 2018 for 2010s geography)
  • IPUMS NHGIS – inter-temporal (cross-decade) crosswalks
  • CT Data Collaborative – Connecticut’s 2020-2022 change from counties to planning regions
  • A curated registry of county change events (ships with the package) – county -> county crosswalks between any pair of years from 2000 onward

Why use crosswalk?

  • Programmatic access: no manual downloads from web interfaces, with optional local caching
  • Standardized output: consistent column names and structure across all crosswalk sources
  • Provenance and diagnostics: full crosswalk metadata and join-quality statistics attached to every result
  • Crosswalk chaining: transformations that change both geography and year are planned and applied automatically

Installation

# install.packages("pak")
pak::pak("UI-Research/crosswalk")

## or, in renv-managed projects
renv::install("UI-Research/crosswalk")

Quick start

Translate ZCTA-level poverty counts to PUMAs. crosswalk_data() fetches the needed crosswalk (here from Geocorr, population-weighted) and applies it; the count_ prefix tells it to treat the variable as a count (multiply by the allocation factor, then sum by target geography):

library(crosswalk)
library(dplyr)

zcta_poverty <- tidycensus::get_acs(
    year = 2023,
    geography = "zcta",
    output = "wide",
    variables = c(below_poverty = "B17001_002"),
    progress_bar = FALSE) |>
  select(
    source_geoid = GEOID,
    count_below_poverty = below_povertyE)

puma_poverty <- crosswalk_data(
  data = zcta_poverty,
  source_geography = "zcta",
  target_geography = "puma",
  weight = "population")

head(puma_poverty)
#> # A tibble: 6 × 3
#>   geoid   geography_name                                     count_below_poverty
#>   <chr>   <chr>                                                            <dbl>
#> 1 0100100 Lauderdale, Colbert & Franklin Counties                         27907.
#> 2 0100200 Limestone County                                                10927.
#> 3 0100300 Morgan & Lawrence Counties--Decatur City                        21102.
#> 4 0100401 Madison County (North & East)--Huntsville City (E…               8940.
#> 5 0100402 Huntsville (North & Far West), Madison (East) & T…              17422.
#> 6 0100403 Huntsville City (Central & South)                               12836.

To inspect or reuse a crosswalk, fetch it explicitly with get_crosswalk() and pass it to crosswalk_data():

zcta_to_puma <- get_crosswalk(
  source_geography = "zcta",
  target_geography = "puma",
  weight = "population")

puma_poverty <- crosswalk_data(
  data = zcta_poverty,
  crosswalk = zcta_to_puma)

Every result carries its provenance and join diagnostics as attributes:

## where did the crosswalk come from?
attr(puma_poverty, "crosswalk_metadata")$data_source_full_name
#> [1] "Geocorr 2022 (Missouri Census Data Center)"

## what share of data GEOIDs failed to match the crosswalk (and were dropped)?
attr(puma_poverty, "join_quality")$pct_data_unmatched
#> [1] 0.4234277

Core functions

Function Purpose
get_crosswalk() Fetch crosswalk(s), chaining steps automatically when geography and year both change
crosswalk_data() Apply crosswalk(s) to a dataset, interpolating count and non-count variables
get_available_crosswalks() List every supported geography/year combination and its source
list_nhgis_crosswalks() List the NHGIS (cross-decade) crosswalks specifically
get_available_crosswalks() |>
  head()
#> # A tibble: 6 × 5
#>   source_geography target_geography source_year target_year crosswalk_source
#>   <chr>            <chr>                  <int>       <int> <chr>           
#> 1 block            block                   1990        2010 nhgis           
#> 2 block            block                   2000        2010 nhgis           
#> 3 block            block                   2010        2011 county_events   
#> 4 block            block                   2010        2012 county_events   
#> 5 block            block                   2010        2013 county_events   
#> 6 block            block                   2010        2014 county_events

API keys

Store keys in your .Renviron (e.g., via usethis::edit_r_environ()). Geocorr and county-events crosswalks require no keys.

Caching

Pass a directory as the cache argument to get_crosswalk() or crosswalk_data() and each fetched crosswalk is saved there as a CSV; later calls with the same parameters read from disk instead of re-downloading. Cached files never expire – delete a file to force a re-download.

Learn more

Citations

Cite the organizations that produce the crosswalks returned by this package:

For NHGIS, see requirements at: https://www.nhgis.org/citation-and-use-nhgis-data

For Geocorr, a suggested citation (update the year):

Missouri Census Data Center, University of Missouri. (2022/2018). Geocorr 2022/2018: Geographic Correspondence Engine. Retrieved from: https://mcdc.missouri.edu/applications/geocorr2022/2018.html

For CTData, a suggested citation (adjust for alternate source geography):

CT Data Collaborative. (2023). 2022 Census Tract Crosswalk. Retrieved from: https://github.com/CT-Data-Collaborative/2022-tract-crosswalk.

For county change events, the underlying documentation is:

U.S. Census Bureau. Substantial Changes to Counties and County Equivalent Entities: 1970-Present. Retrieved from: https://www.census.gov/programs-surveys/geography/technical-documentation/county-changes.html

For this package, refer here: https://ui-research.github.io/crosswalk/authors.html#citation

About

An R package for translating data across space and time.

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages