Skip to content

Instantly share code, notes, and snippets.

@diamonaj
Created October 27, 2018 18:11
Show Gist options
  • Select an option

  • Save diamonaj/62965d6c8307c1b77d59b9852007b9c7 to your computer and use it in GitHub Desktop.

Select an option

Save diamonaj/62965d6c8307c1b77d59b9852007b9c7 to your computer and use it in GitHub Desktop.
storage.vector <- NA
# Function that assigns treatment/control depending on
# propensity scores (assignment probabilities)
experiment <- function(vector.of.probabilities = NULL) {
k = 0
for (i in 1:length(vector.of.probabilities)) {
if(
sample(x = c(1,0), size = 1, prob = c(vector.of.probabilities[i],
1 - vector.of.probabilities[i])) == 1) {
storage.vector[k] <- i
k = k + 1
}
}
return(list(treated.units = storage.vector,
control.units = (1:(length(vector.of.probabilities)))[-storage.vector]))
}
### Here are two distributions
# Incomes for the female-headed households without children are defined per the following code:
set.seed(123); nokids.income <- round(abs(exp(rnorm(1000, 5, 1))))
# Household sizes for the female-headed households with children are defined per this code:
set.seed(123); kids.hhsize <- round(sqrt(abs(rnorm(1000, 12, 100))) + .3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment