Skip to content

Instantly share code, notes, and snippets.

@xmarquez
xmarquez / index.html
Created June 24, 2013 07:30
Gini Coefficients in LIS
<!doctype HTML>
<meta charset = 'utf-8'>
<html>
<head>
<script src='http://code.jquery.com/jquery-1.9.1.min.js' type='text/javascript'></script>
<script src='http://code.highcharts.com/highcharts.js' type='text/javascript'></script>
<script src='http://code.highcharts.com/highcharts-more.js' type='text/javascript'></script>
<style>
@xmarquez
xmarquez / index.html
Created June 24, 2013 07:29
Gini Coefficients in LIS
<!doctype HTML>
<meta charset = 'utf-8'>
<html>
<head>
<script src='http://code.jquery.com/jquery-1.9.1.min.js' type='text/javascript'></script>
<script src='http://code.highcharts.com/highcharts.js' type='text/javascript'></script>
<script src='http://code.highcharts.com/highcharts-more.js' type='text/javascript'></script>
<style>
@xmarquez
xmarquez / List-of-variables-ccp.csv
Last active December 12, 2015 09:39
Code for post on the Normativeness of Democracy
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?
@xmarquez
xmarquez / good bad and ugly.R
Created December 14, 2012 21:41
Code for post on the Good, the Bad, and the Ugly among regimes
CIRI <- read.csv("../Data/CIRI Human Rights Data.csv")
codes <- read.csv("../Data/extended codes.csv")
names(CIRI)[2] <- "year"
CIRI$ccode <- CIRI$COW
CIRI <- merge(CIRI,codes,by=c("year","ccode"))
names(polity)[2] <- "politycode"
@xmarquez
xmarquez / Malevolent democracies and benevolent autocracies
Created December 12, 2012 03:40
Code for post on physical integrity rights and democracy
library(ggplot2)
library(plyr)
library(maps)
CIRI <- read.csv("../Data/CIRI Human Rights Data.csv")
codes <- read.csv("../Data/extended codes.csv")
polity <- read.csv("../Data/p4v2011.csv")
#uds <- read.csv("../Data/uds_summary.csv")
#utip <- read.csv("../Data/EHII2008.csv")
pwt <- read.csv("../Data/pwt70_w_country_names.csv")
@xmarquez
xmarquez / vote shares.R
Created August 24, 2012 05:10
Quick and dirty simulation of votes in 2008 congressional election under inverse income voting system
# We use a lognormal income distribution to simulate the income distribution in the USA in 2008.
# The parameters are chosen so that the median income comes out to about $30,000,
# the gini index comes out to about 0.35, and the 90/10 ratio comes in at about 6:1,
# as in the Luxembourg Income Study figures for 2010.
# See the key figures here: http://www.lisdatacenter.org/data-access/key-figures/inequality-and-poverty/
incomes <- rlnorm(300000,meanlog=log(30000),0.55)
require(reldist) # to calculate the gini index
gini(incomes)
@xmarquez
xmarquez / regimes and gdp.r
Created May 17, 2012 09:30
Code for post on the economic performance of democracies and dictatorships through history
uds <- read.csv("../Data/uds_summary.csv")
pwt <- read.csv("../Data/pwt70_w_country_names.csv")
codes <- read.csv("../Data/codes.csv")
require(countrycode)
require(plyr)
require(ggplot2)
codes$isocode <- countrycode(codes$cowcode,"cown","iso3c")
names(pwt)[1] <- "countryname.pwt"
pwt <- ddply(pwt,.(isocode), transform, cgdpgrowthch = 100*diff(rgdpch)/rgdpch)