Skip to content

Instantly share code, notes, and snippets.

View ulfelder's full-sized avatar

Jay Ulfelder ulfelder

View GitHub Profile
# metadata
data_source <- "https://docs.google.com/spreadsheets/d/1xa0iLqYKz8x9Yc_rfhtmSOJQ2EGgeUVjvV4A8LsIaxY/htmlview?sle=true#gid=0"
data_collectors <- "Jeremy Pressman (@djpressman, U of Connecticut) and\nErica Chenoweth (@EricaChenoweth, U of Denver)"
code_gist <- "https://gist.github.com/benmarwick/a1ac9c7235ebef542824512162ff2f44"
# ------------------------------------------------------------------------
# read in data from google sheets to get a data frame
@ulfelder
ulfelder / freedomintheworld.converter
Last active April 20, 2016 14:54
Converts Freedom House's Freedom in the World data into standard country-year structure for time-series cross-sectional analysis.
# This script converts Freedom House's annual Freedom in the World data from
# the ugly, table-like Excel format in which it's posted into a data frame in R.
# It is set up to work on future updates, too, and should automatically adjust
# as years or countries are added.
#
# Before running this script:
#
# 1. Open a browser & go to http://www.freedomhouse.org/report-types/freedom-world
#
# 2. Download the file "Country ratings and status, FIW 1973-2013(EXCEL)"
@ulfelder
ulfelder / gdelt.atrocities.daily.screen
Created May 30, 2013 21:22
R script for a human-assisted process to screen GDELT for atrocities
# Clear the workspace
rm(list=ls(all=TRUE))
# Set working directory to location of extracted daily update and .txt file with column headers
# setwd("PUT YOUR DIRECTORY NAME HERE")
# Load function to return subset involving violence against civilians
extractor <- function(date) {
filename <- paste(date,"export.csv", sep=".")
dailies <- read.delim(filename, header=FALSE)
@ulfelder
ulfelder / gdelt.atrocities.explore
Last active May 31, 2016 11:59
R code for selecting events from GDELT files that look like they might be atrocities (i.e., lethal violence against civilians), summing them by location, and mapping them.
# Housekeeping: clear workspace and load packages
rm(list=ls(all=TRUE))
library(lubridate)
library(RgoogleMaps)
library(ggmap)
library(mapproj)
library(ggplot2)
library(plyr)
# Load 2011 GDELT data from http://eventdata.psu.edu/data.dir/GDELT.html