Skip to content

Instantly share code, notes, and snippets.

@chrishanretty
Last active December 16, 2015 13:08
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/5439263 to your computer and use it in GitHub Desktop.
Save chrishanretty/5439263 to your computer and use it in GitHub Desktop.
Ages of heads of state and government
## Assumes you have the Samuels/Shugart data from http://laderafrutal.com/academic/samuels-shugart.html
## and the CCP data from http://www.comparativeconstitutionsproject.org/
library(countrycode)
library(foreign)
library(plyr)
library(pwt)
data(pwt7.0)
pwt7.0$cown <- countrycode(pwt7.0$country,"country.name","cown")
pwt7.0 <- aggregate(pwt7.0$pop,list(cown=pwt7.0$cown),mean,na.rm=T)
names(pwt7.0)[2] <- "pop"
## Read in info on ages
ages <- read.csv("ch3_data.csv",header=T)
ages$cown <- countrycode(ages$country,"country.name","cown")
## Fix for Germany
ages$cown[which(ages$cown == 255)] <- 260
## Read in info on constitutions
ccp <- read.dta("ccpcncv1_0.dta")
ccp$hogage <- as.numeric(gsub("\\D.*","",ccp$hogage))
ccp$hosage <- as.numeric(gsub("\\D.*","",ccp$hosage))
ccp$lhage <- as.numeric(gsub("\\D.*","",ccp$lhage))
## Missings
ccp$hosage[ccp$hosage>89] <- 0
ccp$hogage[ccp$hogage>89] <- 0
ccp$lhage[ccp$lhage>89] <- 0
ccp$hosage[ccp$hosage==1] <- 0
ccp$hogage[ccp$hogage==1] <- 0
ccp$lhage[ccp$lhage==1] <- 0
## Get info on HoS age req.s and HoG age req.s
ages <- merge(ages,ccp[,c("cowcode","hosage","hogage","lhage")],
by.x="cown",by.y="cowcode",
all.x=T,all.y=F)
ages$is.pres <- (ages$premiprespres == 1 | ages$presparlpres == 1 | ages$purepres == 1)
ages$relevant.threshold <- ifelse(ages$is.pres, ages$hosage, ages$hogage)
## Assume silence means zero threshold
ages$relevant.threshold[is.na(ages$relevant.threshold)] <- 0
ages$lhage[is.na(ages$lhage)] <- 0
## Set up the model
summary(my.mod.a <- lm(ageassume ~ relevant.threshold + I(relevant.threshold==0) + is.pres,data = ages))
## Create order of politicians within country
## Not quite third-wave versus all else, but still
ages <- ddply(ages,.(cown),transform,Order = order(number))
summary(my.mod.b <- lm(ageassume ~ relevant.threshold + I(relevant.threshold==0) + is.pres + log(Order),data = ages))
ages <- merge(ages,pwt7.0,all.x=T,all.y=F)
summary(my.mod.c <- lm(ageassume ~ relevant.threshold + I(relevant.threshold==0) + is.pres + log(Order) + scale(log(pop)),data = ages))
library(texreg)
htmlreg(list(my.mod.a, my.mod.b, my.mod.c),
inline.css = TRUE,
custom.coef.names= c("Intercept","Minimum age","No minimum age specified","President","Order within country","scaled Population"),
doctype = FALSE, html.tag = FALSE, head.tag = FALSE,body.tag = FALSE,
file="ages.html")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment