Skip to contents

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.17407167  0.17407167  0.2740717
#> 2  02 -0.41202291 -0.41202291 -0.3120229
#> 3  03  0.08215034  0.08215034  0.1821503
#> 4  04  0.53497996  0.53497996  0.6349800
#> 5  05  0.03362362  0.03362362  0.1336236
#> 6  06 -0.67648623 -0.67648623 -0.5764862
#> 7  07 -0.48070807 -0.48070807 -0.3807081
#> 8  08 -0.65355094 -0.65355094 -0.5535509
#> 9  09 -0.68375847 -0.68375847 -0.5837585
#> 10 10  0.63722867  0.63722867  0.7372287

# 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.8956964 -1.8956964 -1.7956964
#> 2  02  0.9875404  0.9875404  1.0875404
#> 3  03  1.3082691  1.3082691  1.4082691
#> 4  04 -0.4993503 -0.4993503 -0.3993503
#> 5  05  0.7563782  0.7563782  0.8563782
#> 6  06 -0.5482245 -0.5482245 -0.4482245
#> 7  07 -0.6847399 -0.6847399 -0.5847399
#> 8  08  1.0310071  1.0310071  1.1310071
#> 9  09 -0.5810295 -0.5810295 -0.4810295
#> 10 10  1.5482073  1.5482073  1.6482073

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 -1.96217674 -1.86217674 -1.7621767 -1.6621767
#> 2  02  0.45827243  0.55827243  0.6582724  0.7582724
#> 3  03 -1.14098248 -1.04098248 -0.9409825 -0.8409825
#> 4  04  0.70795415  0.80795415  0.9079541  1.0079541
#> 5  05  1.40189529  1.50189529  1.6018953  1.7018953
#> 6  06  0.47972165  0.57972165  0.6797217  0.7797217
#> 7  07 -1.70460548 -1.60460548 -1.5046055 -1.4046055
#> 8  08  0.64563834  0.74563834  0.8456383  0.9456383
#> 9  09  0.54523742  0.64523742  0.7452374  0.8452374
#> 10 10 -0.03284671  0.06715329  0.1671533  0.2671533

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.84913604  0.84913604  0.94913604   1.1491360   1.7491360
#> 2  02  0.13741257  0.13741257  0.23741257   0.4374126   1.0374126
#> 3  03  1.90121256  1.90121256  2.00121256   2.2012126   2.8012126
#> 4  04 -0.03754493 -0.03754493  0.06245507   0.2624551   0.8624551
#> 5  05 -1.23259711 -1.23259711 -1.13259711  -0.9325971  -0.3325971
#> 6  06  0.16707920  0.16707920  0.26707920   0.4670792   1.0670792
#> 7  07  0.71954641  0.71954641  0.81954641   1.0195464   1.6195464
#> 8  08  0.18677703  0.18677703  0.28677703   0.4867770   1.0867770
#> 9  09 -0.76503704 -0.76503704 -0.66503704  -0.4650370   0.1349630
#> 10 10  1.25358812  1.25358812  1.35358812   1.5535881   2.1535881