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.4930602  0.4930602  0.5930602
#> 2  02  1.3366320  1.3366320  1.4366320
#> 3  03  0.8886001  0.8886001  0.9886001
#> 4  04 -2.0938406 -2.0938406 -1.9938406
#> 5  05  1.4189190  1.4189190  1.5189190
#> 6  06  1.0430426  1.0430426  1.1430426
#> 7  07 -0.3119563 -0.3119563 -0.2119563
#> 8  08 -1.0932664 -1.0932664 -0.9932664
#> 9  09 -1.2231422 -1.2231422 -1.1231422
#> 10 10 -2.1206555 -2.1206555 -2.0206555

# 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  0.09763563  0.09763563  0.19763563
#> 2  02  0.18129160  0.18129160  0.28129160
#> 3  03  0.07425098  0.07425098  0.17425098
#> 4  04 -0.51311933 -0.51311933 -0.41311933
#> 5  05  0.67200311  0.67200311  0.77200311
#> 6  06 -1.69245885 -1.69245885 -1.59245885
#> 7  07  1.46719145  1.46719145  1.56719145
#> 8  08 -2.14625864 -2.14625864 -2.04625864
#> 9  09  0.66513070  0.66513070  0.76513070
#> 10 10 -0.12509188 -0.12509188 -0.02509188

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  2.46837585  2.56837585  2.66837585  2.76837585
#> 2  02 -0.05503008  0.04496992  0.14496992  0.24496992
#> 3  03 -0.38770988 -0.28770988 -0.18770988 -0.08770988
#> 4  04  0.44484089  0.54484089  0.64484089  0.74484089
#> 5  05 -0.14559963 -0.04559963  0.05440037  0.15440037
#> 6  06  0.59644784  0.69644784  0.79644784  0.89644784
#> 7  07 -0.79597627 -0.69597627 -0.59597627 -0.49597627
#> 8  08  2.03671031  2.13671031  2.23671031  2.33671031
#> 9  09 -0.44919350 -0.34919350 -0.24919350 -0.14919350
#> 10 10  0.17858121  0.27858121  0.37858121  0.47858121

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.5923451   0.5923451  0.69234510   0.8923451  1.49234510
#> 2  02 -0.1276024  -0.1276024 -0.02760236   0.1723976  0.77239764
#> 3  03 -0.7061509  -0.7061509 -0.60615093  -0.4061509  0.19384907
#> 4  04 -0.8151740  -0.8151740 -0.71517397  -0.5151740  0.08482603
#> 5  05  0.1237721   0.1237721  0.22377209   0.4237721  1.02377209
#> 6  06  1.1222136   1.1222136  1.22221358   1.4222136  2.02221358
#> 7  07  0.1028767   0.1028767  0.20287669   0.4028767  1.00287669
#> 8  08  1.3326670   1.3326670  1.43266696   1.6326670  2.23266696
#> 9  09  1.0134507   1.0134507  1.11345069   1.3134507  1.91345069
#> 10 10  0.2733610   0.2733610  0.37336099   0.5733610  1.17336099