Matches treated and control units on the basis of their pre-treatment covariate values.
Usage
morie_matching_longitudinal(
data,
treatment,
covariates,
unit,
time,
treatment_time,
n_pre_periods = 1L,
method = "nearest_neighbor"
)Arguments
- data
Panel data frame.
- treatment
Binary treatment indicator column.
- covariates
Character vector of covariates.
- unit
Column name identifying units.
- time
Column name identifying time.
- treatment_time
Column giving the (per-unit) start of treatment; non-finite values indicate never-treated.
- n_pre_periods
Number of pre-treatment periods to summarise.
- method
One of
"nearest_neighbor"or"mahalanobis".
Examples
# \donttest{
set.seed(1)
panel <- data.frame(id = rep(1:40, each = 3), t = rep(1:3, 40),
x1 = rnorm(120),
d = rep(rbinom(40, 1, 0.5), each = 3))
panel$t0 <- ifelse(panel$d == 1, 3, NA)
morie_matching_longitudinal(panel, "d", "x1", unit = "id",
time = "t", treatment_time = "t0")
#> $matched_data
#> ._treated x1
#> 1 0 -0.835628612
#> 2 1 0.329507772
#> 3 1 0.738324705
#> 4 0 0.389843236
#> 9 0 -0.155795507
#> 10 1 -0.478150055
#> 11 1 -0.102787727
#> 12 1 -1.377059557
#> 14 1 -0.164523596
#> 16 0 0.768532925
#> 17 0 0.398105880
#> 20 1 0.569719627
#> 21 1 -0.039240003
#> 22 0 0.188792300
#> 24 1 0.475509529
#> 25 1 -0.934097632
#> 26 0 0.001105352
#> 27 0 -0.568668733
#> 28 1 1.178086997
#> 29 1 0.332950371
#> 30 0 0.267098791
#> 31 0 1.160402616
#> 32 0 0.558486426
#> 33 0 -1.224612615
#> 39 0 -0.319992869
#> 40 1 0.494188331
#>
#> $n_treated
#> [1] 13
#>
#> $n_matched_control
#> [1] 13
#>
#> $match_pairs
#> treated_idx control_idx distance
#> 2 2 22 0.021757955
#> 3 3 16 0.004670908
#> 10 10 27 0.013996338
#> 11 11 9 0.008196262
#> 12 12 33 0.023571919
#> 14 14 39 0.024039243
#> 20 20 32 0.001736920
#> 21 21 26 0.006238350
#> 24 24 4 0.013246044
#> 25 25 1 0.015225650
#> 28 28 31 0.002734425
#> 29 29 30 0.010182219
#> 40 40 17 0.014856629
#>
#> $method
#> [1] "longitudinal_nearest_neighbor"
#>
#> $details
#> $details$engine
#> [1] "native-greedy-1d"
#>
#> $details$caliper
#> NULL
#>
#> $details$replace
#> [1] FALSE
#>
#> $details$n_neighbors
#> [1] 1
#>
#> $details$alpha
#> [1] 0.05
#>
#> $details$propensity_logit_sd
#> [1] 0.1198941
#>
#>
#> attr(,"class")
#> [1] "morie_match_result" "list"
# }
