Skip to content
Scenario2 min read

ASCM pseudocode with math

Exactly one treated unit in the analysis sample.

0) Assumptions

Implementation / observed-data requirements

  • Exactly one treated unit in the analysis sample.
  • At least 2 donor units in the donor pool.
  • Donors are never treated during the analysis horizon.
  • The treated unit is untreated in all pre-periods and treated in all post-periods.
  • There is at least one pre-treatment period and at least one post-treatment period.
  • Pre and post periods are disjoint, ordered, and satisfy
max(pre)<min(post). \max(\text{pre}) < \min(\text{post}).
  • The treated+donor analysis block is balanced over all analysis periods.
  • There are no duplicate ((unit,time)) rows.
  • There are no missing outcomes in the treated+donor analysis block used for estimation.

Identification / modeling assumptions

  • No interference / spillovers: donor outcomes are unaffected by the treated unit’s treatment.
  • No anticipation: treatment does not affect the treated unit in pre-periods.
  • The treated unit’s untreated outcome path is well approximated by the donor pool, at least in the pre-treatment period.
  • Good pre-treatment fit is informative about the treated unit’s untreated post-treatment path.
  • In ASCM, residual imbalance left by SCM is adequately captured by the augmentation model, allowing controlled extrapolation beyond the donor convex hull.
  • The untreated outcome relationship is stable from pre- to post-period absent treatment.

Inference assumptions

  • For CWZ-style pointwise conformal inference, the residual process under the null is sufficiently stable / approximately shift-invariant for circular time shifts to generate a valid or approximately valid reference distribution.

ASCM pseudocode with math

code.text

1) Build balanced panel matrices

code.text

2) Fit simplex SCM anchor ( w_{sc} )

We first estimate simplex-constrained SCM weights.

Optimization problem

w^sc=argminwRJY1preX0prew22+λscw22 \hat w_{sc} = \arg\min_{w\in\mathbb{R}^J} |Y_1^{pre}-X_0^{pre}w|_2^2 + \lambda_{sc}|w|_2^2

subject to

wj0,j=1Jwj=1 w_j \ge 0, \qquad \sum_{j=1}^{J} w_j = 1

Define

Gsc=(X0pre)X0pre+λscIJ G_{sc} = (X_0^{pre})^\top X_0^{pre} + \lambda_{sc} I_J b=(X0pre)Y1pre b = (X_0^{pre})^\top Y_1^{pre}

Then the objective becomes

w^sc=argminwΔJ(wGscw2bw) \hat w_{sc} = \arg\min_{w\in\Delta_J} \left( w^\top G_{sc} w - 2 b^\top w \right)

where

ΔJ={wRJ:wj0,  1w=1}\Delta_J = \{\, w \in \mathbb{R}^J : w_j \ge 0,\; \mathbf{1}^\top w = 1 \,\}

Pseudocode

code.text

3) Fit augmented weights ( w_{aug} )

Now fit ridge-augmented weights centered around the simplex anchor.

Optimization problem

w^aug=argminwRJY1preX0prew22+λaugww^sc22 \hat w_{aug} = \arg\min_{w\in\mathbb{R}^J} |Y_1^{pre}-X_0^{pre}w|_2^2 + \lambda_{aug}|w-\hat w_{sc}|_2^2

First-order condition:

(X0pre)(X0pre)w+λaugw=(X0pre)Y1pre+λaugw^sc (X_0^{pre})^\top(X_0^{pre}) w + \lambda_{aug} w = (X_0^{pre})^\top Y_1^{pre} + \lambda_{aug}\hat w_{sc}

Define

Gaug=(X0pre)X0pre+λaugI G_{aug} = (X_0^{pre})^\top X_0^{pre} + \lambda_{aug} I r=(X0pre)Y1pre+λaugw^sc r = (X_0^{pre})^\top Y_1^{pre} + \lambda_{aug} \hat w_{sc}

Unconstrained solution:

w~aug=Gaug1r \tilde w_{aug} = G_{aug}^{-1} r

Optional sum-to-one correction

If enforcing

1w=1 \mathbf{1}^\top w = 1

then

w^aug=w~augGaug111w~aug11Gaug11 \hat w_{aug} = \tilde w_{aug} - G_{aug}^{-1}\mathbf{1} \frac{\mathbf{1}^\top \tilde w_{aug}-1} {\mathbf{1}^\top G_{aug}^{-1}\mathbf{1}}

Otherwise

w^aug=w~aug \hat w_{aug} = \tilde w_{aug}

Pseudocode

code.text

4) Build synthetic path and dynamic treatment effects

Synthetic untreated outcome:

Y^0all=X0allw^aug \hat Y_0^{all} = X_0^{all} \hat w_{aug}

Gap path:

g^all=Y1allY^0all \hat g^{all} = Y_1^{all} - \hat Y_0^{all}

Dynamic treatment effects:

τ^t=Y1tX0tw^aug,tpost \hat\tau_t = Y_{1t} - X_{0t}^\top \hat w_{aug}, \qquad t \in post

5) Default inference: average ATT t-test

This layer targets an aggregate post-treatment effect using fold-based bias correction.


5.1 Build holdout blocks

Let requested number of folds be (K_{req}). Define:

K=min(Kreq,T0),r=min(T0K,T1) K=\min(K_{req}, T_0), \qquad r=\min\left(\left\lfloor\frac{T_0}{K}\right\rfloor, T_1\right)

Construct contiguous pre-treatment holdout blocks

Bk=(k1)r,,kr1,k=1,,K. B_k={{(k-1)r,\ldots,kr-1}}, \qquad k=1,\ldots,K.

Each block has length (r).


5.2 Fold-specific refits

For each fold (k):

  • training pre-periods:
pretrain(k)=preBk pre_{train}^{(k)} = pre \setminus B_k
  • fit fold-specific weights:
w^aug(k)=argminwY1,trainpreX0,trainprew22λaugww^sc(k)22 \hat w_{aug}^{(k)} = \arg\min_w |Y_{1,train}^{pre}-X_{0,train}^{pre}w|_2^2 \lambda_{aug}|w-\hat w_{sc}^{(k)}|_2^2

with the same anchor-then-augment procedure applied on the training subset.

  • compute post mean gap:
gˉpost(k)=1T1tpost(Y1tX0tw^aug(k)) \bar g_{post}^{(k)} = \frac{1}{T_1} \sum_{t\in post} \left(Y_{1t}-X_{0t}^\top \hat w_{aug}^{(k)}\right)
  • compute holdout pre mean gap:
gˉhold(k)=1rtBk(Y1tX0tw^aug(k)) \bar g_{hold}^{(k)} = \frac{1}{r} \sum_{t\in B_k} \left(Y_{1t}-X_{0t}^\top \hat w_{aug}^{(k)}\right)
  • fold ATT estimate:
τ^k=gˉpost(k)gˉhold(k) \hat\tau_k = \bar g_{post}^{(k)}-\bar g_{hold}^{(k)}

Aggregate across folds:

τ^1Kk=1Kτ^k \hat\tau \frac{1}{K}\sum_{k=1}^K \hat\tau_k

5.3 Self-normalized t-statistic

Compute fold sample standard deviation:

sK1K1k=1K(τ^kτ^)2 s_K \sqrt{ \frac{1}{K-1}\sum_{k=1}^K(\hat\tau_k-\hat\tau)^2 }

Scale adjustment:

σ^τ1+KrT1sK. \hat\sigma_\tau \sqrt{1+\frac{Kr}{T_1}} s_K.

Estimated standard error:

SE^σ^τK \widehat{SE} \frac{\hat\sigma_\tau}{\sqrt K}

Test statistic:

tK,τ^σ^τ t \frac{\sqrt K,\hat\tau}{\hat\sigma_\tau}

Two-sided p-value:

p=2Pr(tK1t). p = 2\Pr\left(|t_{K-1}|\ge |t|\right).

Confidence interval:

CI1α=[τ^t1α/2,K1SE^,τ^+t1α/2,K1SE^]. CI_{1-\alpha} = \left[ \hat\tau - t_{1-\alpha/2,K-1}\widehat{SE}, \hat\tau + t_{1-\alpha/2,K-1}\widehat{SE} \right].

Pseudocode

code.text

6) Optional pointwise conformal inference for each post period

For each post period tpostt^\star \in post, perform grid inversion of null hypotheses

H0:τt=θ. H_0:\tau_{t^\star}=\theta.

6.1 Reduced sample for one target post period

For a fixed post period tt^\star, keep only:

  • all pre periods,
  • the single target post period tt^\star.

So the reduced sample size is

T0+1. T_0+1.

For candidate null effect (\theta), modify the treated outcome at the target period:

Y1,t(θ)=Y1,tθ. Y_{1,t^\star}^{(\theta)} = Y_{1,t^\star}-\theta.

Let

Y1(θ)=(Y1,1,,Y1,T0,Y1,tθ). Y_1^{(\theta)} = \big( Y_{1,1},\ldots,Y_{1,T_0},Y_{1,t^\star}-\theta \big).

Refit the augmented weights on the reduced sample:

w^aug(θ)=argminwY1(θ)X0w22+λaugww^sc(θ)22. \hat w_{aug}^{(\theta)} = \arg\min_w |Y_1^{(\theta)}-X_0 w|_2^2 + \lambda_{aug}|w-\hat w_{sc}^{(\theta)}|_2^2.

Residual vector under the null:

u(θ)=Y1(θ)X0w^aug(θ)RT0+1. u^{(\theta)} = Y_1^{(\theta)}-X_0 \hat w_{aug}^{(\theta)} \in \mathbb R^{T_0+1}.

6.2 CWZ statistic

Let the last coordinate correspond to the single reduced-sample post period.

Define the CWZ statistic:

S(u)=postutnpost. S(u) = \frac{\left|\sum_{post}u_t\right|}{\sqrt{n_{post}}}.

Since here npost=1n_{post}=1,

S(u)=upost. S(u)=|u_{post}|.

6.3 Circular-shift randomization p-value

Let πm\pi_m denote the mm-th circular shift of the residual vector, for

m=1,,T0+1. m=1,\ldots,T_0+1.

Compute

p^(θ)=1T0+1m=1T0+11 ⁣(S(πmu(θ))S(u(θ))1012)\hat p(\theta) = \frac{1}{T_0+1} \sum_{m=1}^{T_0+1} \mathbf{1}\!\left( S(\pi_m u^{(\theta)}) \ge S(u^{(\theta)}) - 10^{-12} \right)

This is the randomization p-value for the null effect θ\theta.


6.4 Invert the test over a grid

Choose a grid

Θ=θ1,,θG. \Theta={\theta_1,\ldots,\theta_G}.

For each (\theta_g\in\Theta), compute (\hat p(\theta_g)).

Accepted set:

At=θΘ:p^(θ)>α. A_{t^\star} = {\theta\in\Theta:\hat p(\theta)>\alpha}.

Convert accepted grid points into contiguous accepted segments:

At==1Lt[a,b]. A_{t^\star} = \bigcup_{\ell=1}^{L_{t^\star}} [a_{\ell}, b_{\ell}].

If there is exactly one accepted segment, define the pointwise CI as

CIt=[a1,b1]. CI_{t^\star} = [a_1,b_1].

Otherwise keep the full accepted-set representation.

Pointwise p-value for no effect:

pt=p^(0). p_{t^\star}=\hat p(0).

Pointwise significance indicator:

ptα \mathbf { p_{t^\star}\le \alpha}

Minimum attainable p-value:

pmin=1T0+1. p_{min}=\frac{1}{T_0+1}.

Pseudocode

code.text

7) Return PanelEstimate

code.text

Very compact math summary

If you want a shorter “formula-only” version for docs, this is the essence:

w^scargminwΔJY1preX0prew22+λscw22 \hat w_{sc} \arg\min_{w\in\Delta_J} |Y_1^{pre}-X_0^{pre}w|_2^2+\lambda_{sc}|w|_2^2 w^augargminwRJY1preX0prew22+λaugww^sc22 \hat w_{aug} \arg\min_{w\in\mathbb R^J} |Y_1^{pre}-X_0^{pre}w|_2^2+\lambda_{aug}|w-\hat w_{sc}|_2^2 Y^0all=X0allw^aug,τ^tY1tY^0t,tpost \hat Y_0^{all}=X_0^{all}\hat w_{aug}, \qquad \hat\tau_t Y_{1t}-\hat Y_{0t}, \quad t\in post τ^kgˉpost(k)gˉhold(k),τ^=1Kk=1Kτ^k \hat\tau_k \bar g_{post}^{(k)}-\bar g_{hold}^{(k)}, \qquad \hat\tau=\frac{1}{K}\sum_{k=1}^K \hat\tau_k σ^τ1+KrT11K1k=1K(τ^kτ^)2 \hat\sigma_\tau \sqrt{1+\frac{Kr}{T_1}} \sqrt{\frac{1}{K-1}\sum_{k=1}^K(\hat\tau_k-\hat\tau)^2} t=K,τ^σ^τ,CI1ατ^±t1α/2,K1σ^τK t=\frac{\sqrt K,\hat\tau}{\hat\sigma_\tau}, \qquad CI_{1-\alpha} \hat\tau\pm t_{1-\alpha/2,K-1}\frac{\hat\sigma_\tau}{\sqrt K} u(θ)=Y1(θ)X0w^aug(θ),p^(θ)1T0+1m=1T0+11S(πmu(θ))S(u(θ)) u^{(\theta)}=Y_1^{(\theta)}-X_0\hat w_{aug}^{(\theta)}, \qquad \hat p(\theta) \frac{1}{T_0+1} \sum_{m=1}^{T_0+1} \mathbf 1{S(\pi_m u^{(\theta)})\ge S(u^{(\theta)})} CIt=θ:p^t(θ)>α,pt=p^t(0) CI_t = {\theta:\hat p_t(\theta)>\alpha}, \qquad p_t=\hat p_t(0)

References

  • [AG2003] Abadie, A., and Gardeazabal, J. (2003). The Economic Costs of Conflict: A Case Study of the Basque Country. American Economic Review, 93(1), 113–132. (American Economic Association)

  • [ADH2010] Abadie, A., Diamond, A., and Hainmueller, J. (2010). Synthetic Control Methods for Comparative Case Studies: Estimating the Effect of California’s Tobacco Control Program. Journal of the American Statistical Association, 105(490), 493–505. (JSTOR)

  • [ADH2015] Abadie, A., Diamond, A., and Hainmueller, J. (2015). Comparative Politics and the Synthetic Control Method. American Journal of Political Science, 59(2), 495–510. (MIT Economics)

  • [Abadie2021] Abadie, A. (2021). Using Synthetic Controls: Feasibility, Data Requirements, and Methodological Aspects. Journal of Economic Literature, 59(2), 391–425. (NBER)

  • [DI2016] Doudchenko, N., and Imbens, G. W. (2016). Balancing, Regression, Difference-in-Differences and Synthetic Control Methods: A Synthesis. NBER Working Paper 22791 / arXiv:1610.07748. (NBER)

  • [BFR2021] Ben-Michael, E., Feller, A., and Rothstein, J. (2021). The Augmented Synthetic Control Method. Journal of the American Statistical Association, 116(536), 1789–1803. (NBER)

  • [CWZ2021] Chernozhukov, V., Wüthrich, K., and Zhu, Y. (2021). An Exact and Robust Conformal Inference Method for Counterfactual and Synthetic Controls. Journal of the American Statistical Association, 116(536), 1849–1864. (OUP Academic)

  • [CWZ-T] Chernozhukov, V., Wüthrich, K., and Zhu, Y. A t-test for synthetic controls / Debiasing and t-tests for synthetic control inference on average causal effects. arXiv:1812.10820. (arXiv)