Implements counterfactual estimators in TSCS data analysis and statistical tools to test their identification assumptions.
fect(formula = NULL, data, Y, D, X = NULL, group = NULL,
na.rm = FALSE,
index, force = "two-way", r = 0, lambda = NULL, nlambda = 10,
CV = NULL, k = 10, cv.prop = 0.1, cv.treat = FALSE,
cv.nobs = 3, cv.donut = 0, criterion = "mspe",
binary = FALSE, QR = FALSE,
method = "fe",
se = FALSE, vartype = "bootstrap", nboots = 200, alpha = 0.05,
parallel = TRUE, cores = NULL, tol = 0.001, seed = NULL,
min.T0 = NULL, max.missing = NULL,
proportion = 0.3, pre.periods = NULL,
f.threshold = 0.5, tost.threshold = NULL,
knots = NULL, degree = 2,
sfe = NULL, cfe = NULL,
balance.period = NULL, fill.missing = FALSE,
placeboTest = FALSE, placebo.period = NULL,
carryoverTest = FALSE, carryover.period = NULL, carryover.rm = NULL,
loo = FALSE, permute = FALSE, m = 2, normalize = FALSE)
a T-by-N matrix storing data of the outcome variable.
a T-by-N matrix storing data of the treatment variable.
a T-by-N matrix storing data of the indicator for whether is observed or missing.
name of the outcome variable.
name of the treatment variable.
name of the time-varying control variables.
name of the unit and time indicators.
user specified force
option.
the number of time periods.
the total number of units.
the number of time-varying observables.
the number of factors included in the model -- either supplied by users or automatically chosen via cross-validation.
the optimal hyper-parameter in matrix completion method chosen via cross-validation.
coefficients of time-varying observables from the interactive fixed effect model.
the mean squared error of interactive fixed effect model.
the information criterion.
result of the interactive fixed effect model based on observed values.
mean squared prediction error of the cross-validated model.
result of the cross-validation procedure.
the number of iterations in the estimation of the interactive fixed effect model.
estimated time-varying factors.
estimated loadings.
estimated loadings for treated units.
estimated loadings for control units.
estimated ground mean.
estimated time fixed effects.
estimated unit fixed effects.
estimated unit fixed effects for treated units.
estimated unit fixed effects for control units.
a logic value indicating if multicollinearity exists.
a logic value indicating if factor exists.
a vector of unit IDs.
a vector of time periods.
a matrix stroing status of each unit at each time point.
a T-by-N matrix storing the predicted Y(0).
a T-by-N matrix storing the difference between actual outcome and predicted Y(0).
residuals for observed values.
difference between actual outcome and predicted Y(0) for observations of treated units under control.
difference between actual outcome and predicted Y(0) for observations of treated units under control based on baseline (two-way fixed effects) model.
by period residual standard deviation for estimated pre-treatment average treatment effects.
average treatment effect on the treated.
by unit average treatment effect on the treated.
term for switch-on treatment effect.
count of each term for switch-on treatment effect.
switch-on treatment effect.
term for switch-off treatment effect.
switch-off treatment effect.
count of each term for switch-off treatment effect.
average treatment effect for placebo period.
average treatment effect for carryover period.
average treatment effect for each calendar period.
loess fitted values of average treatment effect for each calendar period.
number of treated observations at each calendar period.
average treatment effect for the balance sample.
switch-on treatment effect for the balance sample.
term of switch-on treatment effect for the balance sample.
count of each term for switch-on treatment effect for the balance sample.
average treatment effect for placebo period of the balance sample.
average treatment effect for different groups.
a list saving the switch-on treatment effects for different groups.
inference for att.avg
.
inference for att.avg.unit
.
inference for att.on
.
inference for att.off
.
inference for att.placebo
.
inference for att.carryover
.
inference for eff.calendar
.
inference for eff.calendar.fit
.
inference for balance.att
.
inference for balance.avg.att
.
inference for balance.att.placebo
.
inference for beta
.
inference for group.att
.
inference for group.output
.
bootstrap results for att.avg
.
bootstrap results for att.avg.unit
.
bootstrap results for count
.
bootstrap results for att.avg.off
.
bootstrap results for count.off
.
bootstrap results for att.placebo
.
bootstrap results for att.carryover
.
bootstrap results for balance.att
.
equivalence confidence interval for equivalence test.
equivalence confidence interval for equivalence test for switch-off effect.
bootstrap results for beta
.
goodness-of-fit test and equivalent test results for pre-treatment fitting check.
leave-one-period-out goodness-of-fit test and equivalent test results for pre-treatment fitting check.
permutation test results for sharp null hypothesis.
an object of class "formula": a symbolic description of the model to be fitted, e.g, Y~D+X1+X2
a data frame, can be a balanced or unbalanced panel data.
the outcome indicator.
the treatment indicator. The treatment should be binary (0 and 1).
time-varying covariates. Covariates that have perfect collinearity with specified fixed effects are dropped automatically.
the group indicator. If specified, the group-wise ATT will be estimated.
a logical flag indicating whether to list-wise delete missing observations. Default to FALSE. If na.rm = FALSE
, it allows the situation when Y is missing but D is not missing for some observations. If na.rm = TRUE
, it will list-wise delete observations whose Y, D, or X is missing.
a two-element string vector specifying the unit and time indicators. Must be of length 2. Every observation should be uniquely defined by the pair of the unit and time indicator.
a string indicating whether unit or time or both fixed effects will be imposed. Must be one of the following, "none", "unit", "time", or "two-way". The default is "two-way".
an integer specifying the number of factors. If CV = TRUE
, the cross validation procedure will select the optimal number of factors from r
to 5.
a single or sequence of positive numbers specifying the hyper-parameter sequence for matrix completion method. If lambda
is a sequence and CV = 1
, cross-validation will be performed.
an integer specifying the length of hyper-parameter sequence for matrix completion method. Default is nlambda = 10
.
a logical flag indicating whether cross-validation will be performed to select the optimal number of factors or hyper-parameter in matrix completion algorithm. If r
is not specified, the procedure will search through r = 0
to 5
.
an integer specifying number of cross-validation rounds. Default is k = 10
.
a numerical value specifying the proportion of testing set compared to sample size during the cross-validation procedure.
a logical flag speficying whether to only use observations of treated units as testing set.
an integer specifying the length of continuous observations within a unit in the testing set. Default is cv.nobs = 3
.
an integer specifying the length of removed observations at the head and tail of the continuous observations specified by cv.nobs
.
These removed observations will not be used to fit the data nor be in the validation set for the cross-validation, e.g, if cv.nobs=3
and cv.donut = 1
, the first and the last observation in each triplet will not be included in the test set.
Default is cv.donut = 0
.
criterion used for model selection. Default is "mspe".
"mspe"
for the mean squared prediction error,
"gmspe"
for the geometric-mean squared prediction errors,
if criterion="moment"
, we average the residuals in test sets by their relative periods to treatments and then average the squares of these period-wise deviations weighted by the number of observations at each period, it yields a better pre-trend fitting on test sets rather than a better prediction ability.
"pc"
for the information criterion of interactive fixed effects or generalized synthetic control model.
This version doesn't support this option. a logical flag indicating whether a probit link function will be used.
This version doesn't support this option. a logical flag indicating whether QR decomposition will be used for factor analysis in probit model.
a string specifying which imputation algorithm will be used.
"fe"
for fixed effects model,
"ife"
for interactive fixed effects model,
"mc"
for matrix copletion method,
"polynomial"
for polynomial trend terms,
"bspline"
for regression splines,
"gsynth"
for generalized synthetic control method,
and "cfe"
for complex fixed effects method
Default is method = "fe"
.
a logical flag indicating whether uncertainty estimates will be produced.
a string specifying the type of variance estimator. Choose
from vartype = c("bootstrap", "jackknife", "parametric")
. Default value is
"bootstrap"
.
an integer specifying the number of bootstrap
runs. Ignored if se = FALSE
.
significant level for hypothesis test and CIs. Default value is
alpha = 0.05
.
a logical flag indicating whether parallel computing
will be used in bootstrapping and/or cross-validation. Ignored if
se = FALSE
.
an integer indicating the number of cores to be used in parallel computing. If not specified, the algorithm will use the maximum number of logical cores of your computer (warning: this could prevent you from multi-tasking on your computer).
a positive number indicating the tolerance level.
an integer that sets the seed in random number
generation. Ignored if se = FALSE
and r
is specified.
an integer specifying the minimum value of observed periods that a unit is under control.
an integer. Units with number of missing values greater than
it will be removed. Ignored if this parameter is set "NULL"(i.e. max.missing = NULL
, the default setting).
a numeric value specifying pre-treatment periods that have
observations larger than the proportion of observations at period 0.
These pre-treatment periods are used used for goodness-of-fit test.
Ignore if se = FALSE
. Deafult is proportion = 0.3
.
a vector specifying the range of pre-treatment period used for goodness-of-fit test. If left blank, all
pre-treatment periods specified by proportion
will be used. Ignore if se = FALSE
.
a numeric value specifying the threshold for the F-statistic in the equivalent test.
Ignore if se = FALSE
. Deafult is f.threshold = 0.5
.
a numeric value specifying the threshold for the two-one-sided t-test.
If alpha=0.05
, TOST checks whether the 90
The default value is 0.36 times the standard deviation of the outcome variable after two-way fixed effects are partialed out.
a numeric vector speicfying the knots for b-spline curve trend term.
an integer speifcying the order of either the b-spline or the polynomial trend term.
a vector specifying other fixed effects in addition to unit or time fixed effects that is used when method="cfe"
.
a vector of lists specifying interactive fixed effects when method="cfe"
.
For each list, the value of the first element is the name of the group variable for which fixed effects are to be estimated.
The value of the second element is the name of a regressor (e.g., a time trend).
a vector of length 2 specifying the range of periods for a balanced sample which has no missing observation in the specified range.
a logical flag indicating whether to allow missing observations in this balanced sample. The default is FALSE.
a logic flag indicating whether to perform placebo test.
an integer or a two-element numeric vector specifying the range of pre-treatment periods that will be assigned as pseudo treatment periods.
a logic flag indicating whether to perform (no) carryover test.
an integer or a two-element numeric vector specifying the range of post-treatment periods that will be assigned as pseudo treatment periods.
an integer specifying the range of post-treatment periods that will be assigned as pseudo treatment periods.
a logic flag indicating whether to perform the leave-one-period-out goodness-of-fit test, which is very time-consuming.
a logic flag indicating whether to perform permutation test.
an integer specifying the block length in permutation test. Default value is
m = 2
.
a logic flag indicating whether to scale outcome and
covariates. Useful for accelerating computing speed when magnitude of data is large. The default is normalize=FALSE
.
Licheng Liu; Ye Wang; Yiqing Xu; Ziyi Liu
fect
implements counterfactual estimators in TSCS data analysis. These estimators first impute counterfactuals for
each treated observation in a TSCS dataset by fitting an outcome model (fixed effects model, interactive fixed effects model, or
matrix completion) using the untreated observations. They then estimate the individualistic treatment effect for each treated
observation by subtracting the predicted counterfactual outcome from its observed outcome. Finally, the average treatment effect
on the treated (ATT) or period-specific ATTs are calculated. A placebo test and an equivalence test are included to evaluate the
validity of identification assumptions behind these estimators. Data must be with a dichotomous treatment.
Jushan Bai. 2009. "Panel Data Models with Interactive Fixed Effects." Econometrica.
Yiqing Xu. 2017. "Generalized Synthetic Control Method: Causal Inference with Interactive Fixed Effects Models." Political Analysis.
Athey, Susan, et al. 2021 "Matrix completion methods for causal panel data models." Journal of the American Statistical Association.
Licheng Liu, et al. 2022. "A Practical Guide to Counterfactual Estimators for Causal Inference with Time-Series Cross-Sectional Data." American Journal of Political Science.
For more details about the matrix completion method, see https://github.com/susanathey/MCPanel.
plot.fect
and print.fect
library(fect)
data(fect)
out <- fect(Y ~ D + X1 + X2, data = simdata1,
index = c("id","time"), force = "two-way",
CV = TRUE, r = c(0, 5), se = 0, parallel = FALSE)
Run the code above in your browser using DataLab