Function to draw multiple potential outcomes, one for each condition that an assignment variable can be set to.

## Usage

potential_outcomes(x, conditions = list(Z = c(0, 1)), sep = "_")

## Arguments

x

Formula describing the potential outcomes with the outcome name on the left hand side and the expression describing the potential outcomes on the right hand side, e.g. Y ~ 0.1 * Z + rnorm(N) (this would draw two potential outcomes columns by default, named Y_Z_0 and Y_Z_1).

conditions

A list of conditions for each assignment variable. Defaults to list(Z = c(0, 1)).

sep

Separator inserted between the outcome name and the assignment variable name used to construct the potential outcome variable names, defaults to "_".

## Examples


fabricate(
N = 10,
U = rnorm(N),
potential_outcomes(Y ~ 0.1 * Z + U)
)
#>    ID            U        Y_Z_0       Y_Z_1
#> 1  01 -0.330008991 -0.330008991 -0.23000899
#> 2  02  0.780017893  0.780017893  0.88001789
#> 3  03  0.246418030  0.246418030  0.34641803
#> 4  04 -0.171430937 -0.171430937 -0.07143094
#> 5  05  1.130348708  1.130348708  1.23034871
#> 6  06  0.470111747  0.470111747  0.57011175
#> 7  07  0.908487107  0.908487107  1.00848711
#> 8  08 -0.003946898 -0.003946898  0.09605310
#> 9  09 -0.626360877 -0.626360877 -0.52636088
#> 10 10 -0.695494396 -0.695494396 -0.59549440

# equivalently,

fabricate(
N = 10,
U = rnorm(N),
potential_outcomes(Y ~ 0.1 * Z + U,
conditions = list(Z = c(0, 1)))
)
#>    ID           U       Y_Z_0      Y_Z_1
#> 1  01  1.72874460  1.72874460  1.8287446
#> 2  02 -0.34098278 -0.34098278 -0.2409828
#> 3  03  0.17407167  0.17407167  0.2740717
#> 4  04 -0.41202291 -0.41202291 -0.3120229
#> 5  05  0.08215034  0.08215034  0.1821503
#> 6  06  0.53497996  0.53497996  0.6349800
#> 7  07  0.03362362  0.03362362  0.1336236
#> 8  08 -0.67648623 -0.67648623 -0.5764862
#> 9  09 -0.48070807 -0.48070807 -0.3807081
#> 10 10 -0.65355094 -0.65355094 -0.5535509

fabricate(
N = 10,
U = rnorm(N),
potential_outcomes(Y ~ 0.1 * Z + U,
conditions = list(Z = c(1, 2, 3)))
)
#>    ID          U      Y_Z_1      Y_Z_2      Y_Z_3
#> 1  01 -0.6837585 -0.5837585 -0.4837585 -0.3837585
#> 2  02  0.6372287  0.7372287  0.8372287  0.9372287
#> 3  03 -1.8956964 -1.7956964 -1.6956964 -1.5956964
#> 4  04  0.9875404  1.0875404  1.1875404  1.2875404
#> 5  05  1.3082691  1.4082691  1.5082691  1.6082691
#> 6  06 -0.4993503 -0.3993503 -0.2993503 -0.1993503
#> 7  07  0.7563782  0.8563782  0.9563782  1.0563782
#> 8  08 -0.5482245 -0.4482245 -0.3482245 -0.2482245
#> 9  09 -0.6847399 -0.5847399 -0.4847399 -0.3847399
#> 10 10  1.0310071  1.1310071  1.2310071  1.3310071

fabricate(
N = 10,
U = rnorm(N),
potential_outcomes(Y ~ 0.1 * Z1 + 0.3 * Z2 + 0.5 * Z1 * Z2 + U,
conditions = list(Z1 = c(0, 1),
Z2 = c(0, 1)))
)
#>    ID          U Y_Z1_0_Z2_0 Y_Z1_1_Z2_0 Y_Z1_0_Z2_1 Y_Z1_1_Z2_1
#> 1  01 -0.5810295  -0.5810295  -0.4810295  -0.2810295   0.3189705
#> 2  02  1.5482073   1.5482073   1.6482073   1.8482073   2.4482073
#> 3  03 -1.9621767  -1.9621767  -1.8621767  -1.6621767  -1.0621767
#> 4  04  0.4582724   0.4582724   0.5582724   0.7582724   1.3582724
#> 5  05 -1.1409825  -1.1409825  -1.0409825  -0.8409825  -0.2409825
#> 6  06  0.7079541   0.7079541   0.8079541   1.0079541   1.6079541
#> 7  07  1.4018953   1.4018953   1.5018953   1.7018953   2.3018953
#> 8  08  0.4797217   0.4797217   0.5797217   0.7797217   1.3797217
#> 9  09 -1.7046055  -1.7046055  -1.6046055  -1.4046055  -0.8046055
#> 10 10  0.6456383   0.6456383   0.7456383   0.9456383   1.5456383