if (FALSE) {
library(gerda)
library(dplyr)
# Example 1: County-level election data
county_data <- load_gerda_web("federal_cty_harm") %>%
add_gerda_covariates()
# Check the result
names(county_data) # See new covariate columns
table(county_data$election_year) # Only election years
# Example 2: Municipal-level election data
# Note: All municipalities in the same county will get identical covariates
muni_data <- load_gerda_web("federal_muni_harm_21") %>%
add_gerda_covariates()
# Verify: municipalities in same county have same covariate values
muni_data %>%
group_by(county_code_21, election_year) %>%
summarize(
n_munis = n(),
unemp_range = max(unemployment_rate) - min(unemployment_rate)
)
# Analyze with covariates
county_data %>%
filter(election_year == 2021) %>%
filter(!is.na(unemployment_rate)) %>%
summarize(cor_unemployment_afd = cor(unemployment_rate, afd))
}
Run the code above in your browser using DataLab