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  0.6272381  0.6272381  0.72723807
#> 2  02 -0.9535116 -0.9535116 -0.85351155
#> 3  03  0.6858708  0.6858708  0.78587077
#> 4  04 -0.5539804 -0.5539804 -0.45398038
#> 5  05  1.2386265  1.2386265  1.33862647
#> 6  06 -0.4417577 -0.4417577 -0.34175771
#> 7  07 -1.2461571 -1.2461571 -1.14615709
#> 8  08  1.6760899  1.6760899  1.77608987
#> 9  09 -0.1515111 -0.1515111 -0.05151108
#> 10 10 -0.9886487 -0.9886487 -0.88864873

# 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.1537107  1.1537107  1.2537107
#> 2  02 -2.1222649 -2.1222649 -2.0222649
#> 3  03 -0.5859338 -0.5859338 -0.4859338
#> 4  04  1.5149583  1.5149583  1.6149583
#> 5  05  0.6114122  0.6114122  0.7114122
#> 6  06  1.0332128  1.0332128  1.1332128
#> 7  07  0.4563567  0.4563567  0.5563567
#> 8  08  0.2210251  0.2210251  0.3210251
#> 9  09 -0.2440738 -0.2440738 -0.1440738
#> 10 10  0.2862861  0.2862861  0.3862861

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.193487898  0.29348790  0.3934879  0.4934879
#> 2  02  1.272251951  1.37225195  1.4722520  1.5722520
#> 3  03  0.327225714  0.42722571  0.5272257  0.6272257
#> 4  04 -0.005208752  0.09479125  0.1947912  0.2947912
#> 5  05  0.192387957  0.29238796  0.3923880  0.4923880
#> 6  06 -1.648590764 -1.54859076 -1.4485908 -1.3485908
#> 7  07 -1.226428848 -1.12642885 -1.0264288 -0.9264288
#> 8  08  0.177196313  0.27719631  0.3771963  0.4771963
#> 9  09 -0.800826732 -0.70082673 -0.6008267 -0.5008267
#> 10 10  2.221068887  2.32106889  2.4210689  2.5210689

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.45561276  0.45561276  0.55561276   0.7556128   1.3556128
#> 2  02  0.84817511  0.84817511  0.94817511   1.1481751   1.7481751
#> 3  03  0.32614138  0.32614138  0.42614138   0.6261414   1.2261414
#> 4  04 -1.57125998 -1.57125998 -1.47125998  -1.2712600  -0.6712600
#> 5  05 -0.83469660 -0.83469660 -0.73469660  -0.5346966   0.0653034
#> 6  06 -0.12578297 -0.12578297 -0.02578297   0.1742170   0.7742170
#> 7  07  0.87374116  0.87374116  0.97374116   1.1737412   1.7737412
#> 8  08 -1.07118739 -1.07118739 -0.97118739  -0.7711874  -0.1711874
#> 9  09 -0.76463954 -0.76463954 -0.66463954  -0.4646395   0.1353605
#> 10 10 -0.01387618 -0.01387618  0.08612382   0.2861238   0.8861238