Skip to content

Instantly share code, notes, and snippets.

@chrishanretty
Created September 15, 2014 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrishanretty/8c00e1a6dd2c848b093c to your computer and use it in GitHub Desktop.
Save chrishanretty/8c00e1a6dd2c848b093c to your computer and use it in GitHub Desktop.
Are Scots more left-wing?
library(foreign)
library(car)
library(broom)
library(reshape)
library(ggplot2)
dat <- read.spss("BES2015_W2_Panel_v2.0.sav",to.data.frame = TRUE)
### First, left-right values
### Here, positive values -> more left wing
for(i in 1:5){
the.var <- paste0("lr", i,"W1")
the.newvar <- paste0("lr", i, "score")
dat[,the.newvar] <- car::recode(dat[,the.var],
"'Strongly disagree'=1;
'Disagree'=2;
'Neither agree nor disagree'=3;
'Agree'=4;
'Strongly agree'=5;else=NA")
dat[,the.newvar] <- as.numeric(dat[,the.newvar])
}
# check correlations
cor(dat[,c("lr1score", "lr2score", "lr3score", "lr4score", "lr5score")], use = "pairwise.complete.obs")
dat$lrindex <- rowMeans(dat[,c("lr1score", "lr2score", "lr3score", "lr4score", "lr5score")], na.rm = TRUE)
dat$country <- car:::recode(dat$gor,
"'Scotland'='Scotland';'Wales'='Wales';else='England'")
summary(lrmod <- lm(lrindex ~ 0 + country, dat))
### Now, authoritarian-libertarian values
### Here, positive values -> more authoritarian
for(i in 1:5){
the.var <- paste0("al", i,"W1")
the.newvar <- paste0("al", i, "score")
dat[,the.newvar] <- car::recode(dat[,the.var],
"'Strongly disagree'=1;
'Disagree'=2;
'Neither agree nor disagree'=3;
'Agree'=4;
'Strongly agree'=5;else=NA")
dat[,the.newvar] <- as.numeric(dat[,the.newvar])
}
# check correlations
cor(dat[,c("al1score", "al2score", "al3score", "al4score", "al5score")], use = "pairwise.complete.obs")
dat$alindex <- rowMeans(dat[,c("al1score", "al2score", "al3score", "al4score", "al5score")], na.rm = TRUE)
dat$country <- car:::recode(dat$gor,
"'Scotland'='Scotland';'Wales'='Wales';else='England'")
summary(almod <- lm(alindex ~ 0 + country, dat))
### Now for welfarism
### Here, negative values -> greater support for welfare
welfare.qs <- c("reasonForUnemploymentW1",
"immigrantsWelfareStateW1",
"govtHandoutsW1",
"polForTheRichW1",
"businessBonusW1")
for (q in welfare.qs) {
the.var <- q
the.newvar <- paste0("wf", which(welfare.qs==q),"score")
dat[,the.newvar] <- car::recode(dat[,the.var],
"'Strongly disagree'=1;
'Disagree'=2;
'Neither agree nor disagree'=3;
'Agree'=4;
'Strongly agree'=5;else=NA")
dat[,the.newvar] <- as.numeric(dat[,the.newvar])
}
### Some of these need to be reversed, since agreeing is the pro-welfare response
dat$wf1score <- 6 + dat$wf1score * - 1
dat$wf4score <- 6 + dat$wf4score * - 1
cor(dat[,c("wf1score", "wf2score", "wf3score", "wf4score", "wf5score")], use = "pairwise.complete.obs")
dat$wfindex <- rowMeans(dat[,c("wf1score", "wf2score", "wf3score", "wf4score", "wf5score")], na.rm = TRUE)
summary(wfmod <- lm(wfindex ~0 + country, dat))
lrmod.df <- tidy(lrmod)
wfmod.df <- tidy(wfmod)
almod.df <- tidy(almod)
lrmod.df$outcome <- "Leftism"
wfmod.df$outcome <- "Concern over welfare scams"
almod.df$outcome <- "Authoritarianism"
plot.df <- merge_recurse(list(lrmod.df,wfmod.df,almod.df))
plot.df$estimate.hi <- plot.df$estimate + plot.df$stderror * 1.96
plot.df$estimate.lo <- plot.df$estimate - plot.df$stderror * 1.96
plot.df$Country <- gsub("country","",plot.df$term)
speccie.replication <- ggplot(plot.df, aes(x = outcome, y= estimate, ymin = estimate.lo, ymax = estimate.hi, fill = Country)) +
geom_bar(stat="identity",position="dodge") +
geom_errorbar(position="dodge") +
scale_fill_manual(values = c("red","blue4","springgreen4")) +
scale_x_discrete("Scale") +
scale_y_continuous("Score") +
theme_bw()
pdf(file="speccie_replication.pdf", width = 10, height= 8)
print(speccie.replication)
dev.off()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment