R package for implementing trajectory balancing, a kernel-based reweighting method for causal inference with panel data.
Repo: GitHub
Examples: R code used in the tutorial can be downloaded from here.
Reference: Hazlett, Chad and Yiqing Xu, 2018. “Trajectory Balancing: A General Reweighting Approach to Causal Inference with Time-Series Cross-Sectional Data.” Working Paper, UCLA and Stanford. Available at SSRN: https://papers.ssrn.com/sol3/papers.cfm?abstract_id=3214231.
Installation
You can install the development version of the package from Github by typing the following commands:
install.packages('devtools', repos = 'http://cran.us.r-project.org') # if not already installed
devtools::install_github('chadhazlett/KBAL')
devtools::install_github('xuyiqing/tjbal')
Note that installing kbal (from Github) is required. tjbal also depends on the following packages, which will be installed automatically when tjbal is installed. You can also install them manually:
## for plotting
require(ggplot2)
## for parallel computing
require(foreach)
require(future)
require(parallel)
## for data manipulation
require(plyr)
panelView for panel data visualization is also highly recommended:
devtools::install_github('xuyiqing/panelView')
Notes on installation failures
- Mac users may encounter compilation problems. See here for a potential solution.
- Windows users please consider upgrading R to 4.0.0 or higher and installing the latest Rtools to avoid C++17 complier errors when installing fastplm.
- For Rcpp, RcppArmadillo and MacOS “-lgfortran” and “-lquadmath” error, click here for details.
- Installation failure related to OpenMP on MacOS, click here for a solution.
- To fix these issues, try installing gfortran from here.