JMSLab / xtevent

Stata package -xtevent-
MIT License
43 stars 12 forks source link

xtevent

GitHub release (latest by date)


Description

xtevent is a Stata package to estimate linear panel event-study models. It includes three commands: xtevent for estimation; xteventplot to create event-study plots and; xteventtest for post-estimation hypotheses testing.

Updates


Installation

To install version 3.1.0 from SSC:

ssc install xtevent

To update from an older version:

adoupdate xtevent, update

To install the last version in this repository, use the github command:

First, install the github command:

net install github, from("https://haghish.github.io/github/")

Then execute:

cap github uninstall xtevent
github install JMSLab/xtevent

The github command will also install all the necessary dependencies.

If you have an older version and want to update:

github update xtevent

To install using net:

cap ado uninstall xtevent
net install xtevent, from("https://raw.githubusercontent.com/JMSLab/xtevent/master")

To get started

help xtevent

Examples

Using xtevent 3.1.0

xtevent

*** setup
webuse nlswork, clear
* year variable has many missing observations
* Create a time variable that ignores the gaps
by idcode (year): gen time=_n
xtset idcode time

*Generate a policy variable that follows staggered adoption
by idcode (time): gen union2=sum(union)
replace union2=1 if union2>1 
order time union union2, after(year)

*** Examples
*Estimate a basic event study with clustered standard errors 
*Impute the policy variable assuming no unobserved changes
xtevent ln_w age c.age#c.age ttl_exp c.ttl_exp#c.ttl_exp tenure , ///
            pol(union2) w(3) cluster(idcode) impute(nuchange)

*Omit unit and time fixed effects
*Impute the policy variable verifying staggered adoption
xtevent ln_w age c.age#c.age ttl_exp c.ttl_exp#c.ttl_exp tenure , ///
            pol(union2) w(3) cluster(idcode) nofe note impute(stag)

* Bring back unit and time fixed effects
*Adjust for a pre-trend by estimating a linear trend by GMM
xtevent ln_w age c.age#c.age ttl_exp c.ttl_exp#c.ttl_exp tenure , ///
      pol(union2) w(3) cluster(idcode) trend(-2, method(gmm)) ///
        impute(stag)

*Freyaldenhoven, Hansen and Shapiro (2019) estimator with proxy variables
xtevent ln_w age c.age#c.age ttl_exp c.ttl_exp#c.ttl_exp tenure , ///
      pol(union2) w(3) vce(cluster idcode) proxy(wks_work) ///
        impute(stag)

*reghdfe and two-way clustering
xtevent ln_w age c.age#c.age ttl_exp c.ttl_exp#c.ttl_exp tenure , ///
            pol(union2) w(3) impute(stag) cluster(idcode year) reghdfe ///
            proxy(wks_work) 

*Sun and Abraham (2021) Estimator
xtevent ln_w age c.age#c.age ttl_exp c.ttl_exp#c.ttl_exp tenure, ///
            policyvar(union2) window(3) impute(stag) vce(cluster idcode) ///            
            reghdfe sunabraham

xteventplot


*** Setup
webuse nlswork, clear
* year variable has many missing observations
* Create a time variable that ignores the gaps
by idcode (year): gen time=_n
xtset idcode time

*** Examples 
*Basic event study with clustered standard errors 
*Impute the policy variable assuming no unobserved changes
xtevent ln_w age c.age#c.age ttl_exp c.ttl_exp#c.ttl_exp tenure , ///
            pol(union) w(3) cluster(idcode) impute(nuchange) 

* Simple plot
xteventplot

*Plot smoothest path in confidence region
xteventplot, smpath(line)

*Freyaldenhoven, Hansen and Shapiro (2019) estimator with proxy variables
xtevent ln_w age c.age#c.age ttl_exp c.ttl_exp#c.ttl_exp tenure , ///
            pol(union) w(3) vce(cluster idcode) impute(nuchange) ///
            proxy(wks_work)

*Dependent variable, proxy variable, and overlay plots
xteventplot, y
xteventplot, proxy
xteventplot, overlay(iv)
xteventplot

xteventtest

*** setup
webuse nlswork, clear
xtset idcode year

*** examples 
*Basic event study with clustered standard errors. 
*Impute the policy variable assuming no unobserved changes
xtevent ln_w age c.age#c.age ttl_exp c.ttl_exp#c.ttl_exp tenure , ///
            pol(union) w(3) cluster(idcode) impute(nuchange) 

*Test some coefficients to be equal to 0 jointly
xteventtest, coefs(1 2)

*Test that the sum of all pre-event coefficients is equal to 0
xteventtest, allpre cumul

*Test whether the coefficients before the event follow a linear trend
xteventtest, linpretrend

*Tests that the coefficients for the earliest 2 periods before the event are equal to 0
xteventtest, overidpre(2)

Video tutorial:

Our YouTube channel, Linear Panel Event-Study Design, contains a video series discussing xtevent and the accompanying paper, Visualization, Identification, and Estimation in the Panel Event-Study Design.


Citation

Simon Freyaldenhoven, Christian Hansen, Jorge Pérez Pérez, and Jesse M. Shapiro. "Visualization, Identification, and Estimation in the Linear Panel Event-Study Design." NBER Working Paper No. 29170, August 2021; forthcoming in Advances in Economics and Econometrics: Twelfth World Congress.

Simon Freyaldenhoven, Christian Hansen, Jorge Pérez Pérez, Jesse M. Shapiro, and Constantino Carreto. "xtevent: Estimation and Visualization in the Linear Panel Event-Study Design." Article to accompany Stata package, July 2024.