Description Usage Arguments Examples
Estimate average treatment effect in each subgroup created from predictionresult.
1 | sample_splitting_estimation(data, Y, treatment, X, M, ntilen, adjusted)
|
data |
an optional data frame containing the variables in the model. |
Y |
string which indicates the outcome variable in the estimation. |
treatment |
string which indicates the treatment variable. |
X |
string that indicates the control variables. you are able to set like c("a", "b") to implement multiple control variables. |
M |
numeric that how many time will you iterate the splitting estimation. M in Abadie et al. (2016). |
ntilen |
int that show how many group will you make in the dataset |
adjusted |
TRUE/FALSE to set which estimation you want to implement, adjusted estimation or unadjusted estimation. |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | ##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function (data, Y, treatment, X, M, ntilen, adjusted)
{
control_set <- data %>% filter_(paste(treatment, "==", 0))
treatment_set <- data %>% filter_(paste(treatment, "==",
1))
factor_col <- which(sapply(data, class) %in% c("character",
"factor"))
M <- M
result <- data.frame()
for (i in 1:M) {
sample_flag_control <- sample(NROW(control_set), NROW(control_set)/2,
replace = F)
prediction_set <- control_set[sample_flag_control, ]
estimation_set <- control_set[-sample_flag_control, ]
estimation_set_cut <- level_cut(dataset = estimation_set,
prediction_set = prediction_set, factor_col = factor_col)
treatment_set_cut <- level_cut(dataset = treatment_set,
prediction_set = prediction_set, factor_col = factor_col)
ntile_formula <- as.formula(paste(Y, "~", paste(X, collapse = " + ")))
reg <- prediction_set %>% lm(data = ., formula = ntile_formula)
out <- ATE_ntile(model = reg, Y = Y, X = X, treatment = treatment,
adjusted = adjusted, estimation_dataset = estimation_set_cut,
treatment_dataset = treatment_set_cut, ntilen = ntilen,
i = i)
result <- rbind(result, out)
}
return(result)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.