Title: | Fixed Effects Counterfactuals |
---|---|
Description: | Estimates causal effects with panel data using the counterfactual methods. It is suitable for panel or time-series cross-sectional analysis with binary treatments under (hypothetically) baseline randomization.It allows a treatment to switch on and off and limited carryover effects. It supports linear factor models, a generalization of gsynth and the matrix completion method. Implementation details can be found in Liu, Wang and Xu (2022) <arXiv:2107.00856>. |
Authors: | Licheng Liu [aut], Ziyi Liu [aut, cre], Ye Wang [aut], Yiqing Xu [aut] |
Maintainer: | Ziyi Liu <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.0.0 |
Built: | 2024-11-04 06:44:00 UTC |
Source: | CRAN |
The package implements counterfactual estimators in TSCS data analysis and statistical tools to test their identification assumptions.
It 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 observatio n 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.
See fect
for details.
Licheng Liu <[email protected]>, MIT
Ye Wang <[email protected]>, New York University
Yiqing Xu <[email protected] >, Stanford University
Ziyi Liu <[email protected]>, University of Chicago
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.
Calculate cumulative treatment effects
att.cumu(x, period = NULL, weighted = TRUE, alpha = 0.05, type = "on", plot = FALSE)
att.cumu(x, period = NULL, weighted = TRUE, alpha = 0.05, type = "on", plot = FALSE)
x |
a |
period |
a two-element numeric vector specifying the range of term during which treatment effects are to be accumulated.
e.g. |
weighted |
a logical flag specifying whether to calculate weigthed cumulative treatment effects based on counts at each period. Default is
|
alpha |
a numerical value that specfies significant level. |
type |
a string that specifies the type. Must be one of the following: "on" (switch-on treatment effect); "off" (switch-off treatment effect). Default
is |
plot |
A logical flag indicating whether to plot cumulative effects.
Default is |
Licheng Liu; Ye Wang; Yiqing Xu
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.
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)
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)
formula |
an object of class "formula": a symbolic description of the model to be fitted, e.g, Y~D+X1+X2 |
data |
a data frame, can be a balanced or unbalanced panel data. |
Y |
the outcome indicator. |
D |
the treatment indicator. The treatment should be binary (0 and 1). |
X |
time-varying covariates. Covariates that have perfect collinearity with specified fixed effects are dropped automatically. |
group |
the group indicator. If specified, the group-wise ATT will be estimated. |
na.rm |
a logical flag indicating whether to list-wise delete missing observations. Default to FALSE. If |
index |
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. |
force |
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". |
r |
an integer specifying the number of factors. If |
lambda |
a single or sequence of positive numbers specifying the hyper-parameter sequence for matrix completion method. If |
nlambda |
an integer specifying the length of hyper-parameter sequence for matrix completion method. Default is |
CV |
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 |
k |
an integer specifying number of cross-validation rounds. Default is |
cv.prop |
a numerical value specifying the proportion of testing set compared to sample size during the cross-validation procedure. |
cv.treat |
a logical flag speficying whether to only use observations of treated units as testing set. |
cv.nobs |
an integer specifying the length of continuous observations within a unit in the testing set. Default is |
cv.donut |
an integer specifying the length of removed observations at the head and tail of the continuous observations specified by |
criterion |
criterion used for model selection. Default is "mspe".
|
binary |
This version doesn't support this option. a logical flag indicating whether a probit link function will be used. |
QR |
This version doesn't support this option. a logical flag indicating whether QR decomposition will be used for factor analysis in probit model. |
method |
a string specifying which imputation algorithm will be used.
|
se |
a logical flag indicating whether uncertainty estimates will be produced. |
vartype |
a string specifying the type of variance estimator. Choose
from |
nboots |
an integer specifying the number of bootstrap
runs. Ignored if |
alpha |
significant level for hypothesis test and CIs. Default value is
|
parallel |
a logical flag indicating whether parallel computing
will be used in bootstrapping and/or cross-validation. Ignored if
|
cores |
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). |
tol |
a positive number indicating the tolerance level. |
seed |
an integer that sets the seed in random number
generation. Ignored if |
min.T0 |
an integer specifying the minimum value of observed periods that a unit is under control. |
max.missing |
an integer. Units with number of missing values greater than
it will be removed. Ignored if this parameter is set "NULL"(i.e. |
proportion |
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 |
pre.periods |
a vector specifying the range of pre-treatment period used for goodness-of-fit test. If left blank, all
pre-treatment periods specified by |
f.threshold |
a numeric value specifying the threshold for the F-statistic in the equivalent test.
Ignore if |
tost.threshold |
a numeric value specifying the threshold for the two-one-sided t-test.
If |
knots |
a numeric vector speicfying the knots for b-spline curve trend term. |
degree |
an integer speifcying the order of either the b-spline or the polynomial trend term. |
sfe |
a vector specifying other fixed effects in addition to unit or time fixed effects that is used when |
cfe |
a vector of lists specifying interactive fixed effects when |
balance.period |
a vector of length 2 specifying the range of periods for a balanced sample which has no missing observation in the specified range. |
fill.missing |
a logical flag indicating whether to allow missing observations in this balanced sample. The default is FALSE. |
placeboTest |
a logic flag indicating whether to perform placebo test. |
placebo.period |
an integer or a two-element numeric vector specifying the range of pre-treatment periods that will be assigned as pseudo treatment periods. |
carryoverTest |
a logic flag indicating whether to perform (no) carryover test. |
carryover.period |
an integer or a two-element numeric vector specifying the range of post-treatment periods that will be assigned as pseudo treatment periods. |
carryover.rm |
an integer specifying the range of post-treatment periods that will be assigned as pseudo treatment periods. |
loo |
a logic flag indicating whether to perform the leave-one-period-out goodness-of-fit test, which is very time-consuming. |
permute |
a logic flag indicating whether to perform permutation test. |
m |
an integer specifying the block length in permutation test. Default value is
|
normalize |
a logic flag indicating whether to scale outcome and
covariates. Useful for accelerating computing speed when magnitude of data is large. The default is |
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.
Y.dat |
a T-by-N matrix storing data of the outcome variable. |
D.dat |
a T-by-N matrix storing data of the treatment variable. |
I.dat |
a T-by-N matrix storing data of the indicator for whether is observed or missing. |
Y |
name of the outcome variable. |
D |
name of the treatment variable. |
X |
name of the time-varying control variables. |
index |
name of the unit and time indicators. |
force |
user specified |
T |
the number of time periods. |
N |
the total number of units. |
p |
the number of time-varying observables. |
r.cv |
the number of factors included in the model – either supplied by users or automatically chosen via cross-validation. |
lambda.cv |
the optimal hyper-parameter in matrix completion method chosen via cross-validation. |
beta |
coefficients of time-varying observables from the interactive fixed effect model. |
sigma2 |
the mean squared error of interactive fixed effect model. |
IC |
the information criterion. |
est |
result of the interactive fixed effect model based on observed values. |
MSPE |
mean squared prediction error of the cross-validated model. |
CV.out |
result of the cross-validation procedure. |
niter |
the number of iterations in the estimation of the interactive fixed effect model. |
factor |
estimated time-varying factors. |
lambda |
estimated loadings. |
lambda.tr |
estimated loadings for treated units. |
lambda.co |
estimated loadings for control units. |
mu |
estimated ground mean. |
xi |
estimated time fixed effects. |
alpha |
estimated unit fixed effects. |
alpha.tr |
estimated unit fixed effects for treated units. |
alpha.co |
estimated unit fixed effects for control units. |
validX |
a logic value indicating if multicollinearity exists. |
validF |
a logic value indicating if factor exists. |
id |
a vector of unit IDs. |
rawtime |
a vector of time periods. |
obs.missing |
a matrix stroing status of each unit at each time point. |
Y.ct |
a T-by-N matrix storing the predicted Y(0). |
eff |
a T-by-N matrix storing the difference between actual outcome and predicted Y(0). |
res |
residuals for observed values. |
eff.pre |
difference between actual outcome and predicted Y(0) for observations of treated units under control. |
eff.pre.equiv |
difference between actual outcome and predicted Y(0) for observations of treated units under control based on baseline (two-way fixed effects) model. |
pre.sd |
by period residual standard deviation for estimated pre-treatment average treatment effects. |
att.avg |
average treatment effect on the treated. |
att.avg.unit |
by unit average treatment effect on the treated. |
time |
term for switch-on treatment effect. |
count |
count of each term for switch-on treatment effect. |
att |
switch-on treatment effect. |
time.off |
term for switch-off treatment effect. |
att.off |
switch-off treatment effect. |
count.off |
count of each term for switch-off treatment effect. |
att.placebo |
average treatment effect for placebo period. |
att.carryover |
average treatment effect for carryover period. |
eff.calendar |
average treatment effect for each calendar period. |
eff.calendar.fit |
loess fitted values of average treatment effect for each calendar period. |
N.calandar |
number of treated observations at each calendar period. |
balance.avg.att |
average treatment effect for the balance sample. |
balance.att |
switch-on treatment effect for the balance sample. |
balance.time |
term of switch-on treatment effect for the balance sample. |
balance.count |
count of each term for switch-on treatment effect for the balance sample. |
balance.att.placebo |
average treatment effect for placebo period of the balance sample. |
group.att |
average treatment effect for different groups. |
group.output |
a list saving the switch-on treatment effects for different groups. |
est.att.avg |
inference for |
est.att.avg.unit |
inference for |
est.att |
inference for |
est.att.off |
inference for |
est.placebo |
inference for |
est.carryover |
inference for |
est.eff.calendar |
inference for |
est.eff.calendar.fit |
inference for |
est.balance.att |
inference for |
est.balance.avg |
inference for |
est.balance.placebo |
inference for |
est.beta |
inference for |
est.group.att |
inference for |
est.group.output |
inference for |
att.avg.boot |
bootstrap results for |
att.avg.unit.boot |
bootstrap results for |
att.count.boot |
bootstrap results for |
att.off.boot |
bootstrap results for |
att.off.count.boot |
bootstrap results for |
att.placebo.boot |
bootstrap results for |
att.carryover.boot |
bootstrap results for |
balance.att.boot |
bootstrap results for |
att.bound |
equivalence confidence interval for equivalence test. |
att.off.bound |
equivalence confidence interval for equivalence test for switch-off effect. |
beta.boot |
bootstrap results for |
test.out |
goodness-of-fit test and equivalent test results for pre-treatment fitting check. |
loo.test.out |
leave-one-period-out goodness-of-fit test and equivalent test results for pre-treatment fitting check. |
permute |
permutation test results for sharp null hypothesis. |
Licheng Liu; Ye Wang; Yiqing Xu; Ziyi Liu
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)
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)
Internal fect functions
These are not to be called by the user (or in some cases are just waiting for proper documentation to be written :).
Gets the cohort index given a panel data.
get.cohort(data, D, index, varname = NULL, entry.time = NULL)
get.cohort(data, D, index, varname = NULL, entry.time = NULL)
data |
a data frame, can be a balanced or unbalanced panel data. |
D |
the treatment indicator. The treatment should be binary (0 and 1). |
index |
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. |
varname |
a string specifying the name for the generated cohort index. |
entry.time |
a list of intervals for first get-treated time. |
get.cohort
pre-processes the data and generates the index for different cohorts..
data |
a new data frame containing the cohort index. |
Licheng Liu; Ye Wang; Yiqing Xu, Ziyi Liu
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.
fect
and print.fect
library(fect) data(fect) simdata.cohort <- get.cohort(data = simdata,D = 'D',index = c("id","time"))
library(fect) data(fect) simdata.cohort <- get.cohort(data = simdata,D = 'D',index = c("id","time"))
Estimating interactive fixed effect models.
interFE(formula = NULL, data, Y, X, index, r = 0, force = "none", se = TRUE, nboots = 500, seed = NULL, tol = 1e-3, binary = FALSE, QR = FALSE, normalize = FALSE)
interFE(formula = NULL, data, Y, X, index, r = 0, force = "none", se = TRUE, nboots = 500, seed = NULL, tol = 1e-3, binary = FALSE, QR = FALSE, normalize = FALSE)
formula |
an object of class "formula": a symbolic description of the model to be fitted. |
data |
a data frame (must be with a dichotomous treatment but balanced is not required). |
Y |
outcome. |
X |
time-varying covariates. |
index |
a two-element string vector specifying the unit (group) and time indicators. Must be of length 2. |
r |
an integer specifying the number of factors. |
force |
a string indicating whether unit or time fixed effects will be imposed. Must be one of the following, "none", "unit", "time", or "two-way". The default is "unit". |
se |
a logical flag indicating whether uncertainty estimates will be produced via bootstrapping. |
nboots |
an integer specifying the number of bootstrap
runs. Ignored if |
seed |
an integer that sets the seed in random number
generation. Ignored if |
tol |
a numeric value that specifies tolerate level. |
binary |
a logical flag indicating whether a probit link function will be used. |
QR |
a logical flag indicating whether QR decomposition will be used for factor analysis in probit model. |
normalize |
a logic flag indicating whether to scale outcome and
covariates. Useful for accelerating computing speed when magnitude of data is large.The default is |
interFE
estimates interactive fixed effect models proposed by
Bai (2009).
beta |
estimated coefficients. |
mu |
estimated grand mean. |
factor |
estimated factors. |
lambda |
estimated factor loadings. |
VNT |
a diagonal matrix that consists of the r eigenvalues. |
niter |
the number of iteration before convergence. |
alpha |
estimated unit fixed effect (if |
xi |
estimated time fixed effect (if |
residuals |
residuals of the estimated interactive fixed effect model. |
sigma2 |
mean squared error of the residuals. |
IC |
the information criterion. |
ValidX |
a logical flag specifying whether there are valid covariates. |
dat.Y |
a matrix storing data of the outcome variable. |
dat.X |
an array storing data of the independent variables. |
Y |
name of the outcome variable. |
X |
name of the time-varying control variables. |
index |
name of the unit and time indicators. |
est.table |
a table of the estimation results. |
est.boot |
a matrix storing results from bootstraps. |
Licheng Liu; Ye Wang; Yiqing Xu
Jushan Bai. 2009. "Panel Data Models with Interactive Fixed Effects." Econometrica 77:1229–1279.
print.interFE
and fect
library(fect) data(fect) d <- simdata1[-(1:150),] # remove the treated units out <- interFE(Y ~ X1 + X2, data = d, index=c("id","time"), r = 2, force = "two-way", nboots = 50)
library(fect) data(fect) d <- simdata1[-(1:150),] # remove the treated units out <- interFE(Y ~ X1 + X2, data = d, index=c("id","time"), r = 2, force = "two-way", nboots = 50)
Visualizes estimation results of the matrix completion method.
## S3 method for class 'fect' plot(x, type = NULL, loo = "FALSE", highlight = NULL, plot.ci = NULL, show.points = NULL, show.group = NULL, bound = NULL, vis = NULL, count = TRUE, proportion = 0.3, pre.periods = NULL, f.threshold = NULL, tost.threshold = NULL, effect.bound.ratio = FALSE, stats = NULL, stats.labs = NULL, main = NULL, xlim = NULL, ylim = NULL, xlab = NULL, ylab = NULL, gridOff = FALSE, legendOff = FALSE, legend.pos = NULL, legend.nrow = NULL, legend.labs = NULL, stats.pos = NULL, theme.bw = TRUE, nfactors = NULL, include.FE = TRUE, id = NULL, cex.main = NULL, cex.main.sub = NULL, cex.axis = NULL, cex.lab = NULL, cex.legend = NULL, cex.text = NULL, axis.adjust = FALSE, axis.lab = "both", axis.lab.gap = c(0, 0), start0 = FALSE, return.test = FALSE, balance = NULL,...)
## S3 method for class 'fect' plot(x, type = NULL, loo = "FALSE", highlight = NULL, plot.ci = NULL, show.points = NULL, show.group = NULL, bound = NULL, vis = NULL, count = TRUE, proportion = 0.3, pre.periods = NULL, f.threshold = NULL, tost.threshold = NULL, effect.bound.ratio = FALSE, stats = NULL, stats.labs = NULL, main = NULL, xlim = NULL, ylim = NULL, xlab = NULL, ylab = NULL, gridOff = FALSE, legendOff = FALSE, legend.pos = NULL, legend.nrow = NULL, legend.labs = NULL, stats.pos = NULL, theme.bw = TRUE, nfactors = NULL, include.FE = TRUE, id = NULL, cex.main = NULL, cex.main.sub = NULL, cex.axis = NULL, cex.lab = NULL, cex.legend = NULL, cex.text = NULL, axis.adjust = FALSE, axis.lab = "both", axis.lab.gap = c(0, 0), start0 = FALSE, return.test = FALSE, balance = NULL,...)
x |
a |
type |
a string specifying the type of the plot.
|
loo |
a logical flag indicating whether to use the leave-one-period-out pre-treatment effects for the visualization and tests. |
highlight |
a logical flag indicating whether to highlight the periods for the carryover and placebo test. |
plot.ci |
a string specifying the confidence interval. Choose from: "0.9", "0.95", or "none". |
show.points |
a logical flag indicating whether to represent treatment effects by points or point-ranges. Default to TRUE. |
show.group |
a string indicating the group to be visualized. |
bound |
a string that specifies the bounds to be plotted for equivalence test for pre-treatment fit checking. Choose from: "both", "equiv", "min" and "none". |
vis |
A string specifying whether to plot the dots for placebo plots. |
count |
a logical flag controlling whether to show the count of each term for gap plot. |
proportion |
a positive value specifying periods at which observations equal to or greater than the proporation of the largest number of observations at a certain period. Default to 0.3. |
pre.periods |
a vector specifying the range of pre-treatment period used for goodness-of-fit test. If left blank, all
pre-treatment periods specified by |
f.threshold |
a numeric value specifying the threshold for the F-statistic in the equivalent test.
Ignore if |
tost.threshold |
a numeric value specifying the threshold for the two-one-sided t-test.
If |
effect.bound.ratio |
a logical value specifiying whether to annotate the ratio of estimated average treatment effects / minimun bound. |
stats |
a string that specifices what statistics to be shown. For |
stats.labs |
a string specifying the label for the statistics specified by |
main |
a string that controls the title of the plot. If not supplied, no title will be shown. |
xlim |
a two-element numeric vector specifying the range of x-axis. When
class of time varible is string, must specify not original value but a counting number e.g. |
ylim |
a two-element numeric vector specifying the range of y-axis. |
xlab |
a string indicating the label of the x-axis. |
ylab |
a string indicating the label of the y-axis. |
gridOff |
a logical flag indicating whether to remove the grid lines for the status plot. |
legendOff |
a logical flag controlling whether to show the legend. |
legend.pos |
a string specifying the position of legend. If left blank, legend will be setted at the bottom. |
legend.nrow |
an integer speficying rows of legend. |
legend.labs |
a string vector for user-defined legends. |
stats.pos |
a numeric vector of length 2 specifying the postion for labels of test statistic value. |
theme.bw |
a logical flag specifying whether to use the black and white theme. |
nfactors |
a integer controlling the number of factors to be shown when |
include.FE |
a loical flag indicating whether to keep the fixed effects when |
id |
a string vector specifying a sub-group of units that are to be
plotted for treatment status( |
cex.main |
a numeric value (pt) specifying the fontsize of the main title. |
cex.main.sub |
a numeric value (pt) specifying the fontsize of the subtitles. |
cex.axis |
a numeric value (pt) specifying the fontsize of the texts on the axes. |
cex.lab |
a numeric value (pt) specifying the fontsize of the axis titles. |
cex.legend |
a numeric value (pt) specifying the fontsize of the legend. |
cex.text |
a numeric value (pt) specifying the fontsize of the annotations. |
axis.adjust |
a logic flag indicating whether to adjust labels on x-axis. Useful when class of time variable is string and data magnitude is large. |
axis.lab |
a string indicating whether labels on the x- and y-axis will be shown. There are four options: |
axis.lab.gap |
a numeric vector setting the gaps between labels on the x- or y-axis for |
start0 |
a logical flag indicating whether to index the start of the treatment as period 0 rather than period 1. Default to FALSE. |
return.test |
a logical flag indicating whether to return the results of statistical tests. |
balance |
a logical flag indicating whether to plot the dynamic treatment effects for the balance sample. |
... |
other argv. |
plot.fect
visualizes the estimation results obtained by fect
.
p |
a ggplot2 object saving the graph. |
test.out |
a list storing the results of statistical tests if |
Licheng Liu; Ye Wang; Yiqing Xu, Ziyi Liu
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.
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) plot(out) plot(out,type='status') plot(out,show.points = FALSE)
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) plot(out) plot(out,type='status') plot(out,show.points = FALSE)
Print results of the matrix completion method.
## S3 method for class 'fect' print(x, switch.on = TRUE, switch.off = FALSE,time.on.lim = NULL, time.off.lim = NULL, ...)
## S3 method for class 'fect' print(x, switch.on = TRUE, switch.off = FALSE,time.on.lim = NULL, time.off.lim = NULL, ...)
x |
a |
switch.on |
a logical value that specifies whether to print switch.on effect. |
switch.off |
a logical value that specifies whether to print switch.off effect. |
time.on.lim |
a two-element numeric vector specifying the range of term of
switch-on treatment effects. e.g. |
time.off.lim |
a two-element numeric vector specifying the range of term
of switch-off treatment effects. e.g. |
... |
other argv. |
No return value.
Licheng Liu; Ye Wang; Yiqing Xu; Ziyi Liu
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.
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) print(out)
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) print(out)
Print results of interactive fixed effects estimation.
## S3 method for class 'interFE' print(x, ...)
## S3 method for class 'interFE' print(x, ...)
x |
an |
... |
other argv. |
No return value.
Licheng Liu; Ye Wang; Yiqing Xu
Jushan Bai. 2009. "Panel Data Models with Interactive Fixed Effects." Econometrica 77:1229–1279.
library(fect) data(fect) d <- simdata1[-(1:150),] # remove the treated units out <- interFE(Y ~ X1 + X2, data = d, index=c("id","time"), r = 2, force = "two-way", nboots = 50) print(out)
library(fect) data(fect) d <- simdata1[-(1:150),] # remove the treated units out <- interFE(Y ~ X1 + X2, data = d, index=c("id","time"), r = 2, force = "two-way", nboots = 50) print(out)
A simulated dataset with continuous outcomes.
dataframe
Liu, Licheng, Ye Wang, and Yiqing Xu. 2022. “A Practical Guide to Counterfactual Estimators for Causal Inference with Time-Series Cross-Sectional Data.” American Journal of Political Science, forthcoming.
A simulated dataset with continuous outcomes.
dataframe
Liu, Licheng, Ye Wang, and Yiqing Xu. 2022. “A Practical Guide to Counterfactual Estimators for Causal Inference with Time-Series Cross-Sectional Data.” American Journal of Political Science, forthcoming.
State-level voter turnout data.
dataframe
Melanie Jean Springer. 2014. How the States Shaped the Nation: American Electoral Institutions and Voter Turnout, 1920-2000. University of Chicago Press.
Yiqing Xu. 2017. "Generalized Synthetic Control Method: Causal Inference with Interactive Fixed Effects Models." Political Analysis.