########################################################################################## ###Data preparation script for the extraction of government positions from the Manifesto data ### 0. Libraires require(foreign) ### 1. The original datasets ## 1.1 Get tue Manifesto Project data from https://manifesto-project.wzb.eu/ ## and load it. The version of the file used in the script is 2009/10/11 manifestos <- read.csv("./original data/MPDataset_full.csv", as.is=TRUE) ## 1.2 Get the government and party composition files from ParlGov https://manifesto-project.wzb.eu/ ## and load then. The versions of the files used in the script are 26 July 2011 parties <- read.csv("./original data/view_party.csv", as.is=TRUE) cabinets.temp <- read.csv("./original data/view_cabinet.csv", as.is=TRUE) ### 2. Data manipulation ## 2.1 Merge the manifesto and party files manipart<-merge(parties, manifestos, by.x="cmp", by.y="party") ## 2.2 Run the correction dates ## Some of the election dates in the Manifesto and ParGov files differ. The source files alignes the dates. ## It is possible that in future versions of the files, the corrections would not be needed. source('corrections dates cabinets.r') ## 2.3 Create id variables based on parties and elections cabinets.temp$new_id<-paste(cabinets.temp$party_id, cabinets.temp$election_date) manipart$edate2<-as.Date(manipart$edate, "%m/%d/%Y") manipart$new_id<-paste(manipart$party_id, manipart$edate2) ## 2.4 Merge the cabinet, party and manifesto data cabinets<-merge(cabinets.temp, manipart, by.x="new_id", by.y="new_id") ## 2.5 Create a new variable for ease cabinets$seats_share <- (cabinets$seats / cabinets$election_seats_total) * 100 ## 2.5 Save the table write.table (cabinets, 'cabinets.txt') ## You can load the data by the following (might need to specify the location of the file) cabinets<-read.table ('cabinets.txt', as.is=TRUE)