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

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 -1.03689560 -1.03689560 -0.93689560
#> 2  02 -0.28476301 -0.28476301 -0.18476301
#> 3  03 -1.64813864 -1.64813864 -1.54813864
#> 4  04  0.13254876  0.13254876  0.23254876
#> 5  05  1.17742017  1.17742017  1.27742017
#> 6  06  0.15552338  0.15552338  0.25552338
#> 7  07  0.32867403  0.32867403  0.42867403
#> 8  08  1.23796246  1.23796246  1.33796246
#> 9  09  0.11807125  0.11807125  0.21807125
#> 10 10 -0.09010967 -0.09010967  0.00989033

# 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.70061808  0.70061808  0.8006181
#> 2  02  1.06046179  1.06046179  1.1604618
#> 3  03 -2.21600760 -2.21600760 -2.1160076
#> 4  04 -0.63284750 -0.63284750 -0.5328475
#> 5  05  0.02380316  0.02380316  0.1238032
#> 6  06 -0.39373089 -0.39373089 -0.2937309
#> 7  07 -1.11150592 -1.11150592 -1.0115059
#> 8  08  0.24340115  0.24340115  0.3434011
#> 9  09 -0.64079573 -0.64079573 -0.5407957
#> 10 10  0.42395186  0.42395186  0.5239519

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.15549613 -2.05549613 -1.9554961 -1.8554961
#> 2  02 -0.70445926 -0.60445926 -0.5044593 -0.4044593
#> 3  03 -0.85771516 -0.75771516 -0.6577152 -0.5577152
#> 4  04  0.26832943  0.36832943  0.4683294  0.5683294
#> 5  05  1.18665886  1.28665886  1.3866589  1.4866589
#> 6  06  0.89695772  0.99695772  1.0969577  1.1969577
#> 7  07 -0.06630224  0.03369776  0.1336978  0.2336978
#> 8  08  1.59087566  1.69087566  1.7908757  1.8908757
#> 9  09  0.03203081  0.13203081  0.2320308  0.3320308
#> 10 10 -0.04787739  0.05212261  0.1521226  0.2521226

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.7326153  -0.7326153  -0.6326153 -0.43261530   0.1673847
#> 2  02 -0.5147579  -0.5147579  -0.4147579 -0.21475792   0.3852421
#> 3  03 -1.4046127  -1.4046127  -1.3046127 -1.10461270  -0.5046127
#> 4  04  0.3070250   0.3070250   0.4070250  0.60702500   1.2070250
#> 5  05  1.2171252   1.2171252   1.3171252  1.51712521   2.1171252
#> 6  06 -1.3433557  -1.3433557  -1.2433557 -1.04335571  -0.4433557
#> 7  07  0.6043685   0.6043685   0.7043685  0.90436855   1.5043685
#> 8  08  0.3697197   0.3697197   0.4697197  0.66971970   1.2697197
#> 9  09  0.8543749   0.8543749   0.9543749  1.15437491   1.7543749
#> 10 10 -0.3640760  -0.3640760  -0.2640760 -0.06407601   0.5359240