Skip to content

Instantly share code, notes, and snippets.

@diamonaj
diamonaj / 1b.R
Last active November 5, 2019 06:19
genout <- GenMatch(Tr=treat, X=X, BalanceMatrix=BalanceMat, estimand="ATT", exact = TRUE, M=1,
pop.size=16, max.generations=10, wait.generations=1)
#The outcome variable
Y=re78/1000
#
# Now that GenMatch() has found the optimal weights, let's estimate
# our causal effect of interest using those weights
#
@diamonaj
diamonaj / 1c.R
Last active November 5, 2019 06:18
genout <- GenMatch(Tr=treat, X=X, BalanceMatrix=BalanceMat)
#The outcome variable
Y=re78/1000
#
# Now that GenMatch() has found the optimal weights, let's estimate
# our causal effect of interest using those weights
#
mout <- Match(Y=Y, Tr=treat, X=X, Weight.matrix=genout)
sink("transcript.txt", split = TRUE)
cat(getwd(), "\n")
rm(list=ls())
library(foreign)
foo <- read.csv("https://course-resources.minerva.kgi.edu/uploaded_files/mke/00087718-6996/dw-data.csv")
X = cbind(foo$age, foo$education, foo$black, foo$hispanic, foo$married, foo$nodegree, foo$re75, foo$re74)
# https://tinyurl.com/y9syodxg
rm(list=ls())
library(Matching
)
library(foreign)
foo <- read.csv("https://course-resources.minerva.kgi.edu/uploaded_files/mke/00087718-6996/dw-data.csv")
X = cbind(foo$age, foo$education, foo$black, foo$re75, foo$re74)
@diamonaj
diamonaj / CS112_11_1_3.R
Last active November 18, 2018 17:31
Breakout3
# If you are copy/pasting this to an R Notebook, select "Raw" from the GitHub page before you copy.
# Check the sensitivity of your Genetic Matching results, using "hlsens" and "psens" in the rbounds library.
# You must load the library first.
# You should load your mout2 object... e.g., load("mout2")
## Here is the working matching code, in case it's helpful:
foo <- read.csv(url("https://course-resources.minerva.kgi.edu/uploaded_files/mke/00089202-1711/daughters.csv"))
which.two.or.more.girls <- which(foo$ngirls >= 2 & foo$nboys == 0)
@diamonaj
diamonaj / CS112_11_1_2.R
Last active November 17, 2019 15:00
Breakout2
# If you are copy/pasting this to an R Notebook, select "Raw" from the GitHub page before you copy.
# Table 1 in Ebonya
# Indep. vars
# anygirls: Any female children
# ngirls: Number of female children
# totchi: Total number of children
# white: White=1, 0 otherwise
# female: Female=1, 0 otherwise
@diamonaj
diamonaj / CS112_11_1_1.R
Last active March 25, 2019 02:17
Breakout1
# If you are copy/pasting this to an R Notebook, select "Raw" from the GitHub page before you copy.
# Replication file of Section 5 in
# Iacus, King, Porro (2011), Multivariate Matching Methods
# That Are Monotonic Imbalance Bounding, JASA, V 106, N. 493,
# p. 345-361
foo <- read.csv(url("https://course-resources.minerva.kgi.edu/uploaded_files/mke/00089202-1711/daughters.csv"))
# Table 1 in Ebonya
@diamonaj
diamonaj / Assignment1.R
Last active January 9, 2021 04:05
Assignment1 (code and questions)
######### RUN THE CODE BELOW IN R. R-STUDIO IS THE RECOMMENDED IDE. BOTH R AND R-STUDIO ARE FREE.
######### QUESTIONS SHOULD BE POSTED TO PIAZZA
######### THE ACTUAL ASSIGNMENT BEGINS ON LINE 71 (where it says "ASSIGNMENT 1...")
### Multilateral Development Institution Data
foo <- read.csv("https://tinyurl.com/yb4phxx8") # read in the data
# column names
names(foo)
@diamonaj
diamonaj / CS112_10_1
Created March 17, 2019 18:00
Code Answers to Peackeeping Breakout
PEACEKEEPING WORKOUT (based on King, Gary;Zeng, Langche, 2007,
"Replication data for: When Can History be Our Guide?
The Pitfalls of Counterfactual Inference",
https://hdl.handle.net/1902.1/DXRXCFAWPK,
Harvard Dataverse, V4,
UNF:3:DaYlT6QSX9r0D50ye+tXpA== [fileUNF] )
# CONSIDER USING THE JUPYTER NOTEBOOK WITH R-SERVER KERNEL (NEVER R-SAGE KERNEL)
foo_orig <- read.csv("https://course-resources.minerva.kgi.edu/uploaded_files/mke/00086677-3767/peace.csv")
PEACEKEEPING WORKOUT (based on King, Gary;Zeng, Langche, 2007,
"Replication data for: When Can History be Our Guide?)
# CONSIDER USING THE JUPYTER NOTEBOOK WITH R-SERVER KERNEL (NEVER R-SAGE KERNEL)
rm(list=ls()) # WARNING: THIS DELETES EVERYTHING IN YOUR R WORKSPACE
detach(foo) # probably unnecessary, but just in case you had it attached...
library(Matching)
foo <- read.csv("https://course-resources.minerva.kgi.edu/uploaded_files/mke/00086677-3767/peace.csv")