*! version 0.1 27feb2024

Title

stackdid -- Stacked Difference-in-Differences Regression

Syntax

stackdid
[depvar]
[indepvars]
[if] [in]
[weight]
[, options]

Main
* treatment(varname) binary treatment indicator

* group(varname) panelvar at which treatment occurs

* window(numlist) window of time to consider relative to treatment

nevertreat use only never-treated observations as controls; default
behavior is to use never-treated and not-yet-treated observations

poisson estimate a Poisson regression instead of a linear regression

nobuild do not build stacked data

noregress do not perform regression

Estimator-specific options
reghdfe options for reghdfe

ppmlhdfe options for ppmlhdfe if
poisson specified

Display
nolog do not display build log

Saving
clear replace data in memory with stacked data used in regression

saving(filename, ...) save stacked data to filename; see [G-3] saving option

by is allowed; see prefix.

for allowed weights, see estimator's help file.

* starred options are required, unless nobuild is specified.

Description

stackdid performs a stacked difference-in-differences regression for
staggered treatment settings, as described in Gormley and Matsa (2011). It offers three primary advantages compared to a standard difference-in-differences approach in such settings:

(1) is not subject to earlier bias from dynamic effects

(2) can easily isolate a particular window if interest around each event

(3) can easily be extended into a triple-difference specification

This method generally requires restructuring the data in memory into "stacks"
of "cohorts" centered on treatment events. stackdid will create these stacks
and perform the specified regression. The typical specification is

y = beta*D + delta + alpha + epsilon

where D is a treatment indicator, delta is a cohort-time fixed effect,
and alpha is a unit-cohort fixed effect, and epsilon is a random disturbance.
Since stackdid creates the stacks of cohorts, it also creates the cohort-time fixed effect and the
unit-cohort fixed effect; the user may specify additional fixed effects
using absorb().

Options

Main

treatment(varname) is a binary (0,1) indicator that an observation is
treated; for example, if a group is treated only in 2004, varname equals 1
in 2004 and 0 otherwise for observations in that group. Missing values are
allowed and denote unobserved treatment status.

group(varname) is the panelvar at which treatment occurs. This need not
be the same panelvar as set in xtset; for example, if treatment is
determined at the state-year level, specify group(state), even if the data
are at the firm-year level.

window(numlist) is the window of time (relative to treatment) to include
in a stack. For example, window(-10 10) specifies that a 2004 cohort
consists of 1994-2013 data. However, not all cohort observations in this window will
necessarily enter the stack: first, a treated group exits the stack if its
treatment status subsequently turns off again. Second, a control group exits
the stack if it becomes treated (or, if nevertreat is specified, such
groups will not be controls in the first place).

nevertreat specifies that only never-treated groups be controls. This reduces
the number of groups eligible to be used as controls, or has no effect. If this
is not specified, controls consist of never-treated groups and not-yet-treated
groups.

poisson specifies that the model be estimated using a poisson regression
instead of a linear regression. Functionally, this changes the underlying
estimation command from reghdfe to ppmlhdfe; see
estimator-specific options.

nobuild does not build stacked data and proceeds directly to estimation.
This option assumes the data in memory are stacked data already built by stackdid.
See remarks for the intended use case.

noregress does not perform the estimation step.

Estimator-specific options

Linear regressions and Poisson regressions are allowed by stackdid thanks
to the excellent estimation commands reghdfe and ppmlhdfe contributed
by Sergio Correia et al. Thus, stackdid "inherits" these commands' options;
see their help files for full documentation.

estimator

reghdfe linear regression with multiple fixed effects

ppmlhdfe Poisson psuedo-likelihood regression with multiple fixed effects

Display

nolog suppresses printing to console a build log.

Saving

clear replaces the data in memory with the stacked data built by stackdid and used by estimator. This option must be specified
if the post-estimation return function e(sample) is desired. If clear
is not specified, the original data in memory are restored after estimation.

