| add_gerda_census | R Documentation |
Convenience function to merge Zensus 2022 municipality-level data with GERDA election data. The census provides a cross-sectional snapshot (2022), so the same values are attached to all election years.
The function works with both municipality-level and county-level election data:
Municipality-level data: Direct merge using 8-digit AGS codes
County-level data: Census data is aggregated to the county level (population-weighted means for shares, sums for counts) before merging
add_gerda_census(election_data, unmatched = "warn")
election_data |
A data frame containing GERDA election data. Must contain
either an |
unmatched |
How to handle input rows whose geographic identifier does
not match Census 2022. One of |
The input data must contain one of:
ags: 8-digit municipal code for municipality-level data
county_code: 5-digit county code for county-level data
Since the census is a 2022 cross-section, census values are the same for all election years. The merge is on geography only (no year join).
For county-level data, municipality-level census data is first aggregated:
Share variables: Population-weighted means
Count variables (population_census22, total_dwellings_census22): Sums
Other variables (avg_household_size_census22, avg_rent_per_m2_census22): Population-weighted means
Geographic identifiers must be character vectors containing exactly eight
digits (ags) or five digits (county_code). Numeric identifiers are
rejected because leading zeros may already have been lost. Before joining,
the function verifies reference-key uniqueness and rejects output-column
conflicts. It then verifies that the input row count is unchanged and
reports the exact number of unmatched rows and geographic units. Missing
join keys are classified as unexpected. Use unmatched = "error" in
unattended pipelines.
The input data frame with additional census columns appended. The
number of rows remains unchanged. A machine-readable join report is
attached and can be retrieved with gerda_join_diagnostics().
gerda_census for direct access to the census data
gerda_census_codebook for variable descriptions
gerda_join_diagnostics for inspecting match results
## Not run:
library(gerda)
# Municipality-level merge
muni_data <- load_gerda_web("federal_muni_harm_21") |>
add_gerda_census()
# County-level merge (aggregated from municipalities)
county_data <- load_gerda_web("federal_cty_harm") |>
add_gerda_census()
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.