R Package
The gerda R package provides tools to download and work with GERDA datasets directly in R. Current version: 0.5.0 (CRAN).
Installation
# Install from CRAN
install.packages("gerda")
# Or install development version from GitHub
devtools::install_github("hhilbig/gerda")
Main Functions
Data Loading
gerda_data_list(print_table = TRUE): Lists all available GERDA datasets with descriptions, including federal, state, municipal, European, mayoral, and county elections.print_table: IfTRUE(default), prints a formatted table and invisibly returns a tibble. IfFALSE, returns the tibble directly.
load_gerda_web(file_name, verbose = FALSE, file_format = "rds"): Loads a GERDA dataset from the web.file_name: Dataset name (seegerda_data_list()for options).verbose: Print loading messages (defaultFALSE).file_format: File format to download,"rds"or"csv"(default"rds").- Includes fuzzy matching for file names and suggests close matches if exact match isn’t found.
Covariates
-
add_gerda_covariates(): Appends county-level socioeconomic indicators (population, unemployment, etc.) to election datasets. Use with piped data. -
gerda_covariates(): Returns raw covariate data as a standalone dataset for manual merging. -
gerda_covariates_codebook(): Returns the codebook with variable descriptions and metadata for all covariates.
Census 2022
-
add_gerda_census(): Merges municipality-level Census 2022 data with GERDA election data. Works with both municipality-level (direct merge on AGS) and county-level data (aggregated with population-weighted means for shares, sums for counts). -
gerda_census(): Returns raw Census 2022 municipality-level data (~10,800 municipalities, 16 variables covering demographics, migration, households, housing, and rents). -
gerda_census_codebook(): Returns the data dictionary for Census 2022 variables.
Party Mapping
party_crosswalk(party_gerda, destination): Maps GERDA party names to corresponding values from the ParlGov database.party_gerda: Character vector of party names.destination: Target column name from ParlGov crosswalk.
Usage Examples
library(gerda)
# List available datasets
gerda_data_list()
# Load harmonized municipal election data
municipal <- load_gerda_web("municipal_harm", verbose = TRUE)
# Load federal county data with socioeconomic covariates
federal_county <- load_gerda_web("federal_cty_harm") |>
add_gerda_covariates()
# Add Census 2022 demographics to municipality-level data
federal_muni <- load_gerda_web("federal_muni_harm_21") |>
add_gerda_census()
# Load new datasets
mayoral <- load_gerda_web("mayoral_harm")
european <- load_gerda_web("european_muni_harm")
county <- load_gerda_web("county_elec_harm_21")
# View covariate and census definitions
gerda_covariates_codebook()
gerda_census_codebook()
# Map party names to ParlGov
party_crosswalk(c("cdu_csu", "spd", "gruene"), "party_name_english")
Documentation
Feedback
Feedback is welcome. Please email hhilbig@ucdavis.edu or open an issue on GitHub.