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
### Takes as input a Google Docs spreadsheet | |
### Outputs national and regional level estimates of support | |
### over time | |
### Load libraries | |
library(R2WinBUGS) | |
library(rjags) | |
library(RCurl) | |
library(reshape) | |
library(foreach) |
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
variable | Question | |
---|---|---|
cowcode | Correlates of War country code (www.correlatesofwar.org). | |
country | Country name. | |
systyear | Year in which the constitutional system was promulgated. | |
systid | Unique identification number for the constitutional system. | |
evntyear | Year of promulgation of the most recent constitutional event. | |
endyear | Year through which the data for the event is guaranteed valid. | |
evntid | Unique identification number for the constitutional event. | |
evnttype | Event type (e.g. amendment, new, etc.). | |
source | What is the source for the text of the Constitution? |
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
crayola <- structure(c("#EFDECD", "#CD9575", "#FDD9B5", "#78DBE2", "#87A96B", | |
"#FFA474", "#FAE7B5", "#9F8170", "#FD7C6E", "#000000", "#ACE5EE", | |
"#1F75FE", "#A2A2D0", "#6699CC", "#0D98BA", "#7366BD", "#DE5D83", | |
"#CB4154", "#B4674D", "#FF7F49", "#EA7E5D", "#B0B7C6", "#FFFF99", | |
"#1CD3A2", "#FFAACC", "#DD4492", "#1DACD6", "#BC5D58", "#DD9475", | |
"#9ACEEB", "#FFBCD9", "#FDDB6D", "#2B6CC4", "#EFCDB8", "#6E5160", | |
"#CEFF1D", "#71BC78", "#6DAE81", "#C364C5", "#CC6666", "#E7C697", | |
"#FCD975", "#A8E4A0", "#95918C", "#1CAC78", "#1164B4", "#F0E891", | |
"#FF1DCE", "#B2EC5D", "#5D76CB", "#CA3767", "#3BB08F", "#FEFE22", | |
"#FCB4D5", "#FFF44F", "#FFBD88", "#F664AF", "#AAF0D1", "#CD4A4C", |
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
myboot<-function(data, stat, nreps, hist = TRUE) { | |
estimates<-get(stat)(data) | |
len<-length(estimates) | |
container<-matrix(NA, ncol = len , nrow = nreps) | |
nobs<-nrow(data) | |
for(i in 1:nreps) { | |
posdraws<-ceiling(runif(nobs)*nobs) | |
resample<-data[posdraws,] | |
container[i,]<-get(stat)(resample) | |
} |
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(foreign) ## for data import | |
library(dplyr) ## for chaining ops together | |
library(ggplot2) ## for plotting | |
library(reshape2) ## for reshaping | |
library(hrbrthemes) ## for pretty pictures | |
library(survey) ## for... uh, survey data | |
party.colours <- c("#0087DC","#D50000","#FDBB30","#FFFF00","#008142","#99CC33","#70147A","#DDDDDD") | |
bes <- read.spss("~/Dropbox/2017-forecasting/data/individual/BES2015_W10_Panel_v0.3.sav") |
I hereby claim:
- I am briatte on github.
- I am briatte (https://keybase.io/briatte) on keybase.
- I have a public key whose fingerprint is CF1D 937F 13FD 11F4 9060 57C7 EC0B 0E46 6A4C 4EDE
To claim this, I am signing this object:
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
term<-c("egypt","jordan","israel","saudi") | |
term_vec<-foreach(i=1:length(all_score_frames),.combine=rbind) %do% | |
{ | |
score_row<-rep(0,length(term)) | |
for(z in 1:length(score_row)) | |
{ | |
sel_score<-all_score_frames[[i]][all_score_frames[[i]]$term==term[z],"score"] | |
sel_score[is.na(sel_score)]<-0 | |
if(length(sel_score)==0) | |
sel_score<-0 |
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
require(tidyverse) | |
require(lubridate) | |
#Data from www.parlgov.org | |
dat <- read.csv("view_election.csv") | |
dat <- dat %>% | |
filter(election_type != "ep") %>% | |
mutate(election_date = as.Date(election_date)) %>% | |
filter(election_date > as.Date("1945-01-01")) %>% | |
distinct(country_name, election_date) %>% | |
group_by(country_name) %>% |