install.packages("fect")
1 Get Started
This chapter provides installation instructions and introduces the datasets used in the tutorial.
1.1 Installation
To install fect from CRAN, run the code chunk below:
We recommend users to install the most up-to-date version of fect from Github using:
devtools::install_github("xuyiqing/fect")
After installation, check fect version to make sure the package is up-to-date.
installed.packages()["fect", "Version"]
#> [1] "2.0.0"
panelView for panel data visualization is highly recommended and will be used in the tutorial:
devtools::install_github('xuyiqing/panelView')
fect depends on the following packages, which should be installed automatically when fect is being installed. You can also install them manually.
install_all <- function(packages) {
installed_pkgs <- installed.packages()[, "Package"]
for (pkg in packages) {
if (!pkg %in% installed_pkgs) {
install.packages(pkg)
}
}
}
packages <- c("abind", "doParallel", "doRNG", "fixest", "foreach", "future",
"GGally", "ggplot2", "grid", "gridExtra", "Mass",
"panelView", "Rcpp")
install_all(packages)
1.2 Datasets
The fect package ships three datasets.
1.2.1 simdata
We use a dataset called simdata
to demonstrate the counterfactual estimators shipped in previous versions of fect.
In simdata
, treatment is allowed to switch on and off. There are 200 units and 35 time periods. The data-generating process (DGP) is described in the paper.
Below, we use the panelView package to visualize treatment status of all units in simdata.
library(panelView)
panelview(Y ~ D, data = simdata, index = c("id","time"),
axis.lab = "time", xlab = "Time", ylab = "Unit",
gridOff = TRUE, by.timing = TRUE,
background = "white", main = "Simulated Data: Treatment Status")
panelview(Y ~ D, data = simdata, index = c("id","time"),
axis.lab = "time", xlab = "Time", ylab = "Unit",
theme.bw = TRUE, type = "outcome", main = "Simulated Data: Outcome")
1.2.2 simgsynth
We are merging gysth into fect. Since gysnth does not accommodate treatment reversal, we will use two datasets, simgsynth
and turnout
, to demonstrate how to run Gsynth using the fect package.
In simgsynth
, there are 5 treated units, 45 control units, and 30 time periods. The treatment kicks at Period 21 for all treated units, hence, a block DID set up.
We use panelView to visualize the treatment status of all units.
The following code visualizes the outcome variable by treatment condition; different colors correspond to unique treatment statuses.
1.2.3 turnout
The turnout
dataset was used to analyze the impact of Election-Day Registration reforms on voter turnout in the United States originally using gysnth. The treatment took effect at varying times across states. Further details about the dataset can be found in the Xu(2017) Section 5.
Again, we first visualize the treawtment status. The figure below shows a balanced panel with 9 treated units with the treatment starts at different time periods.
panelview(turnout ~ policy_edr, data = turnout,
index = c("abb","year"), pre.post = TRUE,
by.timing = TRUE)
We then visualize the outcome variable by treatment status (now in two separate figures) using colored lines to represent changes in treatment status for the treatment group.