This repository contains R code to create tidy datasets for the German Bundestag election results.
The original data is provided by the Federal Returning Officer (Bundeswahlleiter). The concept of tidy data is explained by Hadley Wickham in his article "Tidy Data" in the Journal of Statistical Software (2014, Vol. 59, Issue 10).
Note that this is currently work in progress: I started with the 1949 Bundestag elections and will slowly work towards more recent elections. This project has been inspired by similar projects from Arndt Leininger and Marie-Louise Timcke who both focused on the 2017 elections.
The folder code
contains the R code to transform the un-tidy raw data into tidy data. The file names refer to the election years: tidy_1949.r
refers to the 1949 Bundestag elections.
The original data as provided on the website of the Federal Returning Officer can be found in the folder data_raw
. The resulting tidy datasets that are created when running the R code are stored in the folder data_tidy
.
The R code creates two different files for each election: ..._districts
includes district-level results, whereas ..._states
shows results for the states (Länder) and for the federal level.
Each row in the tidy dataset shows the election results for one party in one electoral district in one election for one type of vote ("Erststimme", "Zweitstimme"). The tidy datasets have the following variable structure:
district_no
: number of the electoral districtdistrict_name
: name of the electoral districtstate
: name of the state to which the electoral district belongs (for results on state level: abbreviated name of the state)party_short
: abbreviated party nameparty_long
: full party namevote_type
: "Erststimme", "Zweitstimme"year
: year of electionvotes_party_district
: absolute number of votes for the respective party in the electoral districtvoteshare_party_district
: vote share for the respective party in the electoral district, in %voters_district
: total number of voters in the respective electoral district (both valid and invalid votes)validvotes_district
: valid votes for all parties in the respective electoral districtinvalidvotes_district
: invalid votes in the respective electoral districteligible_district
: absolute number of eligible voters in the respective districtturnout_district
: voter turnout in the electoral district, in %
The Federal Returning Officer provides a PDF file with an overview of all Bundestag elections: Ergebnisse früherer Bundestagswahlen.
Moreover, there are separate websites with the results for each election as well the possibility to download the raw data:
- 1949 Bundestag elections: website, raw csv data
- 1953 Bundestag elections: website, raw csv data
- 1957 Bundestag elections: website, raw csv data
- 1961 Bundestag elections: website, raw csv data
- 1965 Bundestag elections: website, raw csv data
- 1969 Bundestag elections: website, raw csv data
- 1972 Bundestag elections: website, raw csv data
- 1976 Bundestag elections: website, raw csv data
- (some elections are still missing here)
- 2005 Bundestag elections: website, raw csv data