*! version 1.1 5nov2019
help stackreg and xtstackreg

Title

stackreg and xtstackreg -- Stacked linear regression analysis to facilitate testing of multiple hypotheses

Syntax

stackreg depvars = indepvars [if] [in] [weight] [, options]

xtstackreg depvars = indepvars [if] [in] [weight] [, options]

Variables

Model
depvars left-hand-side variables

indepvars right-hand-side variables

options

Main
noconstant suppress constant term

constraints(numlist) apply specified linear constraints

nocommon keep observations with any non-missing values in depvars

Panel Data
fe apply within-transformation to depvars and indepvars (equiv. to using xtstackreg)

SE/Inference
cluster(clustvarlist) estimate clustered standard errors (level of clustering higher than obs. unit)

df(dftype) degrees-of-freedom adjustment (dftype may be adjust, raw, or areg)

wald use Wald- instead of of F-test after stackreg

Speed
sreshape use sreshape to increase speed

Reporting
level(#) set confidence level; default as set by set level

edittozero(#) edit coefficient covariance matrix for roundoff error (zeros); see mata edittozero()

omitted display omitted collinear variables

emptycells display empty cells for interactions of factor variables

display_options further options for displaying output

depvars and indepvars may contain factor variables; see fvvarlist.

display_options are those available for ereturn display.

The prefix commands bootstrap and jackknife are allowed; by and svy are not allowed; see prefix.

aweights, fweights, iweights, and pweights are allowed, pweights is the default; see weight.

The available postestimation commands are (almost) the same as for regress; see
regress postestimation.

predict and margins behave in the same way as they behave after mvreg; see mvreg postestimation.

Description

stackreg implements the stacked regression analysis which facilitates statistical testing in a multiple testing framework.
The stacked regression approach was suggested e.g. by Weesie (1999) and Pei et al. (2019).
stackreg is closely realted to the real Stata command suest.
Unlike suest, which is extremely flexible in allowing inference involving regression models of different type, stackreg is confined to the linear model.
However, in the context of the linear model, stackreg is more flexible than suest in several respects.
In detail: (i) stackreg accomodates multi-way clustering (Cameron et al., 2011),
if the community-distributed command cgmreg (by Jonah B. Gelbach and Douglas L. Miller) is installed;
(ii) stackreg allows imposing cross-equation constraints by specifying the option constraints();
(iii) stackreg is a panel data command that accomodates fixed-effects estimation;
(iv) unlike suest, stackrg applies a degrees-of-freedom adjustment that exactly reproduces the standard errors equation-by-equantion estimation yields;
(v) stackreg allows for factor-variables in depvars.
stackreg can also be regared as more robust alternative to sureg and mvreg in particular.
Whlie these commands implement an FGLS estimator and, hence, rely on strong assumptions when estimating cross-equation coeffient covariances, stackreg uses clustering in the same fashion as suest.
The stacked regression approach may alternatively implemted using the data management tool stack.
Implementing the stacked regression approach on basis of stack is however cumbersome, in particular with panel fixed-effects estimation.
Technically stackreg runs a simple OLS regression in which the left-hand-side variable is the stacked variables in depvars,
while the variables in indepvars enter the right-and side as a saturated set of interactions with indicators for each element of indepvars.
In terms of the estimated coefficients and standard errors (see options SE/Inference) this is fully equivalent to separately regressing each element of depvars on indepvars,
unless cross-equation restrictions are imposed on the coefficients.
However, unlike separate regressions, the stacked approach inherently accommodates estimating coefficient covariances across equations.
This is of major importance for testing hypotheses that involve coefficients from more than one equation.
stackreg is hence not an estimation procedure in its own right, but a procedure that prepares the ground for jointly testing multiple hypotheses.
After running stackreg, test or testparm can be used in the usual fashion to test hypotheses that involve coefficients from different equations.
xtstackreg is the same as stackreg, fe.

Variables

Model

depvars specifies the list of dependent variables in the stacked regression.
depvars may include factor variables and hence allows for straightforwardly considering interactions and polynomials in the regressions that precedes the joint test of multiple hypotheses.

indepvars specifies the list of independent variables in the stacked regression.
In a very basic setting of a balancing check, indepvars consists of a single treatment indicator.
Yet, more ivolved analyses may require a more complex specification of indepvars.
One example is a difference-in-differences setting,
where the common trend assumption implies that the interaction of the post-treatment-period indicator (post) and treatment-group indicator (tgroup) has no explanatory power for any element of depvars.
In this example indepvars is specified as post##tgroup and the joint null hypothesis can be tested with testparm post#tgroup after running stackreg; see Example 1.
indepvars may include factor variables.

Options

Main

noconstant makes stackreg suppress the constant terms in the stacked regression.

constraints(numlist) makes stackreg apply the linear constraints specified by numlist.
numlist needs to comply with Stata's numlist syntax; i.e. 1/3 is allowed for referring to the constraints 1, 2, and 3, while 1-3 is not allowed.
The specified constraints need to be defined in advance using constraint.
The syntax for defining the constraints has to be of the form [depvar]indepvar.
That is in order to identify a coefficient on which a restriction is imposed, both the equation (dependent variable) and the right-hand-side variable need to be specified.
Factor variables syntax is allowed for specifying constraints, e.g. [c.lfare#c.lfare]1998.year = 0.
Any linear constraints are allowed including cross-equation restrictions.
Option constraints() cannot be combined with multi-way clustering.
If constraints() is specified, and noconstant is not specified, stackreg estimates an overall constant and drops the equation-specific constant from the final equation.

nocommon makes stackreg use observations for which information on some variables in depvars is missing.
The default is to consider only observations for which information on all variables in depvars is available.
That is, by default the estimation sample and the number of observations is homogeneous across equations.
With nocommon specified, stackreg selects the estimation sample on a equation-by-equation basis,
i.e. the number of observations that enter the regression analysis may vary across the left-hand-side variables.
The information about whether or not the estimation sample is heterogeneous across equations is saved in e(common).

Panel Data

fe makes stackreg use within-transformed variables rather than their levels when estimating the stacked regression.
That is with option fe, stackreg allows for individual fixed effects.
fe requires that the data is declared to be panel data using xtset.
stackreg with option fe is fully equivalent to xtstackreg (with and without option fe, i.e. fe has no effet with xtstackreg).
Providing a separate xt command is just to make more salient that stackreg can be used with panel data.
xtstackreg requires stackreg to be installed.

SE/Inference

cluster(clustvarlist) makes stackreg cluster the standard errors (and covariances) at a higher level than the original unit of observation.
By default, an identifier of the original observations serves as clustvar, since stacking the regression makes each original sampling unit contribute several observations to the stacked regression analysis.
stackreg accomodates multi-way higher-level clustering, i.e. clustvarlist may consist of more than one variable.
Multi-way clustering requires the community-contributed command cgmreg (by Jonah B. Gelbach and Douglas L. Miller, later versions by Judson Caskey) to be installed.
stackreg has been tested with cgmreg version 3.0.0 (by J.B. Gelbach and D.L. Miller).
Other versions of cgmreg may behave differently and might make stackreg fail or produce incorrect results.
Multi-way clustering combined with option constraints().

df(adjust|raw|areg) specifies the type of degrees-of-freedom adjustment stackreg applies. df(adjust) is the default.
With df(adjust),
stackreg adjusts the degrees-of-freedom correction such that the reported standard errors coincide with those one gets from separately regressing the elements of depvars on indepvars, using regress, robust.
This, depending on how the option cluster() is specified, likewise applies to the standard errors one gets from regress, cluster() and cgmreg, cluster(), respectively.
In the most simple case (no higher-level clustering, no panel data, homogeneous number of obs. across depvars) the initially estimated variance-covariance matrix is adjusted by the factor (N-1)/(N-1/G),
with N denoting the genuine number of observations, and G denoting the number of variables in depvars.
(With multi-level clustering and option nocommon, the match with the standard errors from cgmreg may not be perfect;
see Cameron et al. (2011) for different approaches to the degree-of-freedom correction in a multi-level-clustering setting; some are based on internal results not accessible via what cgmreg saves in e().)
For xtstackreg the default, i.e. df(adjust), is to adjust the degrees-of-freedom correction such that the standard error coincide with those from xtreg, fe robust and xtreg, fe cluster(), respectively.
This implies that xtstackreg by default clusters the standard errors at the level of panelvar, what is also the default with xtreg, fe robust.
If df(areg) is specified, xtstackreg adjusts the degrees-of-freedom such that the standard errors match those from areg,
absorb(panelvar) robust and areg, absorb(panelvar) cluster(), respectively.
That is with df(areg), stackreg does not cluster the standard errors at the level of panelvar unless this explicitely requested with cluster(panelvar).
df(areg) is ignored by stackreg if fe is not specified.
df(raw) prevents stackreg from adjusting the degrees-of-freedom correction to the stacked regression setting.

wald prevents stackreg from saving the residual degrees of freedom in e(df_r).
This makes test and testparm apply a Wald- rather than an F-test after stackreg.
With multi-way clustering and heterogeneous numbers of observations e(df_r) is never saved, because there is no (universal) answer to the question what the number of clusters is.
In consequence test and testparm apply a Wald-test in these cases.

Speed

sreshape makes stackreg, if installed, call the community-contributed command sreshape (by K.L. Simons) instead of reshape.
Since sreshape is much faster than reshape (Simons 2016) in many settings, specifying sreshape may speed up stackreg.

Reporting

level(#); see [R] estimation options. One may change the reported confidence level by retyping
stackreg without arguments and only specifying the option level(#).

edittozero(#) specifies how small the numeric deviation from zero of an element of the estimated variance-covariance needs to be in order to set this element to the value of zero.
The specified value is just passed through to the mata function edittozero(); see [M-5] edittozero().
Minimal editing that is edittozero(1) is the default.
The different estimation commands that are alternatively called by stackreg may differ with respect to how estimated coefficient variances that are close to zero are dealt with.
Specifying edittozero() aligns their behaviors.

omitted specifies that variables that were omitted because of collinearity are displayed and labeled as "(omitted)".
The default is not to display them, i.e. noomitted.

emptycells specifies that empty cells for interactions of factor variables are displayed and labeled as "(empty)".
The default is not to display them, i.e. noemptycells.

For further display_options, see [R] estimation options.

Example 1

(Wooldridge, 2012, p. 456; difference-in-differences analysis, effect of new garbage incinerator on house prices)

Load data

. use "http://fmwww.bc.edu/ec-p/data/wooldridge/kielmc.dta", clear

Regression of primary interest (difference-in-differences with controls)

. regress rprice age c.age#c.age intst area land rooms baths y81##nearinc

Stacked balancing regression

. stackreg age c.age#c.age intst area land rooms baths = y81##nearinc

Test of joint significance of interaction of post-treatment-period indicator y81 and treatment-group indicator nearinc

. testparm y81#nearinc

Example 2

(Wooldridge, 2012, p. 506-507; fixed-effects estimation, effect of market concentration on flight fares; second outcome lpassen (log-number of passengers) added)

Load data

. use "http://fmwww.bc.edu/ec-p/data/wooldridge/airfare.dta", clear

Stacked fixed-effects estimation (standard errors match those from xtreg, fe robust)

. xtstackreg lfare lpassen = concen i.year

Test of null that market concentration neither affects the fare nor the number of passengers

. test concen

Same as above with standard errors that match those from areg, absorb(id) robust

. xtstackreg lfare lpassen = concen i.year, df(areg)

. test concen

Same as above with two-way (origin and destination) clustering (cgmreg called from stackreg)

. egen gorigin = group(origin)

. egen gdestin = group(destin)

. xtstackreg lfare lpassen = concen i.year, cluster(gorigin gdestin)

. test concen

Saved results

stackreg and xtstackreg save the following in e():

Scalars

e(N) number of observations (not expanded by stacking)

e(k_eq) number of equations in e(b)

e(N_g) number of groups (only saved with xtstackreg or option fe)

e(rank) rank of e(V)

e(N_stack) number of observations in stacked regression

e(N_clust) number of clusters

e(df_r) residual degrees of freedom (only saved if wald ist not specified and e(common) : "common" and e(estimator) : "regress")

e(df_m) model degrees of freedom (not saved if e(common) : "nocommon") or e(estimator) : "cnsreg")

e(N_l) number of observations lth equation (only saved if e(common) : "nocommon")

e(rank_l) rank of lth block (lth equation) of e(V) (only saved if e(common) : "nocommon" or e(estimator) : "cnsreg")

e(df_r_l) residual degrees of freedom lth equation (only saved if e(common) : "nocommon")

e(df_m_l) model degrees of freedom lth equation (only saved if e(common) : "nocommon" or e(estimator) : "cnsreg")

e(level) confidence level

Macros

e(title) Stacked Regression

e(cmdline) command as typed

e(cmd) stackreg or xtstackreg

e(depvar) names in depvars

e(eqnames) names in depvars

e(estimator) regress, cnsreg, or cgmreg

e(model) either ols or fe

e(common) either common or nocommon (nocommon indicates that the estimation sample varies across equations)

e(vcetype) Clust. Robust

e(marginsok) predictions allowed by margins

e(predict) program used to implement predict

e(properties) b V

Matrices

e(b) vector of estimated coefficients

e(V) estimated coefficient variance-covariance matrix

e(Cns) constraints matrix (only saved if e(estimator) : "cnsreg")

Functions

e(sample) marks estimation sample

References

Cameron, A., Gelbach, J. and Miller, D. (2011). Robust Inference With Multiway Clustering. Journal of Business & Economic Statistics 29(2), 238-249.

Pei, Z., Pischke, J.-S. and Schwandt, H. (2019). Poorly Measured Confounders are More Useful on the Left than on the Right. Journal of Business & Economic Statistics 37(2), 205-216.

Simons, K. L. (2016). A sparser, speedier reshape. Stata Journal 16(3), 632-649.

Wooldridge, J. M. (2002). Econometric Analysis of Cross Section and Panel Data. MIT Press.

Wooldridge, J.M. (2012). Introductory Econometrics: A Modern Approach, 5th edition. South-Western.

Weesie, J. (1999). Seemingly unrelated estimation and the cluster-adjusted sandwich estimator. Stata Technical Bulletin 52, 34-47.

Also see

Manual: [R] suest, [MV] mvreg, [R] test, [R] areg, [R] cnsreg, [R] sureg, [XT] xtset

Help: [R] suest, [MV] mvreg, [R] test, [R] areg, [R] cnsreg, [R] sureg, [XT] xtset, cgmreg, sreshape

Authors

Michael Oberfichtner

Institute for Employment Research (IAB)

Nürnberg,
Germany

E-mail: Michael.Oberfichtner2@iab.de

Harald Tauchmann

Friedrich-Alexander-Universität Erlangen-Nürnberg (FAU)

Nürnberg,
Germany

E-mail: harald.tauchmann@fau.de

Disclaimer

This software is provided "as is" without warranty of any kind, either expressed or implied. The entire risk as to the quality and
performance of the program is with you. Should the program prove defective, you assume the cost of all necessary servicing, repair or
correction. In no event will the copyright holders or their employers, or any other party who may modify and/or redistribute this software,
be liable to you for damages, including any general, special, incidental or consequential damages arising out of the use or inability to
use the program.

Acknowledgements

We would like to thank Julia Lang, Johannes Ludsteck, Sabrina Schubert, and an anonymous reviewer for many valuable comments and suggestions.
Excellent research assistance from Irina Simankova is gratefully acknowledged.