Skip to content

Instantly share code, notes, and snippets.

@diamonaj
Last active November 17, 2019 15:00
Show Gist options
  • Save diamonaj/c85faf0c240c5aeffb73c199d3839fd4 to your computer and use it in GitHub Desktop.
Save diamonaj/c85faf0c240c5aeffb73c199d3839fd4 to your computer and use it in GitHub Desktop.
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
# 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
#### Step 2 ####
## Re-run genetic matching using a different causal question
## What's the impact of having two girls and no boys vs. 2 boys and no girls?
## Same data set as before
foo <- read.csv(url("https://course-resources.minerva.kgi.edu/uploaded_files/mke/00089202-1711/daughters.csv"))
## Here is some code to get you started...
which.two.or.more.girls <- which(foo$ngirls >= 2 & foo$nboys == 0)
which.two.or.more.boys <- which(foo$ngirls == 0 & foo$nboys >= 2)
subset2kids <- foo[c(which.two.or.more.girls, which.two.or.more.boys), ]
## 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...
X_subset2kids <- cbind(subset2kids$)
set.seed(2324); genout2 <- GenMatch(Tr = subset2kids$, X = X_subset2kids, pop.size = , nboots = )
mout2 <- 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.
mout2 <- Match(Y = subset2kids$, Tr = subset2kids$, X = X_subset2kids, Weight.matrix = )
summary(mout2)
## IMPORTANT: SAVE YOUR mout2 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
## 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.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment