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(plyr) | |
library(zoo) | |
startyr <- 1992 | |
endyr <- 2012 | |
pg <- read.csv("http://www.parlgov.org/stable/static/data/stable-utf-8/view_cabinet.csv",as.is=T) | |
## Exclude GDR | |
pg <- pg[which(pg$country_name_short!="GDR"),] |
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
#!/usr/bin/perl -w | |
use strict; | |
use Switch; | |
binmode STDOUT, ":utf8"; | |
use WWW::Mechanize; | |
use HTML::TokeParser; | |
use Data::Dumper; | |
my $start = 'http://www.sondaggipoliticoelettorali.it/'; |
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
## Load libraries | |
library(sp) | |
library(RColorBrewer) | |
library(car) | |
library(stringdist) | |
## Read in the shapefile | |
shape <- readOGR("../shapefiles/",layer="Comuni_11") | |
shape$NOME <- iconv(shape$NOME, "latin1", "UTF8") | |
shape$NOME.lc <- tolower(shape$NOME) |
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
dat <- read.csv("votazioni.csv",header=T) | |
## Exclude schede bianche, schede null | |
dat <- subset(dat,!is.element(Candidato,c("Schede bianche","Schede nulle","Voti dispersi"))) | |
## Iterate over years | |
for (my.year in unique(dat$Year)) { | |
my.subset <- subset(dat,Year == my.year) | |
## top eight candidates | |
max.per.candidate <- tapply(my.subset$Voti,my.subset$Candidato,max) | |
max.per.candidate <- sort(max.per.candidate,decreasing=TRUE)[1:8] |
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
## 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) | |
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) | |
library(survival) | |
dat <- read.dta("delay.dta") | |
dat$bargainingdays [which(dat$bargainingdays == 0)] <- .01 | |
dat$post_legislative_parties <- dat$postelection * dat$legislative_parties | |
dat$post_polariz <- dat$postelection * dat$polarization | |
dat$post_positive <- dat$postelection * dat$positive_parl |
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
## ############################ | |
## LOAD THE NECESSARY LIBRARIES | |
## ############################ | |
library(foreign) | |
library(survival) | |
## ###################### | |
## READ DATA AND DO DATES | |
## ###################### |
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
### Load libraries | |
library(foreign) | |
library(basicspace) | |
library(ggplot2) | |
library(car) | |
### Demo | |
data(LC1980) | |
result <- aldmck(data=LC1980, |
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
import re | |
import codecs | |
import urllib.request | |
from bs4 import BeautifulSoup | |
from bs4 import SoupStrainer | |
start = 'http://www.atpworldtour.com/Rankings/Singles.aspx' | |
outfile = codecs.open('atp_ranks3.csv', 'w','utf-8') | |