Skip to contents

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

  1. Mac users may encounter compilation problems. See here for a potential solution.
  2. 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.
  3. For Rcpp, RcppArmadillo and MacOS “-lgfortran” and “-lquadmath” error, click here for details.
  4. Installation failure related to OpenMP on MacOS, click here for a solution.
  5. To fix these issues, try installing gfortran from here.

Report bugs

Please report bugs to yiqingxu [at] stanford.edu with your sample code and data file. Much appreciated!