Getting Started

This vignette uses the matrix API. Rows of Y are units, columns are time periods, controls come first, and treated units come last.

using MSC
using Statistics

sim = simulate_msc(
    ncontrols = 30,
    ntreated = 6,
    T0 = 60,
    T1 = 8,
    tau = 1.5,
    noise = 0.03,
    seed = 11,
)

est = msc_estimate(
    sim.Y,
    sim.N0,
    sim.T0;
    nlambda = 10,
    nfolds = 5,
    max_iter = 1000,
    tol = 1e-6,
)

round(est.estimate, digits = 3)
1.497

effect_matrix returns post-treatment effects by period and treated unit. The ATT is the average of this matrix.

effects = effect_matrix(est)
(
    size = size(effects),
    att = round(mean(effects), digits = 3),
    by_unit = round.(unit_effects(est), digits = 3),
)
(size = (8, 6), att = 1.497, by_unit = [1.515, 1.49, 1.496, 1.484, 1.491, 1.508])

The fitted weight matrix is sparse by construction:

first(weights_table(est; atol = 1e-8), 8)
8×3 DataFrame
Rowcontroltreatedweight
AnyAnyFloat64
1control_6treated_1-0.094151
2control_16treated_1-0.111713
3control_20treated_10.0118709
4control_21treated_10.132049
5control_30treated_1-0.316197
6control_3treated_2-0.0335523
7control_6treated_2-0.0631858
8control_20treated_20.0863237

Plotting recipes are available when Plots is loaded:

using Plots

plt = plot(
    est;
    title = "MSC average effect",
    xlabel = "Post-treatment period",
    ylabel = "Effect",
)