Skip to content

Instantly share code, notes, and snippets.

View svmiller's full-sized avatar
🤷‍♂️
¯\_(ツ)_/¯

Steven V. Miller svmiller

🤷‍♂️
¯\_(ツ)_/¯
View GitHub Profile
@svmiller
svmiller / 1-convert-cow-states-to-country-year.R
Last active May 23, 2017 23:42
Convert CoW state data to country-year panel data.
library(tidyverse)
States <- read_csv("~/Dropbox/data/COW/states/states2011.csv")
# Create a PDF of state-years. ----------
# States data nominally end in 2011, so let's fudge that.
States %>%
mutate(endyear = ifelse(endyear == 2011, 2015, endyear)) %>%
rowwise() %>%
@svmiller
svmiller / tidy-freedom-of-the-press-data.R
Created May 22, 2017 19:13
Not the most elegant, albeit still fairly "tidy" script to make Freedom House's "Freedom of the Press" data actually usable.
library(tidyverse)
library(stringr)
# Freedom of the Press data ---------
# Oh god, Freedom House, why the sam hell do you do these things...
FP <- readxl::read_excel("~/Dropbox/data/freedom-house/FOTP1980-FOTP2017_Public-Data.xlsx", sheet=2) %>%
repair_names()
# Ugh, all right. Let's do this...
setwd("~/Dropbox/projects/blog-posts/nato-spending")
library(WDI)
library(countrycode)
library(tidyverse)
Milit <- WDI(country="all", indicator=c("MS.MIL.XPND.GD.ZS", "MS.MIL.XPND.ZS","MS.MIL.TOTL.P1", "SP.POP.TOTL"),
start=1988, end=2015) %>%
rename(milex = MS.MIL.XPND.GD.ZS, milgovexp = MS.MIL.XPND.ZS,
milper = MS.MIL.TOTL.P1, tpop = SP.POP.TOTL) %>% tbl_df() %>%
library(RCurl)
library(tidyverse)
library(maps)
# library(fiftystater)
theme_steve <- function() {
theme_bw() +
theme(panel.border = element_blank(),
plot.caption=element_text(hjust=1, size=9,
margin=margin(t=10),
@svmiller
svmiller / terrorism-in-ukg-1970-2015.R
Created June 4, 2017 20:15
Model terrorism patterns in the United Kingdom
# You won't need all of these packages. I just copied it from another,related analysis:
# https://github.com/svmiller/etjc
library(car)
library(arm)
library(countrycode)
library(data.table)
library(tidyverse)
library(sqldf)
# library(pdftools)
@svmiller
svmiller / 1-scrape-noaa.R
Created June 20, 2017 15:24
Get Phoenix airport June highs data
library(rnoaa)
library(tidyverse)
library(stringr)
library(weathermetrics)
my_token <- "get your own here..."
theme_steve <- function() {
theme_bw() +
theme(panel.border = element_blank(),
@svmiller
svmiller / 1-gawk-at-fariss-lhr-data.R
Created November 15, 2017 23:04
Poking around Fariss' (2014) LHR data.
library(tidyverse)
library(lubridate) # just in case I need to manipulate a date
library(stringr) # just in case I need to manipulated a string
library(stevemisc) # for my personal theme
library(scales) # just in case I need to fudge a y-axis to be a scale
library(knitr) # just in case I need a markdown table
# I'm going to assume you have Fariss' data downloaded somewhere. Here's what mine looks like.
LHR <- read_csv("~/Dropbox/data/latent-human-rights/HumanRightsProtectionScores_v2.04.csv")
@svmiller
svmiller / twitter-art.md
Last active November 15, 2018 00:48
Useful for my purposes when I want to make a funny (lol, I know...) on the Twitter-dot-coms.

| ̄ ̄ ̄ ̄ ̄  ̄| | DEATH | | IS | | INEVITABLE | | _______| (__/) || (•ㅅ•) || /   づ

(・_・)っ

library(tidyverse)
library(stevemisc)
# Load data
Non <- read_csv("~/Dropbox/data/cow/wars/Non-StateWarData_v4.0.csv")
Intra <- read_csv("~/Dropbox/data/cow/wars/Intra-StateWarData_v4.1.csv")
Inter <- read_csv("~/Dropbox/data/cow/wars/Inter-StateWarData_v4.0.csv")
Extra <- read_csv("~/Dropbox/data/cow/wars/Extra-StateWarData_v4.0.csv")
@svmiller
svmiller / scrape-tidy-presidency-project-approval-data.R
Created May 22, 2018 15:10
Scrape American Presidency Project Approval Data
library(rvest)
library(lubridate)
library(tidyverse)
Truman <- read_html("http://www.presidency.ucsb.edu/data/popularity.php?pres=33")
Truman %>%
html_table(fill=T) -> Truman
Truman[[11]] -> Truman