View source: R/treatment_assign.R
treatment_assign | R Documentation |
treatment_assign() carries out robust treatment assignment by strata/blocks
treatment_assign( data, share_control, n_t = 2, strata_varlist, missfits = c("global", "NA", "strata"), seed = 1990, share_ti = rep(1/n_t - share_control/n_t, times = n_t), key )
data |
A data.frame, tibble or data.table |
share_control |
share of the observations assigned to control group |
n_t |
Number of treatments groups |
strata_varlist |
vector of categorical variables to form the strata/blocks for random assignment. Should be in the form of vars(var1, var2, ...) |
missfits |
How to handle the misfits. Default is "global". See Carril (2016) for details. |
seed |
A number used to set.seed(). |
share_ti |
The share of each treatment group. If NULL (Default), each treatment group will have equal share. |
key |
The key identifier column of data. |
This function creates a variable that indicates the treatment status. The random assignment is made by strata/blocks. It can handle equal or unequal treatment shares. Finally, it has three methods available to handle misfits (same as randtreat in STATA): "global": assigning the observations that couldn't be randomly assigned globally, "strata": assigning the observations that couldn't be randomly assigned by strata, "NA": set the the treat observations that couldn't be randomly assigned to NA.
A list: "data" = the data with key, treat, strata, misfit column., "summary_strata" = A summary tibble with the membership of each strata and its size.
data<-data.frame(key = c(1:1000), ing_quartile = rep(c("Q1", "Q2", "Q3", "Q4"), each = 250), age_quartile = rep(c("Q1", "Q2", "Q3", "Q4"), times = 250)) assigment<-treatment_assign(data = data, share_control = 0.1, n_t = 3, strata_varlist = dplyr::vars(ing_quartile, age_quartile), missfits = "strata", seed = 1990, key = "key") table(data$treat, useNA = "ifany") prop.table(table(data$treat, useNA = "ifany"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.