Skip to content

Instantly share code, notes, and snippets.

@chrishanretty
Last active August 29, 2015 14:17
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/563ebb7dc80b308884af to your computer and use it in GitHub Desktop.
Save chrishanretty/563ebb7dc80b308884af to your computer and use it in GitHub Desktop.
Did the 2010 debates increase political engagement?
## ----libraries, echo = FALSE, message = FALSE, warning = FALSE-----------
library(foreign)
library(cem)
library(MatchIt)
## ----datain, echo = FALSE, message = FALSE, warning = FALSE--------------
## Requires you to download the file from http://bes2009-10.org/bes-data.php
dat <- read.spss("CIPSDEC2311.SAV",to.data.frame = T)
## ----munge, echo = FALSE, message = FALSE, warning = FALSE---------------
### Dependent variable: change in turnout intention
### Pre-campaign
dat$oldTurnout <- as.numeric(dat$AAQ33)
### Campaign
dat$newTurnout <- as.numeric(dat$BBQ33)
### Change: campaign - precampaign
dat$chgTurnout <- dat$newTurnout - dat$oldTurnout
### Independent variable: debate exposure
dat$debate1 <- as.numeric(dat$BBQTV1 == "Yes ")
dat$debate2 <- as.numeric(dat$BBQTV2 == "Yes ")
dat$debate3 <- as.numeric(dat$BBQTV3 == "Yes ")
### How many debates could they have seen?
dat$responseDate <- as.Date(substr(dat$BBCRESP,0,10),
format = "%d/%m/%Y")
### bbqtv1 'see or hear leaders debate april 15th'
### bbqtv2 'see or hear leaders debate april 22nd'
### bbqtv3 'see or hear leaders debate april 29th'
dat$possibleDebates <- as.numeric(dat$responseDate > as.Date("2010-04-15")) +
as.numeric(dat$responseDate > as.Date("2010-04-22")) +
as.numeric(dat$responseDate > as.Date("2010-04-29"))
### Restrict to those who could have seen one debate
dat <- subset(dat, possibleDebates > 0)
dat$anyDebates <- apply(dat[,c("debate1","debate2","debate3")],1,max,na.rm = T)
dat$anyDebates[!is.finite(dat$anyDebates)] <- NA
## ----modelling, echo = FALSE, message = FALSE, warning = FALSE, error = FALSE, results = "hide"----
### (1) Pre-election interest (AAQ2)
dat$AAQ2 <- relevel(dat$AAQ2, "Somewhat interested")
### (2) Attention to politics (aaq131)
dat$attention <- as.numeric(dat$AAQ131)
### (3) Political parties contacted (bbq66)
dat$contact <- as.numeric(dat$BBQ66 == "Yes")
### (4) marginalty (MARGIN05)
dat$MARGIN05 <- relevel(dat$MARGIN05,
"Fairly Safe: maj 2005 10.0-14.99")
### (5) Media consumption (daily newspaper)
dat$media <- dat$AAQ145
linmod <- lm(chgTurnout ~ anyDebates + AAQ2 + attention + contact + MARGIN05 + media, data = dat, weights =W8_1)
tmp <- dat[,c("chgTurnout","anyDebates","AAQ2","attention","contact","MARGIN05","media")]
mycp <- list(attention = 2:10)
mat <- cem(treatment="anyDebates", data=tmp, drop="chgTurnout",cutpoints = mycp)
out <- att(mat, chgTurnout ~ anyDebates, data=tmp)
## Should give
##
## G0 G1
## All 3789 7217
## Matched 3488 6928
## Unmatched 301 289
##
## Linear regression model on CEM matched data:
##
## SATT point estimate: 0.177548 (p.value=0.039119)
## 95% conf. interval: [0.008885, 0.346211]
## ----comparisonmod, echo = FALSE, message = FALSE, warning = FALSE-------
dat$AAQ145 <- relevel(dat$AAQ145, "Sometimes")
comparison.mod <- lm(newTurnout ~ AAQ145, data = dat)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment