*! version 1.3.0 25Jan2024

Title

honestdid -- Stata implementation of the HonestDiD R package

Important: Please run honestdid _plugin_check before first use to check honestdid is installed correctly and up to date. Please refer to the online documentation if this check fails and to the online instructions for the latest version.

Syntax

Stata version of the HonestDiD R package, which implements robust inference for difference-in-differences and event study design methods developed in Rambachan and Roth (2021). See the examples section below for an illustration of how users can use this package to conduct sensitivity analysis on the parallel trends assumption in difference-in-differences and event study designs.

honestdid
,
[options coefplot_options]

Typically at least one of numpre() or pre() and post() are required options.

Options
numpreperiods(int) number of pre-treatment periods; rest vector entries are assumed to be post-treatment (required or specify pre()/post())

preperiodindex(numlist) pre-period indices (required or specify numpreperiods())

postperiodindex(numlist) post-period indices (required or specify numpreperiods())

delta(str) delta to use: rm (for relative magnitudes) or sd (second differences)

b(str) name of coefficient matrix; default is e(b)

vcov(str) name of vcov matrix; default is e(V)

omit omit dropped levels from b and vcov parsing names of b (e.g. omitted variables in regression)

l_vec(str) name of vector with parameters of interest (default is first period post event)

mvec(str) either name of vector with M values or number list of M values (must be >= 0)

grid_lb(real) lower bound for grid search (ignored with FLCI); default is selected internally based on estimates

grid_ub(real) upper bound for grid search (ignored with FLCI); default is selected internally based on estimates

gridPoints(str) number of grid points for search; default 1000

alpha(real) 1 - confidence level; default 0.05

method(str) C-LF (default with delta(rm)), FLCI (default with delta(sd)), Conditional, C-F

matasave(str) save resulting mata object (default: HonestEventStudy)

parallel(int) number of cores for parallel execution (default 4 if parallel is installed)

coefplot coefficient plot

colorspec(str) colors for CIs. The first color is taken as the color of the original CI and the second as the color of the other CIs; this option can be overriden by passing ciopts(lcolor()).

cached use cached results for coefficient plot

Description

See the online examples for details or refer to the examples below (note not all the functionality of the R package HonestDiD is mirrored, but the core functionality has been implemented).

Example 1: Benzarti and Carloni (2019)

Section 6.2 of Rambachan and Roth (2021) explains the underlying event study specification for the coefficients and variance-covariance matrix used below. We load the stored estimates since the underlying microdata is not available; further note the referenced beta and sigma objects only contain the entries corresponding to the event study coefficients. Now we construct robust confidence intervals for DeltaRM(Mbar). In the R Vignette, the test uses option bound set to "deviation from linear trend"; here only the analogue to "deviation from parallel trends" has been implemented.

. tempname beta sigma

. mata {

st_matrix(st_local("beta"), _honestExampleBCBeta())

st_matrix(st_local("sigma"), _honestExampleBCSigma())

}

. local opts mvec(0.5(0.5)2) gridPoints(100) grid_lb(-1) grid_ub(1)

. honestdid, numpre(4) b(`beta') vcov(`sigma') `opts'

The results are printed to the Stata console and saved in a mata
object. The user can specify the name of the mata object via the
mata() option. The default name is HonestEventStudy and the
object's name is saved in s(HonestEventStudy). In addition
to the CI, all the inputs and options are saved:

. mata `s(HonestEventStudy)'.CI

. mata `s(HonestEventStudy)'.betahat

. mata `s(HonestEventStudy)'.sigma

. mata `s(HonestEventStudy)'.numPrePeriods

. mata `s(HonestEventStudy)'.numPostPeriods

. mata `s(HonestEventStudy)'.prePeriodIndices

. mata `s(HonestEventStudy)'.postPeriodIndices

. mata `s(HonestEventStudy)'.open

. mata `s(HonestEventStudy)'.options.alpha

. mata `s(HonestEventStudy)'.options.l_vec

. mata `s(HonestEventStudy)'.options.Mvec

. mata `s(HonestEventStudy)'.options.rm

. mata `s(HonestEventStudy)'.options.omit

. mata `s(HonestEventStudy)'.options.method

. mata `s(HonestEventStudy)'.options.Delta

. mata `s(HonestEventStudy)'.options.grid_lb

. mata `s(HonestEventStudy)'.options.grid_ub

. mata `s(HonestEventStudy)'.options.gridPoints

For ease of use, the package also provides a way to plot the CIs
using the coefplot package. This can be done when the CIs
are computed or using the results cached in mata.

. honestdid, coefplot cached

. honestdid, coefplot cached xtitle(Mbar) ytitle(95% Robust CI)

. graph export coefplot.pdf, replace

Example 2: Lovenheim and Willen (2019)

Section 6.3 of Rambachan and Roth (2021) explains the underlying event study specification for the regression below, which is based on Equation (20) (also see p. 11 of the HonestDiD Vignette). The data is the same one provided in the HonestDiD R package and can be downloaded by installing honestdid with the all option. Since the data is available, we run the regression using reghdfe and then use the resulting estimates.

. use LWdata_RawData.dta, clear

. mata stata(_honestExampleLWCall())

. honestdid, pre(1/9) post(10/32) coefplot

(As noted above, this requires the user package reghdfe.) Note
we did not need to specify the coefficient vector or the
variance-covariance vector, and instead the function took the stored
results e(b) and e(V) from reghdfe to do the
computations. Further, the coefficient plot was created using the
coefplot package.

Now to mirror the Vignette:

. matrix b = 100 * e(b)

. matrix V = 100^2 * e(V)

. mata st_matrix("l_vec", _honestBasis(15 - (-2), 23))

. local opts delta(sd) mvec(0(0.005)0.04) l_vec(l_vec)

. local plot coefplot xtitle(M) ytitle(95% Robust CI)

. honestdid, pre(1/9) post(10/32) b(b) vcov(V) `opts' `plot'

. graph export coefplot.pdf, replace

Stored results

honestdid stores the following in s():

Macros

s(HonestEventStudy) honestdid results mata object

The following data are available in s(HonestEventStudy) (default name: HonestEventStudy):

real matrix CI
Matrix with M in first column, original CI and robust CIs in columns 2, 3

real vector betahat
coefficient vector (pre and post period coefficients only)

real matrix sigma
vcov matrix (pre and post period vcov matrix only)

real vector prePeriodIndices
pre period indices of coef vector

real vector postPeriodIndices
post period indices of coef vector

real vector open
vector for whether CI is open at endpoint (0 not open, 1 at lower, 2 at upper, 3 at both)

struct _honestOptions scalar options
structure with options used in internal computations

The following data are available in s(HonestEventStudy).options (default name: HonestEventStudy.options):

real scalar alpha
1 - confidence level

real vector l_vec
vector with parameters of interest (default is first period post event)

real vector Mvec
vector with M values

real scalar rm
whether relative magnitudes were requested

real scalar grid_lb
lower bound for grid search (ignored with FLCI)

real scalar grid_ub
upper bound for grid search (ignored with FLCI)

real scalar gridPoints
number of grid points

string scalar Delta
type of Delta (DeltaSD or DeltaRM)

string scalar method
method used (C-LF, FLCI, Conditional, C-F)

References

See the HonestDiD Vignette and the paper by Rambachan and Roth (2021).