Created
October 27, 2018 18:11
-
-
Save diamonaj/62965d6c8307c1b77d59b9852007b9c7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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