library(tidyverse)
library(lehdr) # package documentation: https://github.com/jamgreen/lehdr
options(scipen=999)
# list of all states
<-c(state.abb, "DC") %>% str_to_lower()
states
####### ####### LEHS/LODES ####### #######
# tract level measures for total jobs pulled using LODES 2020
# format = read_lodes(state abbreviation, type=c(origin = OD, residence = rac, workplace = wac), segment id, job id, year)
# jobs by sector for both where people live (rac) and where people work (wac).
# call the LODES api for each year - Job type: all jobs
<- grab_lodes(state = states,
rac lodes_type = "rac", # residence area characteristics
segment = "S000", # total number of jobs
job_type = "JT01", # primary jobs
year = 2020,
agg_geo = "tract") %>%
mutate(GEOID = as.character(h_tract)) %>%
rename(num_jobs_total_rac = C000, # total number of jobs
num_jobs_low_wage_rac = CE01, # Number of jobs with earnings $1250/month or less
num_jobs_med_wage_rac = CE02, # Number of jobs with earnings $1251/month to $3333/month
num_jobs_high_wage_rac = CE03, # Number of jobs with earnings greater than $3333/month
num_jobs_white_rac = CR01, # Number of jobs for workers with Race: White, Alone
num_jobs_black_rac = CR02, # Number of jobs for workers with Race: Black or African American Alone
num_jobs_aian_rac = CR03, # Number of jobs for workers with Race: American Indian or Alaska Native Alone
num_jobs_asian_rac = CR04, # Number of jobs for workers with Race: Asian Alone
num_jobs_nhpi_rac = CR05, # Number of jobs for workers with Race: Native Hawaiian or Other Pacific Islander Alone
num_jobs_two_more_race_rac = CR07, # Number of jobs for workers with Race: Two or More Race Groups
num_jobs_hispanic_rac = CT02) %>% # Number of jobs for workers with Ethnicity: Hispanic or Latino
select(num_jobs_total_rac,
num_jobs_low_wage_rac ,
num_jobs_med_wage_rac ,
num_jobs_high_wage_rac ,
num_jobs_white_rac,
num_jobs_black_rac,
num_jobs_aian_rac,
num_jobs_asian_rac,
num_jobs_nhpi_rac,
num_jobs_two_more_race_rac,
num_jobs_hispanic_rac,
GEOID, year, state)
# Exclude federal jobs
# Reporting changed in 2015 so we would see an artificial decline in reported jobs
# call the LODES api for each year - Job type: all federal jobs
<- grab_lodes(state = states, lodes_type = "rac",
rac_fed segment = "S000", # all jobs
job_type = "JT05", # primary federal jobs
year = 2020,
agg_geo = "tract") %>%
mutate(GEOID = as.character(h_tract)) %>%
rename(num_jobs_total_fed_rac = C000,
num_jobs_low_wage_fed_rac = CE01, # Number of jobs with earnings $1250/month or less
num_jobs_med_wage_fed_rac = CE02, # Number of jobs with earnings $1251/month to $3333/month
num_jobs_high_wage_fed_rac = CE03, # Number of jobs with earnings greater than $3333/month
num_jobs_white_fed_rac = CR01, # Number of jobs for workers with Race: White, Alone
num_jobs_black_fed_rac = CR02, # Number of jobs for workers with Race: Black or African American Alone
num_jobs_aian_fed_rac = CR03, # Number of jobs for workers with Race: American Indian or Alaska Native Alone
num_jobs_asian_fed_rac = CR04, # Number of jobs for workers with Race: Asian Alone
num_jobs_nhpi_fed_rac = CR05, # Number of jobs for workers with Race: Native Hawaiian or Other Pacific Islander Alone
num_jobs_two_more_race_fed_rac = CR07, # Number of jobs for workers with Race: Two or More Race Groups
num_jobs_hispanic_fed_rac = CT02) %>% # Number of jobs for workers with Ethnicity: Hispanic or Latino
select(num_jobs_total_fed_rac,
num_jobs_low_wage_fed_rac,
num_jobs_med_wage_fed_rac,
num_jobs_high_wage_fed_rac,
num_jobs_white_fed_rac,
num_jobs_black_fed_rac,
num_jobs_aian_fed_rac,
num_jobs_asian_fed_rac,
num_jobs_nhpi_fed_rac,
num_jobs_two_more_race_fed_rac,
num_jobs_hispanic_fed_rac,
GEOID, year, state)
# subtract federal jobs from overall counts - this is particularly important if you are looking to get past years of data, or data over time
<- rac %>%
rac left_join(rac_fed, by = c("GEOID", "year", "state")) %>%
mutate(across(matches("fed"), ~if_else(is.na(.x), 0, .x)),
num_jobs_total_rac = num_jobs_total_rac - num_jobs_total_fed_rac,
num_jobs_low_wage_rac = num_jobs_low_wage_rac - num_jobs_low_wage_fed_rac,
num_jobs_med_wage_rac = num_jobs_med_wage_rac - num_jobs_med_wage_fed_rac,
num_jobs_high_wage_rac = num_jobs_high_wage_rac - num_jobs_high_wage_fed_rac ,
num_jobs_white_rac = num_jobs_white_rac - num_jobs_white_fed_rac,
num_jobs_black_rac = num_jobs_black_rac - num_jobs_black_fed_rac,
num_jobs_aian_rac = num_jobs_aian_rac - num_jobs_aian_fed_rac,
num_jobs_asian_rac = num_jobs_asian_rac - num_jobs_asian_fed_rac,
num_jobs_nhpi_rac = num_jobs_nhpi_rac - num_jobs_nhpi_fed_rac,
num_jobs_two_more_race_rac = num_jobs_two_more_race_rac - num_jobs_two_more_race_fed_rac,
num_jobs_hispanic_rac = num_jobs_hispanic_rac - num_jobs_hispanic_fed_rac) %>%
select(num_jobs_total_rac,
num_jobs_low_wage_rac ,
num_jobs_med_wage_rac ,
num_jobs_high_wage_rac ,
num_jobs_white_rac,
num_jobs_black_rac,
num_jobs_aian_rac,
num_jobs_asian_rac,
num_jobs_nhpi_rac,
num_jobs_two_more_race_rac,
num_jobs_hispanic_rac, GEOID, year, state)
LODES Data
Please use all code samples responsibly - these are samples and likely require adjustments to work correctly for your specific needs. Read through the documentation and comments to understand any caveats or limitations of the code and/or data and follow-up with the code author or Code Library admins (code_library@urban.org) if you have questions on how to adapt the sample to your specific use case.
Purpose: LEHD Origin-Destination Employment Statistics (LODES) are measures for total jobs (where people work and where people live). This code pulls 2020 LODES data straight from the LODES server and at the tract level, and subtracts out federal jobs.
Data: The LODES data are derived from the Longitudinal Employer-Household Dynamics (LEHD) microdata. LEHD data link employee and employer data by combining administrative state unemployment insurance wage records with the American Community Survey and other administrative data.There are two core datasets:
Residence Area Characteristic (RAC): the number of jobs by census tract where the employee lives
Workplace Area Characteristic (WAC): the total number of jobs by the census tract where the employee works
Limitations: WAC and RAC data are missing in select states in certain years. See the technical documentation for more details. Additionally, reporting on federal jobs changed in 2015 so we would see an artificial decline in reported jobs in past years. Therefore, we subtract out federal jobs from the overall number of jobs in this code.
Author: Amy Rogin (January 2024)
When pulling data from the API, all past years are updated to the most recent census geography vintage. So if you pull 2015 LODES data in 2023, it will be in 2020 census geographies