saving(filename [, replace]) saves the stacked cohorts built by stackdid
and used by estimator to filename.

replace permits saving() to overwite an existing dataset.

Remarks

stackdid has two primary features. Options are provided to isolate either
of these. If both of these options are specified, stackdid does nothing.

feature optionally off

(1) build stacked data nobuild

(2) perform specified regression noregress

Practictioners often build upon a baseline specification with increasingly strict
fixed effects and/or controls. stackdid will always create the same stacks
when the required options (treatment(), group(), window()) and
nevertreat are the same. Thus, one can reduce redundant computation using the clear
option in the first specification and the nobuild option in subsequent
specifications.

Although stackdid without the clear option returns the original
data, Stata will flag it as having changed. This is an artifact of building
stacks in memory, adjacent to the original data. The consequence is that
use and exit will prompt you to clear the data in memory.

Examples

An example dataset is supplied. In it, a balanced panel of 500 fictional firms
(firm_id) in 2000-2011 are divided into eleven groups
(sector) with three treatment events. The outcome variable (y) has
an autoregressive component persistent in continuous treatment,
encouraging the application of stackdid. The sample of firms is bisected
by characteristic char. A window of three years before
and after treatment events is to be specified.

Load the example data and apply xtset

. use https://raw.githubusercontent.com/jacobwtriplett/stackdid/main/stackdid_example

. xtset firm_id year

Basic usage

. stackdid y treatXpost, tr(treatXpost) gr(sector) w(-3 3)

Subsequent specifications

. stackdid y treatXpost, tr(treatXpost) gr(sector) w(-3 3) clear

. stackdid y treatXpost, nobuild absorb(firm_id)

Triple difference

. stackdid y treatXpost treatXpostXchar, nobuild absorb(year#char)

If group() is needed for estimator

. stackdid, tr(treatXpost) gr(sector) w(-3 3) clear noreg

. estimator y treatXpost, group(...)

Suggested: visually decompose cohorts

. table (sector) (year) (_cohort), statistic(firstnm treatXpost) nototal

Stored results

stackdid stores the following in r():

Scalars

r(N_orig) number of observations in original data

r(N_stacked) number of observations in stacked data (also see e(N))

Macros

r(cmdline) command as typed

r(regline) command fed to estimator (also see e(cmdline))

r(treatment) treatment variable

r(group) group variable

r(window) window numlist

See estimator's help file for results stored in e().

Author

Jacob Triplett

Carnegie Mellon University

jacobtri@andrew.cmu.edu

Acknowledgments

I wish to thank Todd Gormley for the inspiration to develop this package,
and Todd Gormley and David Matsa for invaluable guidance during its development.

References

Sergio Correia, Paulo Guimarães, Thomas Zylkin: "ppmlhdfe: Fast Poisson Estimation with High-Dimensional Fixed Effects", 2019; arXiv:1903.01690.

Sergio Correia, 2014. "REGHDFE: Stata module to perform linear or instrumental-variable regression absorbing any number of high-dimensional fixed effects," Statistical Software Components S457874, Boston College Department of Economics, revised 21 Aug 2023.

Todd A. Gormley, David A. Matsa, Growing Out of Trouble? Corporate Responses to Liability Risk, The Review of Financial Studies, Volume 24, Issue 8, August 2011, Pages 2781–2821, https://doi.org/10.1093/rfs/hhr011.

Todd A. Gormley, David A. Matsa,
Playing it safe? Managerial preferences, risk, and agency conflicts,
Journal of Financial Economics,
Volume 122, Issue 3,
2016,
Pages 431-455,
ISSN 0304-405X,
https://doi.org/10.1016/j.jfineco.2016.08.002.

Todd A. Gormley, Manish Jha, and Meng Wang, The Politicization of Social Responsibility (March 11, 2024). Available at SSRN: https://ssrn.com/abstract=4558097