Created
April 20, 2021 15:39
-
-
Save chrishanretty/f777311cc5f17cd371804dcff75b9929 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(countrycode) | |
library(tidyverse) | |
library(rio) | |
holder <- list() | |
### (0) PartyFacts lookup | |
pf <- read.csv("data/partyfacts-external-parties.csv") | |
### (1) Manifesto Project | |
### Accessed through a library | |
library(manifestoR) | |
marpor_apikey_locn <- "~/Dropbox/tmp/manifesto_apikey.txt" | |
mp_setapikey(key.file = marpor_apikey_locn) | |
marpor <- mp_maindataset() | |
### There is a very odd error for Norway, 1989, which arises because | |
### we do not know the length of the manifestos. We'll insert the | |
### shortest manifesto we know of from Norway. | |
marpor$total[which(is.na(marpor$total) & marpor$countryname == "Norway" & | |
marpor$edate == "1989-09-11")] <- | |
min(marpor$total[which(marpor$countryname == "Norway")], na.rm = T) | |
marpor$left_right <- mp_scale(marpor, scalingfun = logit_rile) | |
marpor <- merge(marpor, | |
pf %>% | |
filter(dataset_key == "manifesto") %>% | |
dplyr::select(dataset_key, dataset_party_id, partyfacts_id), | |
by.x = "party", | |
by.y = "dataset_party_id", | |
all.x = TRUE, | |
all.y = FALSE) | |
marpor$iso3c <- countrycode(marpor$countryname, | |
"country.name", | |
"iso3c") | |
marpor$year <- as.numeric(format(marpor$edate, format = "%Y")) | |
holder[["manifesto"]] <- marpor %>% | |
dplyr::select(left_right = rile, | |
partyfacts_id, | |
iso3c, year) %>% | |
mutate(source = "manifesto") | |
### (2) CHES | |
ches <- read.csv("data/1999-2019_CHES_dataset_means.csv") %>% | |
mutate(left_right = as.numeric(as.character(lrecon)), | |
iso3c = NA) | |
ches <- merge(ches, | |
pf %>% | |
filter(dataset_key == "ches") %>% | |
dplyr::select(dataset_key, dataset_party_id, partyfacts_id), | |
by.x = "party_id", | |
by.y = "dataset_party_id", | |
all.x = TRUE, | |
all.y = FALSE) | |
holder[["ches"]] <- ches %>% | |
dplyr::select(left_right, | |
partyfacts_id, | |
iso3c, year) %>% | |
mutate(source = "ches") | |
### (3) V-Party | |
vparty_file <- "data/V-Dem-CPD-Party-V1.rds" | |
vparty <- readRDS(vparty_file) %>% | |
dplyr::select(partyfacts_id = pf_party_id, | |
year, | |
left_right = v2pariglef) %>% | |
mutate(source = "vparty") | |
holder[["vparty"]] <- vparty | |
### (4) DBPI | |
## dpi <- rio::import("data/DPI2015.dta") %>% | |
## mutate(iso3c = countrycode(countryname, | |
## "country.name", | |
## "iso3c")) | |
### (5) Huber-Inglehart | |
### (6) Kitschelt (2013) | |
kitschelt <- rio::import("data/partylevel_20130907.dta") %>% | |
dplyr::select(iso3c = ccodewb, partynum, left_right = dw) %>% | |
mutate(dataset_party_id = paste(iso3c, partynum, sep = "-"), | |
year = 2010) | |
kitschelt <- merge(kitschelt, | |
pf %>% | |
filter(dataset_key == "kitschelt") %>% | |
dplyr::select(dataset_key, dataset_party_id, partyfacts_id), | |
by = "dataset_party_id", | |
all.x = TRUE, | |
all.y = FALSE) | |
holder[["kitschelt"]] <- kitschelt %>% | |
dplyr::select(left_right, | |
partyfacts_id, | |
iso3c, year) %>% | |
mutate(source = "kitschelt") | |
### (7) PPMD | |
### ppmd <- rio::import("data/ppmd_summary_data.por") | |
### (8) Comparative Candidates? | |
### (9) Coppedge | |
### | |
### (10) Global Party Survey | |
gps <- read.csv("data/Global Party Survey by Party SPSS V2_1_Apr_2020-2.csv") %>% | |
dplyr::select(ID_GPS, | |
iso3c = ISO, | |
left_right = V4_Scale, | |
year = Elec_year) | |
gps <- merge(gps, | |
pf %>% | |
filter(dataset_key == "gps") %>% | |
dplyr::select(dataset_key, dataset_party_id, partyfacts_id), | |
by.x = "ID_GPS", | |
by.y = "dataset_party_id", | |
all.x = TRUE, | |
all.y = FALSE) | |
holder[["gps"]] <- gps %>% | |
dplyr::select(-ID_GPS) %>% | |
mutate(source = "gps") | |
### (11) Janda | |
### (12) KUREP | |
## kurep <- rio::import("data/ceeandwe2007elitesurveyspublic06-24-2013.dta") %>% | |
## mutate(countryname = characterize(country)) | |
### (13) Laver/Hunt | |
### (14) Morgan (1976) | |
### (15) POPPA | |
### (16) PPLA | |
### (17) Ray | |
### (18) Thomas | |
dat <- bind_rows(holder) %>% | |
pivot_wider(id_cols = c(year, partyfacts_id), | |
values_from = left_right, | |
names_from = source, | |
values_fn = mean) | |
panel.cor <- function(x, y, digits = 2, prefix = "", cex.cor, ...) | |
{ | |
usr <- par("usr"); on.exit(par(usr)) | |
par(usr = c(0, 1, 0, 1)) | |
r <- abs(cor(x, y, use = "pairwise")) | |
txt <- format(c(r, 0.123456789), digits = digits)[1] | |
txt <- paste0(prefix, txt) | |
if(missing(cex.cor)) cex.cor <- 0.8/strwidth(txt) | |
text(0.5, 0.5, txt, cex = cex.cor * r) | |
} | |
png(file = "cross_data_cors.png") | |
pairs(dat[,c("manifesto", "ches", "vparty", "kitschelt", "gps")], | |
labels = c("Manifesto Project\n(logit scaling)", "CHES", "V-Party", | |
"Kitschelt (2013)", "Global Party Survey"), | |
lower.panel = panel.smooth, upper.panel = panel.cor) | |
dev.off() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment