6 Generalized synthetic control
- GSC estimates factors from never-treated controls, then uses each treated unit’s pretreatment outcomes to estimate its loadings. In fect, set
method = "gsynth". - Use GSC for block or staggered adoption without treatment reversal, including panels with few treated units.
- Follow the five checks in Section 6.2: count the data; check overlap; choose the rank forward from treated units; use out-of-sample inference; report the choices.
- Rolling CV remains the default of
CV = TRUE, but for GSC it scores control cells and can miss a factor on which treated and control units differ. Choose the rank with the forward rule (Step 3). - Bounded factor loadings (
loading.bound = "simplex") are experimental and not recommended for reported results. They do not replace the overlap checks. - Basic estimation comes first. Cross-validation options, plots, staggered adoption, unbalanced panels, bounded loadings, and inference follow the five checks.
The standalone gsynth package is a wrapper of fect. Use its old syntax if needed.
GSC is the generalized synthetic control method proposed in Xu (2017) [Paper]. Download the R script for this chapter here.
GSC differs from the other estimators in fect in its treatment setting, factor estimation, and inference:
- GSC handles block and staggered DID without treatment reversal. FEct, IFEct, and MC also allow reversals under assumptions about carryover effects.
- GSC can be used with few treated units. Its parametric bootstrap uses prediction errors from controls left out of the factor fit.
- GSC estimates time components from never-treated controls. IFE-EM uses all untreated cells, including treated units’ pretreatment observations.
fect(..., method = "gsynth") is equivalent to fect(..., method = "ife", time.component.from = "nevertreated").
Both fit an interactive fixed effects (IFE) model with factors estimated from never-treated controls. Each treated unit’s loadings are then estimated from its own pretreatment outcomes.
Use method = "gsynth" when treatment does not reverse and never-treated controls are available. This includes settings with \(N_{tr} = 1\). Set vartype = "parametric" explicitly to use the parametric bootstrap.
The default IFE-EM regime, time.component.from = "notyettreated", uses EM to estimate time components from all untreated cells. It accommodates treatment reversal (Chapter 2).
The examples use sim_gsynth for block adoption and turnout for staggered adoption.
6.1 Basic usage
The simulated example shows the data structure, estimation arguments, and returned estimates.
6.1.1 Simulated data
sim_gsynth is the simulated dataset described in Xu (2017). It has 5 treated units, 45 control units, and 30 time periods. Treatment starts in Period 21 for every treated unit, giving a block DID design.
head(sim_gsynth)
#> id time Y D X1 X2 eff error mu alpha
#> 1 101 1 6.210998 0 0.3776736 -0.1732470 0 0.2982276 5 -0.06052364
#> 2 101 2 4.027106 0 1.7332009 -0.4945009 0 0.6365697 5 -0.06052364
#> 3 101 3 8.877187 0 1.8580159 0.4984432 0 -0.4837806 5 -0.06052364
#> 4 101 4 11.515346 0 1.3943369 1.1272713 0 0.5168620 5 -0.06052364
#> 5 101 5 5.971526 0 2.3636963 -0.1535215 0 0.3689645 5 -0.06052364
#> 6 101 6 8.237905 0 0.5370867 0.8774397 0 -0.2153805 5 -0.06052364
#> xi F1 L1 F2 L2
#> 1 1.1313372 0.25331851 -0.04303273 0.005764186 -0.8804667
#> 2 -1.4606401 -0.02854676 -0.04303273 0.385280401 -0.8804667
#> 3 0.7399475 -0.04287046 -0.04303273 -0.370660032 -0.8804667
#> 4 1.9091036 1.36860228 -0.04303273 0.644376549 -0.8804667
#> 5 -1.4438932 -0.22577099 -0.04303273 -0.220486562 -0.8804667
#> 6 0.7017843 1.51647060 -0.04303273 0.331781964 -0.8804667Use panelView to inspect treatment timing and missing observations. The plot shows that (1) there are 5 treated units and 45 controls; (2) treatment starts in period 21; and (3) there are no missing values.
library(panelView)
#> ## See https://yiqingxu.org/packages/panelview/ for more info.
#> ## Report bugs -> yiqingxu@stanford.edu.
#>
#> Attaching package: 'panelView'
#> The following object is masked from 'package:fect':
#>
#> simdata
panelview(Y ~ D, data = sim_gsynth, index = c("id","time"), pre.post = TRUE) The outcome plot colors each path by treatment status.
6.1.2 Estimation
The outcome is \(Y\), the treatment indicator is \(D\), and the covariates are \(X_1\) and \(X_2\). The unit and time identifiers are \(id\) and \(time\).
Set method = "gsynth" to fit GSC. This first call illustrates the default CV interface. For the recommended rank choice, use the forward rule in Section 6.2.
system.time(
out <- fect(Y ~ D + X1 + X2, data = sim_gsynth, index = c("id","time"),
method = "gsynth", force = "two-way", CV = TRUE, r = c(0, 5),
se = TRUE, nboots = 1000, vartype = 'parametric',
parallel = TRUE, cores = 16))
#>
#> +----------------------------------------------------------+
#> | Parallel computing: using 16 of 14 available cores. |
#> | |
#> | To change: set cores = <n> in fect(). |
#> | Default: min(available - 2, 8). |
#> +----------------------------------------------------------+
#> Cross-validating ...
#> Criterion: Mean Squared Prediction Error
#> Interactive fixed effects model...
#> Cross-validating ...
#> r = 0; sigma2 = 1.84865; IC = 1.02023; PC = 1.74458; MSPE = 2.33679
#> r = 1; sigma2 = 1.51541; IC = 1.20588; PC = 1.99818; MSPE = 2.12486
#> r = 2; sigma2 = 0.99737; IC = 1.16130; PC = 1.69046; MSPE = 1.44221
#> *
#> r = 3; sigma2 = 0.94664; IC = 1.47216; PC = 1.96215; MSPE = 2.94174
#> r = 4; sigma2 = 0.89411; IC = 1.76745; PC = 2.19241; MSPE = 4.51367
#> r = 5; sigma2 = 0.85060; IC = 2.05928; PC = 2.40964; MSPE = 6.43875
#>
#> r* = 2
#>
#> Parametric Bootstrap (para.error = "empirical")
#>
Simulating errors ...
#> Can't calculate the F statistic because of insufficient treated units.
#> user system elapsed
#> 73.483 6.645 95.195The first variable on the right-hand side is the binary treatment indicator. The remaining variables are covariates. index identifies the unit and time columns.
force selects the additive fixed effects: "none", "unit", "time", or "two-way". The default, "two-way", includes unit and time effects.
With CV = TRUE, r=c(0,5) sets the candidate rank range. With CV = FALSE, the first element of r fixes the rank. A scalar also works, such as \(r = 0\).
Set se = TRUE to estimate uncertainty. With few treated units, use vartype = "parametric" subject to the cautions in the five checks. Conformal intervals (vartype = "conformal") offer a finite-sample guarantee under their exchangeability and tuning conditions; see Chapter 8. The default number of parametric bootstrap runs is 200. Change it with nboots.
The printed output includes sigma2, the estimated error variance; IC, an information criterion; and MSPE, the mean squared prediction error. By default (cv.rule = "min"), CV selects the rank with the smallest MSPE. cv.rule = "1se" selects the smallest rank within one standard error of it.
The following fields report three commonly requested results:
-
est.att: average treatment effect on the treated (ATT) by event time. -
est.avg: ATT averaged over treated post-treatment observations. -
beta: coefficients of the time-varying covariates.
print(out)
out$est.att
out$est.avg
out$betaatt.boot stores the bootstrap ATT estimates, with one row per event time and one column per run. With keep.sims = TRUE, eff.boot also stores cell-level draws (time periods * units * bootstrap runs).
Use cores to set the number of parallel workers for CV and uncertainty estimation. If cores is omitted or NULL, fect selects the smaller of 8 and the number of usable system cores minus 2.
6.2 Five checks for a GSC analysis
Iwasaki and Xu (2026) reanalyze published applications of GSC and IFE-EM and recommend five steps, in order: count the data, check overlap before choosing the rank, choose the rank forward from the treated units, use out-of-sample inference, and report what was done. Version 2.5.0 of fect runs each step. This section walks through them on sim_gsynth.
6.2.1 Step 1: count the data
GSC predicts a treated unit’s untreated outcome from the factors of the never-treated units and the unit’s own pretreatment periods, so count both. sim_gsynth has 45 never-treated units and 5 treated units, each with 20 pretreatment periods. The rank rule of Step 3 needs about 15 pretreatment periods when the candidate ranks go up to 5. With fewer, report the ranks that both rules of Step 3 pick (forward and leave one out), and treat a finding that holds at some ranks and not at others as fragile. fect_rank() reports whether the window is long enough (see Step 3).
6.2.2 Step 2: check overlap before choosing the rank
A factor model can only predict a treated unit well if the controls can represent it. overlap_check() asks this of the raw data, before any model is fitted. For each treated unit, it takes the unit’s pretreatment periods, subtracts from the treated unit’s path and from each never-treated unit’s path its mean over those periods, rebuilds the treated unit’s path as a weighted average of the never-treated units’ paths (weights that are non-negative and sum to one), and records the root mean squared error. The yardstick is the same error for each never-treated unit rebuilt from the others. A treated unit is flagged when its error is larger than the donors’ 90th percentile.
oc <- overlap_check(Y ~ D, data = sim_gsynth, index = c("id", "time"), level = 0.90)
oc
#> Overlap check without a rank (level 0.9)
#> Treated units: 5; never-treated donors: 45
#> Assessable: 5 of 5 (100% of the effect's weight)
#> Flagged: 1 (20% of the effect's weight)
#>
#> Flagged units:
#> unit onset weight error yardstick pct
#> 105 21 0.2 3.77 3.48 0.933
#>
#> Cohorts: 1 of 1 assessable, 0 flaggedOne of the five treated units, unit 105, is rebuilt worse than 93% of the donors and is flagged. The table oc$units gives each unit’s error, its percentile (pct) and its weight in the average effect. The check needs no rank and no factor model, so the choice of the rank cannot change it. It is a screen rather than a test. A treated unit is rebuilt from all the donors, while each donor is rebuilt from the others, so the treated unit’s error tends to be smaller, and a unit slightly outside what the donors can reproduce may pass. Like every pretreatment check, it cannot detect a factor that does not vary before treatment starts. plot(oc) draws each treated unit’s gap, its demeaned pretreatment outcome minus its rebuild, in each period before adoption.
plot(oc)The grey lines are the donors’ gaps, each donor rebuilt from the others, and the shaded region holds 90% of them in each period. A unit the donors can follow has a gap that stays mostly inside the region and crosses zero at random. A gap that leaves the region often, or that trends or stays on one side of zero near adoption, belongs to a unit the donors cannot follow. Unit 105’s gap leaves the region in 6 of its 20 periods, against 1 to 3 for the other units, and its region is pink because it is flagged. plot(oc, type = "percentile") draws one row per unit, which suits panels with many treated units.
6.2.3 Step 3: choose the rank forward from the treated units
fect_rank() fits GSC at every candidate rank and scores each rank by how well it predicts the treated units’ own pretreatment outcomes. The forward rule refits each treated unit’s loadings on its first pretreatment periods and predicts the next one, moving the cutoff forward one period at a time, so every prediction uses only earlier periods, as the post-treatment prediction does. The leave-one-out rule of Xu (2017) also trains on later periods, which under serially correlated errors carry information about the held-out one, so it leans toward more factors. The chosen rank is the smallest minimizer of the forward score. The table also gives the estimate at every rank and the share of the treated units’ predicted post-treatment outcomes that lie outside the range of all observed outcomes in the panel (extrapolation).
rk <- fect_rank(Y ~ D + X1 + X2, data = sim_gsynth, index = c("id", "time"),
force = "two-way", r = 0:5)
rk
#> Rank choice from the treated units' pretreatment outcomes
#> Forward rule: r = 2; leave one out: r = 2
#> forward: ranks 0-5, scores 5 of 5 treated units (100% of the effect's weight); leave one out: ranks 0-5, 5 (100%)
#> Forward window: long enough (units with at least 8 forward predictions at the largest rank carry 100% of the weight; median pretreatment periods 20)
#>
#> r fwd loo ATT S.E. CI.lower CI.upper p.value n.tr extrapolation
#> 0 2.315 2.373 5.084 NA NA NA NA 5 0
#> 1 1.713 1.717 5.569 NA NA NA NA 5 0
#> 2 1.511 1.145 5.543 NA NA NA NA 5 0
#> 3 1.574 1.150 5.741 NA NA NA NA 5 0
#> 4 1.662 1.214 5.810 NA NA NA NA 5 0
#> 5 1.845 1.238 5.753 NA NA NA NA 5 0The forward rule picks 2 factors, the number in the simulation, and so does the leave-one-out rule. Report the estimate at every candidate rank and mark the one the rule chose. Here it moves between 5.54 and 5.81 from r = 1 on, a range of about one standard error (0.26 in the output below). To fit at the forward rule’s rank in one call, set cv.method = "forward":
out.fwd <- fect(Y ~ D + X1 + X2, data = sim_gsynth, index = c("id", "time"),
method = "gsynth", force = "two-way", CV = TRUE, r = c(0, 5),
cv.method = "forward", se = TRUE, vartype = "parametric",
nboots = 500, seed = 1234, parallel = TRUE, cores = 16)
#> Forward rule: r = 2 (forward: ranks 0-5, scores 5 of 5 treated units (100% of the effect's weight); leave one out: ranks 0-5, 5 (100%))
#>
#> +----------------------------------------------------------+
#> | Parallel computing: using 16 of 14 available cores. |
#> | |
#> | To change: set cores = <n> in fect(). |
#> | Default: min(available - 2, 8). |
#> +----------------------------------------------------------+
#> Parametric Bootstrap (para.error = "empirical")
#>
Simulating errors ...
#> Can't calculate the F statistic because of insufficient treated units.
out.fwd$r.cv
#> [1] 2
out.fwd$est.avg
#> ATT.avg S.E. CI.lower CI.upper p.value
#> [1,] 5.54329 0.2565507 5.04046 6.04612 0At the chosen rank, loading_check() checks overlap in the factor model itself. It asks whether each treated unit’s estimated loading lies inside the region the controls’ loadings enclose (their convex hull). For a unit outside the hull, it measures the distance to the hull relative to the sampling variance of the unit’s own loading estimate, and flags the unit when that distance exceeds the 95th percentile of a chi-square distribution with r degrees of freedom. With trim = TRUE it drops the flagged units, chooses the rank again on the units kept and refits. Report the trimmed estimate beside the full one. It is the effect for the treated units the controls can represent, a different estimand.
lc <- loading_check(out.fwd, trim = TRUE)
lc
#> Loading check at r = 2 (chi-square level 0.95, cutoff 5.99)
#> Treated units: 5; inside the controls' hull: 2; flagged: 0
#> Extrapolation: 0.0% of treated post-treatment counterfactuals outside the observed outcome range
#>
#> Trimmed: no treated unit significantly outside the hullThree of the five treated units, unit 105 among them, lie outside the hull, but each by less than the noise in its loadings allows (lc$table). None is flagged, so there is nothing to trim. Step 2 flags unit 105 and this check does not, because the two checks ask different questions, and each can flag a unit the other passes. plot(lc) draws the loadings.
plot(lc)6.2.4 Step 4: use out-of-sample inference
With few treated units, use the parametric bootstrap (vartype = "parametric", Algorithm 2 of Xu (2017), as in out.fwd above). It simulates each treated unit’s prediction error with the prediction errors of controls left out of the factor fit. Use it with caution when the controls are few relative to the treated units or to the rank. The interval at the chosen rank does not account for the choice of the rank. Conformal intervals are a second option, with a finite-sample guarantee under their own conditions (Section 6.9.1).
For IFE-EM (method = "ife", factors from all untreated cells), Algorithm 2 does not apply, because the factors depend on the treated units’ own pretreatment errors, and vartype = "parametric" stops with an error. With few treated units, use GSC with Algorithm 2, or conformal intervals, which also work with IFE-EM (Section 6.9.1). The unit bootstrap and the jackknife rely on variation across treated units and do not solve the problem when there are few.
6.2.5 Step 5: report
Report the rank and how it was chosen (here, the forward rule over ranks 0 to 5), whether a printed estimate is an average or a single period, the version of fect, the stopping rule (tol, max.iteration) and the seed, and post the data and code.
6.3 Cross-validation
cv.method = "rolling" is the default for DID/TWFE CV, GSC CV, and fect_mspe(). "block" is also available. For GSC rank selection, the five checks recommend "forward" instead.
fect_cv (DID/TWFE) |
CV in GSC |
fect_mspe (post-hoc) |
|
|---|---|---|---|
"rolling" |
Default | Default | Default |
"block" |
Available | Available | Available |
"loo" |
— | Available | — |
"forward" |
— | Available (v2.5.0) | — |
The methods differ in what they predict and which periods they use:
-
"rolling"holds out blocks and drops later eligible periods from each sampled unit’s training data. -
"block"holds out blocks while retaining eligible periods on both sides. -
"loo"predicts each treated unit’s pretreatment outcomes from its other pretreatment periods. -
"forward"predicts each treated unit’s pretreatment outcomes from earlier periods only. It does not mask cells in the control factor fit.
"loo" and "forward" require time.component.from = "nevertreated". Their factor estimates must exclude the held-out treated observations. For GSC, rolling and block CV score control cells. A factor that matters more for treated units can receive little weight in those scores. Changing the window does not resolve that problem (Iwasaki and Xu 2026). Use fect_rank() and the forward rule in Section 6.2.
The legacy values "all_units" (now "block") and "treated_units" (block masking restricted to treated pretreatment cells) remain accepted and print a note. Use "block" in place of "all_units". See the cheatsheet.
The following call shows the rolling-window option. Its selected rank is an alternative to compare with the treated-unit rules. See Chapter 4 for the rolling design and the side-by-side figure.
fit <- fect(Y ~ D + X1 + X2, data = sim_gsynth, index = c("id", "time"),
method = "gsynth", force = "two-way",
CV = TRUE, r = c(0, 5),
cv.method = "rolling",
cv.buffer = 1, cv.nobs = 3, k = 20, cv.prop = 0.1,
cv.rule = "1se",
se = TRUE, vartype = "parametric")
fit$r.cv # selected r --- use this for downstream inferenceRolling and block CV score the model’s full prediction for both method = "ife" and method = "gsynth". That prediction includes the intercept, unit and time effects, covariates, and factors. The estimators differ in which observations supply their time components. See the Cross-Validation section of the cheatsheet for the parameter reference.
6.4 Plot reference
The plots below use out, the initial fit with default rolling CV. They illustrate plot options. The five-check analysis uses out.fwd.
6.4.1 Gap plots
plot(out) reports ATT by event time. The true effects in sim_gsynth range from 1 to 10, with added white noise, during periods 21 to 30.
plot() returns a ggplot2 object. print() displays it, and ggsave() saves it.
connected = TRUE draws the confidence interval as a shaded area.
plot(out, connected = TRUE)show.points = FALSE removes the points.
plot(out, connected = TRUE, show.points = FALSE)Use main for the title, xlab and ylab for axis labels, and xlim and ylim for axis limits. Standard ggplot2 styling also applies.
6.4.2 Plot types
The eight plot types used here are:
-
"gap": ATT by event time (the default). -
"counterfactual": average observed treated outcomes and estimated untreated outcomes. -
"factors": estimated factors. -
"loadings": estimated factor loadings. -
"status": treatment and observation status.axis.labselects labels. With 200 or more units, unit labels are dropped. -
"box": distributions of estimated unit-level gaps. -
"calendar": ATT by calendar time. -
"equiv": average pretreatment residuals with equivalence confidence intervals.
For method = "gsynth" with vartype = "parametric", the counterfactual plot’s 95% intervals have the same widths as the ATT intervals, reflected around the observed outcomes.
plot(out, type = "counterfactual")raw = "all" adds each treated and control unit’s observed outcome path.
plot(out, type = "counterfactual", raw = "all")raw = "band" adds the 5th to 95th percentiles of observed treated and control outcomes in each period. The bands describe the raw outcomes. They are not confidence intervals.
plot(out, type = "counterfactual", raw = "band")"status" shows treatment status. Use xticklabels and yticklabels to select labels, such as xticklabels=c("1","5","10", "15","20", "25", "30"). A nonexistent value, such as yticklabels="0", removes numeric labels on that axis. panelView provides a standalone version.
"loadings" and "factors" display the fitted factor model.
plot(out, type = "loadings")plot(out, type = "factors", xlab = "Time")"box" shows the dispersion of estimated unit-level gaps. These gaps include prediction error and do not by themselves identify individual treatment effects. With few treated units, the display becomes a scatter plot. The graph labels the number of treated units; xangle and yangle tilt axis labels.
xlim restricts the display, here to fifteen periods before treatment and ten after.
"calendar" shows ATT by calendar time. The blue lowess curve has a shaded 95% confidence band, and the red dashed line marks the overall average ATT.
plot(out,type = "calendar")6.5 Staggered DID
The turnout example examines Election-Day Registration (EDR) reforms in the United States. Treatment starts in different periods across states. See Xu (2017) Section 5 for the dataset.
6.5.1 Data structure
The panelView plot shows that (1) the panel is balanced with 9 treated units and (2) treatment starts in different periods.
The outcome plot colors paths by treatment status.
6.5.2 Estimation without factors
Without factors, the ATT estimates are close to the difference-in-differences estimates.
out0 <- fect(turnout ~ policy_edr + policy_mail_in + policy_motor,
data = turnout, index = c("abb","year"),
se = TRUE, method = "gsynth",
r = 0, CV = FALSE, force = "two-way",
nboots = 1000, seed = 02139)
#>
#> +----------------------------------------------------------+
#> | Parallel computing: using 8 of 14 available cores. |
#> | |
#> | To change: set cores = <n> in fect(). |
#> | Default: min(available - 2, 8). |
#> +----------------------------------------------------------+
#> Can't calculate the F statistic because of insufficient treated units.6.5.3 Estimation with factors
This call retains the default CV specification for comparison. For a GSC analysis, use fect_rank() to compare ranks and choose forward from the treated units, as in Section 6.2.
Set keep.sims = TRUE to retain the draws needed for counterfactual intervals for subsets of treated units.
out_turnout <- fect(turnout ~ policy_edr + policy_mail_in + policy_motor,
data = turnout, index = c("abb","year"),
se = TRUE, method = "gsynth", vartype = "parametric",
r = c(0, 5), CV = TRUE, force = "two-way",
nboots = 1000, seed = 02139, keep.sims = TRUE)
#>
#> +----------------------------------------------------------+
#> | Parallel computing: using 8 of 14 available cores. |
#> | |
#> | To change: set cores = <n> in fect(). |
#> | Default: min(available - 2, 8). |
#> +----------------------------------------------------------+
#> Cross-validating ...
#> Criterion: Mean Squared Prediction Error
#> Interactive fixed effects model...
#> Cross-validating ...
#> r = 0; sigma2 = 77.99366; IC = 4.82744; PC = 72.60594; MSPE = 162.37836
#> r = 1; sigma2 = 13.65239; IC = 3.52566; PC = 21.67581; MSPE = 27.01241
#> r = 2; sigma2 = 8.56312; IC = 3.48518; PC = 19.23841; MSPE = 21.51608
#> *
#> r = 3; sigma2 = 6.40268; IC = 3.60547; PC = 18.61783; MSPE = 32.92659
#> r = 4; sigma2 = 4.74273; IC = 3.70145; PC = 16.93707; MSPE = 27.86608
#> r = 5; sigma2 = 4.02488; IC = 3.91847; PC = 17.05226; MSPE = 51.99269
#>
#> r* = 2
#>
#> Parametric Bootstrap (para.error = "empirical")
#>
Simulating errors ...
#> Can't calculate the F statistic because of insufficient treated units.6.5.4 Implied weights
wgt.implied stores an \(N_{co}\times N_{tr}\) matrix, with one row per control unit and one column per treated unit. Unit IDs label the rows and columns. Column \(i\) holds weights that rebuild the factor part of treated unit \(i\)’s counterfactual:
\[ \Lambda_{co}^\top w_i = \lambda_i,\qquad w_i = \Lambda_{co}(\Lambda_{co}^\top\Lambda_{co})^{-1}\lambda_i. \]
These weights can be positive or negative (Xu 2017). With time fixed effects, each column sums to zero. They represent the factor component, rather than synthetic-control weights for the full outcome. The following output shows Wisconsin’s weights.
dim(out_turnout$wgt.implied)
#> [1] 38 9
sort(out_turnout$wgt.implied[, "WI"])
#> KY AL VA NM MD NC
#> -0.078149896 -0.052473777 -0.044024879 -0.042160158 -0.040763881 -0.039980955
#> MS SC FL DE MO GA
#> -0.035282643 -0.022996157 -0.022764544 -0.020468346 -0.019809351 -0.016407696
#> TN AZ NV OH IN AR
#> -0.015706586 -0.013740106 -0.006777864 -0.004803724 -0.004161985 -0.003344846
#> TX CO LA KS OR IL
#> 0.004111036 0.005609900 0.005732374 0.006425572 0.006450031 0.008133593
#> WV NE VT MI WA OK
#> 0.009500662 0.009902250 0.011309988 0.020489796 0.028841328 0.028852809
#> SD UT NJ PA CA RI
#> 0.029809136 0.031680004 0.035735523 0.041853564 0.044591927 0.047392982
#> NY MA
#> 0.047806688 0.0595882346.5.5 Plot reference
The gap plot reports ATT by event time.
The status plot shows staggered adoption. xlab, ylab, and main set labels, and xangle and yangle set their tilt in degrees.
The counterfactual plot compares observed and estimated untreated outcomes.
plot(out_turnout, type = "counterfactual")id selects a state or a vector of states. Subset counterfactual intervals require keep.sims = TRUE and vartype = "parametric" in this example.
plot(out_turnout, type = "counterfactual", id = "WI", main = "Wisconsin")With few treated units, the box plot becomes a scatter plot.
The calendar plot reports ATT by calendar time.
The factor and loading plots describe the fitted factor model.
plot(out_turnout, type = "factors", xlab = "Year")plot(out_turnout, type = "loadings")6.5.6 Cumulative effects
For staggered adoption without reversals, cumulative ATT sums the per-period ATTs from event time 1 to \(k\). Use it when the sum answers the substantive question, such as accumulated voter mobilization. out_turnout retains the cell-level replicates needed by estimand() because it uses keep.sims = TRUE and vartype = "parametric".
cumu.turnout <- estimand(out_turnout, "att.cumu", "event.time")
esplot(cumu.turnout, Period = "event.time",
Estimate = "estimate", CI.lower = "ci.lo", CI.upper = "ci.hi",
Count = "n_cells",
main = "Cumulative Effect of EDR Reform on Turnout",
ylab = "Cumulative ATT")See Chapter 3 (Alternative Estimands) for estimand(), including parametric variance, log-scale ATT, and APTT.
6.6 Unbalanced panels
GSC in fect accommodates unbalanced panels. This example removes 50 observations at random and the first 15 observations of Wyoming, then refits the model.
White cells in the panelView plot mark missing observations.
6.6.1 Estimation
The first fit uses the default unit bootstrap. It is retained to compare with the explicit parametric-bootstrap fit below. Both calls use default CV. In an analysis, apply the five checks before choosing a rank.
6.6.2 Parametric bootstrap on an unbalanced panel
With few treated units, the five checks recommend the GSC parametric bootstrap, subject to the cautions in Step 4. Set vartype = "parametric" explicitly. It is also available when outcomes are missing.
On a balanced panel, the default parametric-bootstrap path resamples whole-\(T\) error vectors. With missing outcomes (para.error = "ar", the default there), fect uses Gaussian draws based on pairwise-available residual second moments. It retains off-diagonal terms to represent within-unit serial dependence. These are estimated second moments; the draws need not reproduce the full error distribution.
The parametric bootstrap targets uncertainty conditional on the factors, loadings, covariates, and treatment indicators, \((\Lambda, F, X, D)\). The unit bootstrap resamples unit identities and reflects variation in sample composition. Their standard errors need not coincide. See Chapter 7 for its mechanics.
Compare the average widths of the period-specific ATT intervals. Similar widths would not establish that either procedure has correct coverage.
ci_width <- function(out) mean(out$est.att[, "CI.upper"] -
out$est.att[, "CI.lower"], na.rm = TRUE)
data.frame(
vartype = c("bootstrap", "parametric"),
CI_width = c(ci_width(out_ub), ci_width(out_ub_param))
)
#> vartype CI_width
#> 1 bootstrap 5.682597
#> 2 parametric 8.1623856.6.3 Plot reference
The fitted status plot marks Wyoming in gray because it has too few pretreatment observations and is excluded.
out_ub$obs.missing records observation status: 1 for treated observations, 2 for untreated observations, 3 for missing observations, and 4 for excluded units. Fits with placebo or carryover tests also use 5 for masked test observations and 6 for observations removed by carryover.rm.
Use id to select units and the axis options to adjust the display.
The unit-bootstrap gap plot uses a y-axis range of \((-10,15)\).
The next plot uses the parametric bootstrap on the same unbalanced panel.
6.7 Bounded factor loadings (experimental)
loading.bound = "simplex" is experimental, and we do not recommend it for reported results. Keep the default, loading.bound = "none". In simulations with a decision rule fixed in advance, the bound did better than unbounded GSC in none of the seven designs tested. The per-unit bound may be deprecated in a later release.
loading.bound = "simplex" restricts each treated unit’s factor loading to a non-negative weighted average of the controls’ loadings. An entropy penalty pulls the weights toward equal weights, and cross-validation sets its strength (gamma.loading, or a grid in gamma.loading.grid). The bound changes the estimator but does not create overlap. When a treated unit’s loading lies outside the controls’, the bound replaces the extrapolation with a counterfactual from inside their range, and if the factor model holds outside that range, the bounded estimate is biased.
The simulations used four panels with 500 replications each and a true effect of zero, at the true rank. With overlap, the bound’s false-positive rate was 13%, against 5% for unbounded GSC. Without overlap, including designs in which the untreated outcome bends outside the controls’ range, it was 78% to 94%, against 4% to 7%. Its RMSE was lower only with 5 pretreatment periods (0.95 against 1.08), and there its false-positive rate was 13% against 5%. To find out whether the controls can represent the treated units, use the overlap checks in Section 6.2.
The call is shown for completeness and is not run here.
out.bounded <- fect(Y ~ D, data = sim_gsynth, index = c("id", "time"),
method = "gsynth", r = 2, loading.bound = "simplex",
se = TRUE, vartype = "parametric")
out.bounded$gamma.loading # penalty chosen by cross-validation
out.bounded$loading.proj.resid # pretreatment fit under the bound
out.bounded$wgt.implied # implied donor weights, one column per treated unit6.7.1 Notes
- The bound is available for
method = "gsynth", or equivalentlymethod = "ife"withtime.component.from = "nevertreated". - The unit intercept is not bounded. Since version 2.4.8, with
force = "unit"or"two-way", it is fitted jointly with the weights. - Percentile-bootstrap intervals may under-cover when the bound binds. Boundary-corrected inference is not implemented.
- Before version 2.4.7, the bound was dropped without a message in CV, fits without standard errors, parametric-bootstrap replicates and
loo = TRUErefits. - Before version 2.4.8, the loadings were fitted without an intercept, which was then set to the residual mean, so under
"unit"or"two-way"the treated outcome’s level could change the loadings, the ATT and the selectedgamma.loading. Onsim_gsynthwith two factors, the bounded ATT was 5.10 before version 2.4.8 and is 4.33 now.
6.8 CFE with never-treated controls
The complex fixed effects (CFE) estimator also supports time.component.from = "nevertreated". It can add fixed effects, unit-specific trends through Q.type, or time-invariant covariates with time-varying coefficients through Z and gamma. See Chapter 5 for the CFE tutorial.
6.8.1 Estimation
Set method = "cfe" and time.component.from = "nevertreated". This example also includes unit-specific linear trends.
With time.component.from = "nevertreated", CFE estimates factors from never-treated controls, as GSC does. It fits the additional CFE components on the control panel and projects them onto treated units. See Chapter 5.
6.8.2 Comparing GSC and CFE
The following comparison holds the estimation regime fixed and varies the model components. fect_mspe() reports prediction scores. It does not replace the treated-unit rank rule of Step 3.
# Model 1: gsynth (pure IFE, r = 2)
out.gsynth.comp <- fect(Y ~ D + X1 + X2, data = sim_gsynth, index = c("id","time"),
method = "gsynth", force = "two-way",
r = 2, se = FALSE, CV = FALSE, max.iteration = 20000)
# Model 2: CFE + nevertreated with r = 2 only (equivalent to gsynth)
out.cfe.nt.comp <- fect(Y ~ D + X1 + X2, data = sim_gsynth, index = c("id","time"),
method = "cfe", force = "two-way",
time.component.from = "nevertreated",
r = 2, se = FALSE, CV = FALSE, max.iteration = 20000)
# Model 3: CFE + nevertreated with r = 2 and linear trend (overspecified)
out.cfe.nt.lin <- fect(Y ~ D + X1 + X2, data = sim_gsynth, index = c("id","time"),
method = "cfe", force = "two-way",
time.component.from = "nevertreated",
Q.type = "linear", r = 2, se = FALSE, CV = FALSE,
max.iteration = 20000)mspe.comp <- fect_mspe(list(gsynth_r2 = out.gsynth.comp,
CFE_r2 = out.cfe.nt.comp,
CFE_linear_r2 = out.cfe.nt.lin), seed = 1234)
print(mspe.comp$summary[, c("Model", "MSPE", "RMSE", "MAD")])
#> Model MSPE RMSE MAD
#> 1 CFE_linear_r2 3.267006 1.807486 0.7985979
#> 2 CFE_r2 1.912028 1.382761 0.5413321
#> 3 gsynth_r2 1.937964 1.392108 0.5382881sim_gsynth follows an IFE data generating process with two factors. Models 1 and 2 fit that model using never-treated controls. Their MSPEs are 1.94 and 1.91, and their MADs are 0.538 and 0.541. Different iterative algorithms stop at slightly different solutions. On the full data, their ATTs agree to four decimals (5.5433).
Model 3 adds unit-specific linear trends absent from the data generating process. Its MSPE is 3.27, about 1.7 times that of Model 2. Rolling CV fits each held-out unit’s trend using earlier periods and extrapolates it. Here the extra parameters increase prediction error.
fect_mspe() scores the full prediction: the intercept, unit and time effects, covariates, factors, and additional CFE terms. Before version 2.4.7, it scored these never-treated fits using only the factor component for GSC or 0 for CFE. Both CFE models then scored 110.33 regardless of specification.
6.9 Inference
The default vartype is "bootstrap" for every method, including method = "gsynth". Set vartype = "parametric" explicitly for GSC with few treated units. Its two-stage procedure targets the conditional prediction-error variance
\[ V_t = \mathrm{Var}(\widehat{\mathrm{ATT}}_t - \mathrm{ATT}_t \mid \Lambda, F, X, D). \]
It uses prediction errors from controls left out of the factor fit. Its limitations, including few controls and uncertainty from rank selection, are described in Step 4 of Section 6.2.
For the GSC parametric bootstrap, para.error, introduced in v2.4.2, selects the error resampling path. "auto" uses "empirical" on fully observed panels and "ar" when outcomes are missing. The other options are "ar", the v2.4.1 behavior, "empirical", and "wild". See Chapter 7 for the interaction of vartype, ci.method, and para.error, bootstrap mechanics, and the coverage study.
The jackknife is also available. Like the unit bootstrap, it relies on variation across units and does not solve the inference problem with few treated units.
6.9.1 Conformal intervals
Conformal intervals (vartype = "conformal") are a second way to handle few treated units. The parametric bootstrap simulates each treated unit’s prediction error from a model of the errors. Conformal inference instead treats each never-treated control in turn as if it had been treated at the same date, predicts it in the same way, and compares the treated units’ prediction errors with the controls’ (the Jackknife+ of Liu and Xu (2026)). Under the conditions in Section 8.2.5, each interval covers its effect with probability at least \(1 -\) alpha in finite samples, with no model of the errors. Chapter 8 explains the method. This section shows how it fits the five checks.
The call below uses the rank the forward rule chose in Step 3, held fixed with CV = FALSE. With five treated units, conformal.block = TRUE gives the average effect an interval with a guarantee: it compares the five treated units, taken together, with nine blocks of five controls (Section 8.4.2). The blocks are drawn at random, so set seed. conformal.diag = 10 adds intervals for the last ten periods before treatment, computed as if each treated unit had adopted at that period (Section 8.5.1). The level is 90%: a 95% block interval needs at least 19 blocks, or 95 controls here, and with 45 controls it would be the whole real line.
out.cf <- fect(Y ~ D + X1 + X2, data = sim_gsynth, index = c("id", "time"),
method = "gsynth", force = "two-way", r = 2, CV = FALSE,
se = TRUE, vartype = "conformal", alpha = 0.1,
conformal.block = TRUE, conformal.diag = 10, seed = 1234)
print(out.cf)
#> Call:
#> fect.formula(formula = Y ~ D + X1 + X2, data = sim_gsynth, index = c("id",
#> "time"), force = "two-way", r = 2, CV = FALSE, method = "gsynth",
#> se = TRUE, vartype = "conformal", alpha = 0.1, seed = 1234,
#> conformal.diag = 10, conformal.block = TRUE)
#>
#> Estimator: gsynth
#> Fixed effects: id (unit) + time (time)
#> Inference: conformal, Jackknife+ for full-path estimators (90% level; 45 never-treated controls; no S.E.)
#> Aggregates: block Jackknife+, 9 control blocks of 5 (N = 10, q = 1)
#> Diagnostics: last 10 pre-treatment dates; 1 of 50 unit-date intervals exclude zero
#>
#> ATT:
#> ATT S.E. CI.lower CI.upper p.value
#> Tr obs equally weighted 5.543 NA 5.026 5.983 0.1
#> Tr units equally weighted 5.543 NA 5.026 5.983 0.1
#>
#> Covariates:
#> Coef S.E. CI.lower CI.upper p.value
#> X1 1.021 NA NA NA NA
#> X2 3.052 NA NA NA NAThe block interval for the average effect runs from 5.03 to 5.98. The 90% normal interval from the parametric bootstrap in Step 3 runs from 5.12 to 5.97. The p-value, 0.1, is the smallest possible with nine blocks (\(1/N\) with \(N = 10\)). There are no standard errors. When both intervals are reported and they disagree, the parametric one depends on the model of the errors, and the conformal one on the comparison with the controls.
The two gap plots show the same estimates with 90% intervals, from ten periods before treatment to ten after: the parametric bootstrap on the left and the conformal intervals on the right.
library(gridExtra)
p.pb <- plot(out.fwd, type = "gap", plot.ci = "0.9", xlim = c(-9, 10),
ylim = c(-6.5, 11.5), main = "Parametric bootstrap")
#> Warning in plot.fect(out.fwd, type = "gap", plot.ci = "0.9", xlim = c(-9, : 90% CI in gap plots or exiting treatment plots.
p.cf <- plot(out.cf, type = "gap", xlim = c(-9, 10), ylim = c(-6.5, 11.5),
main = "Conformal (block Jackknife+)")
## drop the plot's note on the blocks and the pre-treatment intervals,
## so that the two panels have the same height
grid.arrange(p.pb, p.cf + ggplot2::labs(caption = NULL), ncol = 2)With nine blocks, each conformal interval is set by the most extreme of the nine blocks’ errors at that date, so its width changes more from period to period than the parametric interval’s. After treatment, it is wider in 6 of the 10 periods, most of all in periods 1, 5 and 8. In period 1 it includes zero, and the parametric interval, just above zero, does not.
Before treatment, the two show different things. The parametric points are the fit’s in-sample residuals, averaged over the treated units. The conformal points are out-of-sample prediction errors: each period’s outcome is predicted from earlier periods and the controls, as if treatment had started then. Both should be near zero. The conformal interval excludes zero in 1 of the 10 pretreatment periods, about what chance gives at alpha = 0.1; a run of such periods would say the treated units were harder to predict than the controls.
Three of the five checks bear on the conformal guarantee.
-
Count the data (Step 1). A finite interval at
alpha = 0.1needs at least nine never-treated controls, and the block interval needs at least nine per treated unit. - Check overlap (Steps 2 and 3). The guarantee needs the treated units to be no harder to predict than the controls. A treated unit that the donors cannot follow, or whose loadings lie far outside the controls’, is the usual way this fails. The overlap checks give evidence on this condition, and so do the pretreatment intervals in the plot.
-
Choose the rank (Step 3). The guarantee assumes a rank fixed in advance. The forward rule chooses the rank from the treated units’ pretreatment outcomes, and Liu and Xu (2026) warn that tuning on the treated units’ fit can break the guarantee. Passing the chosen rank with
CV = FALSEdoes not change this. Report the intervals at nearby ranks as well:
cf.near <- sapply(c(1, 3), function(r) {
fit <- fect(Y ~ D + X1 + X2, data = sim_gsynth, index = c("id", "time"),
method = "gsynth", force = "two-way", r = r, CV = FALSE,
se = TRUE, vartype = "conformal", alpha = 0.1,
conformal.block = TRUE, seed = 1234)
fit$est.avg[1, c("ATT.avg", "CI.lower", "CI.upper")]
})
colnames(cf.near) <- c("r = 1", "r = 3")
round(cf.near, 2)
#> r = 1 r = 3
#> ATT.avg 5.57 5.74
#> CI.lower 4.71 4.99
#> CI.upper 6.63 6.45At one and three factors, the intervals are wider than at two, and all three exclude zero. Conformal intervals are also available for IFE-EM (method = "ife") and matrix completion (method = "mc"), with the same conditions.
6.10 Additional notes
Missing data, covariates, and the pretreatment window affect computation and the information available for estimation.
- Unbalanced panels. Missing control outcomes require iterative imputation and can increase computation time. Inspect the missing-data pattern before fitting. Removing units or periods changes the analysis sample and should be reported. GSC still estimates factors from never-treated controls and uses treated units’ pretreatment outcomes to estimate their loadings.
- Covariates. Covariates add parameters and can increase the work needed for convergence. Choose them for the outcome model and inspect convergence.
-
min.T0. This argument excludes treated units with too few pretreatment observations. For CV, it must be at leastr.max+ 2. A unit that meets it, for example withmin.T0 = 5, can still have too few periods for the rank rule: Step 1 asks for about 15 when the candidate ranks go up to 5, andfect_rank()reports whether the window is long enough.
6.11 How to cite
Cite Xu (2017) for GSC.
@article{Xu2017,
title = {Generalized Synthetic Control Method: Causal Inference with Interactive Fixed Effects Models},
author = {Xu, Yiqing},
journal = {Political Analysis},
volume = {25},
number = {1},
pages = {57--76},
year = {2017}
}