Skip to content

Instantly share code, notes, and snippets.

@diamonaj
Last active March 25, 2019 02:17
Show Gist options
  • Save diamonaj/555eb605698b055fa76c1404c6c44bb7 to your computer and use it in GitHub Desktop.
Save diamonaj/555eb605698b055fa76c1404c6c44bb7 to your computer and use it in GitHub Desktop.
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
# 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
# age: age
# srvlng: Service length (years)
# reg1 - reg9 are regional binary variables
# binary religious variables: none, Protestant, Catholic, OtherC, OtherR
# binary party variables: Dems, Repubs, OthParty
# DEPENDENT VARIABLE: nowtot
#### BREAKOUT 1 ####
## Perform genetic matching with the following variables:
## Dems, Repubs, Christian, age, srvlng, demvote
## Tr = hasgirls
## Set pop.size = 20, set nboots = 250... complete the instructions below...
set.seed(2324); genout <- GenMatch(Tr = , X = cbind(), pop.size = , nboots = )
mout <- Match(Tr = , X = cbind(), Weight.matrix = )
MatchBalance( ~ , match.out = )
## If you obtain really high balance, consider rerunning with M = 2 or 3...
## If/when you are satisfied by balance achieved, then rerun Match() with Y included
## and obtain the treatment effect estimate, the standard error, and the confidence interval.
mout <- Match(Y = , Tr = ,
X = cbind(), Weight.matrix = )
summary(mout)
## If you get to the end and have extra time, you can try changing X (remember to change
## it in GenMatch, in Match, and also in the formula for MatchBalance().
## For example, you could try to control more finely for religion. You could try to control
## for race (e.g., binary "white" variable), or for region (reg1, reg2, etc.)
## IMPORTANT: SAVE YOUR mout object!
## Follow this protocol: save(object_name, file = "object_filename") to save to working directory
## e.g., if you have an object named mmm, save(mmm, file = "mmm")
## To retrieve your object, you would type: load("object_filename")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment