*! version 1.0.0 15may2026

Title

harreg -- Time-series regression with HAR standard errors and fixed-b inference

Syntax

harreg depvar [indepvars] [if] [in]
[, options]

Model
noconstant suppress constant term

HAR
estimator(type) LRV estimator: ewc, ewp, nw, or qs; default is ewc

lags(#) sets the truncation parameter S for nw or qs (for nw, Bartlett weights are nonzero at lags 1 to S-1)

df(#) degrees of freedom parameter nu for ewc, ewp, or qs

Inference
level(#) set confidence level; default is level(95)

critdraws(#) Monte Carlo draws for nw/qs critical values; default is 5000

seed(#) random-number seed for simulations

Reporting
noheader suppress the table header

notable suppress the coefficient table

You must tsset your data before using harreg; see [TS] tsset.

depvar and indepvars may contain time-series operators (see tsvarlist)
and factor-variable notation (see fvvarlist); for example,
harreg y x i.region c.x##c.x.

Description

harreg fits a time-series regression by OLS and reports
heteroskedasticity- and autocorrelation-robust (HAR) standard errors
based on fixed-b asymptotics, as recommended by
Lazarus, Lewis, Stock, and Watson (LLSW, 2018) and Lazarus, Lewis, and Stock (LLS, 2021).

The default estimator is the equal-weighted cosine (EWC) with
nu = floor(0.41*T^(2/3)), as recommended by LLSW (2018).
Alternative long-run variance (LRV) estimators include
equal-weighted periodogram (EWP),
Newey-West/Bartlett (NW), and
quadratic spectral (QS).

The default rules for the truncation parameter (nw, qs) and
degrees of freedom (ewc, ewp) are designed to optimize the
tradeoff between test size (controlling the probability of false rejection)
and size-adjusted power, following LLSW (2018).

For ewc and ewp, inference uses t(nu) and F(m,nu-m+1)
reference distributions, where m is the number of restrictions tested.
For nw and qs, harreg simulates the fixed-b null distribution
to obtain p-values and critical values.

Options

Model

noconstant suppresses the constant term (intercept) in the model.

HAR

estimator(type) specifies the long-run variance estimator.
type may be ewc (equal-weighted cosine, the default),
ewp (equal-weighted periodogram),
nw (Newey-West/Bartlett), or
qs (quadratic spectral).

lags(#) specifies the truncation parameter S for the nw or qs kernel estimators.
The default for nw is S = ceil(1.3*sqrt(T)).
The default for qs is S = ceil(T/nu) where nu = floor(0.41*T^(2/3)).
These defaults are chosen to optimize the tradeoff between
test size and size-adjusted power, as derived in LLSW (2018) and LLS (2021).
If lags() is specified for orthonormal series estimators ewc or ewp,
the option will be ignored and the default will be used.

df(#) specifies the degrees of freedom parameter nu for the ewc or ewp
orthonormal series estimators.
The default is nu = floor(0.41*T^(2/3)), chosen to optimize the tradeoff
between test size and size-adjusted power following LLSW (2018, eq. (4)) and LLS (2021).
For ewp, nu is restricted to be even; any odd-number input will be
rounded down to the nearest even integer.
df(#) may also be specified for qs; if lags() is also specified,
lags() takes precedence, and otherwise S = ceil(T/nu).

Inference

level(#) specifies the confidence level, as a percentage, for
confidence intervals. The default is level(95) or as set by
set level.

critdraws(#) specifies the number of Monte Carlo draws used
to simulate fixed-b critical values when the estimator is nw or qs.
The default is 5000; the minimum is 1000.

seed(#) specifies the random-number seed for simulations.
The default ensures reproducible critical values across runs.
Specify seed(0) to use a different random seed each time.

Reporting

noheader suppresses the display of the header above the
coefficient table.

notable suppresses the display of the coefficient table.

Remarks

harreg requires the time variable to be regularly spaced with no gaps.

After harreg, you can use harwald for joint Wald tests of
coefficients with fixed-b critical values.
predict is available with options
xb (fitted values, the default) and residuals.

Use harwald for coefficient tests: it applies the fixed-b
reference distribution that matches the estimator chosen at the
harreg call, whereas general post-estimation commands would
use a standard reference distribution.

harreg fits linear regression models by OLS; instrumental-variables
estimation is not supported.

Examples

Setup

. webuse lutkepohl2

. tsset

Basic HAR regression using default EWC estimator

. harreg dln_inv dln_inc dln_consump

Newey-West estimator with truncation parameter S = 8

. harreg dln_inv dln_inc dln_consump, estimator(nw) lags(8)

EWP estimator with specified degrees of freedom

. harreg dln_inv dln_inc dln_consump, estimator(ewp) df(20)

Joint Wald test after estimation

. harwald dln_inc dln_consump

Stored results

harreg stores the following in e():

Scalars

e(N) number of observations

e(df_m) model degrees of freedom

e(df_r) residual degrees of freedom

e(rank) rank of e(V)

e(r2) R-squared

e(r2_a) adjusted R-squared

e(rmse) root mean squared error

e(mss) model sum of squares

e(rss) residual sum of squares

e(tss) total sum of squares

e(ll) log likelihood

e(bw) truncation parameter S (nw/qs) or degrees of freedom nu (ewc/ewp)

e(df_fb) fixed-b degrees of freedom

e(cv_fb) fixed-b critical value at e(level)

e(level) confidence level

e(F_fb) model F statistic (fixed-b)

e(p_fb) p-value for model F

e(cvF_fb) critical value for model F at e(level)

e(F) model F statistic (regress-style alias of e(F_fb))

Macros

e(cmd) harreg

e(cmdline) command as typed

e(title) title for output

e(depvar) name of dependent variable

e(estimator) LRV estimator used

e(vce) HAR sub-method (har ewc, har nw, etc.)

e(vcetype) HAR

e(properties) b V

e(predict) program used to implement predict

Matrices

e(b) coefficient vector

e(V) variance-covariance matrix of estimators

e(se) standard errors

e(t) t statistics

e(p) p-values

e(ci_lo) lower confidence bounds

e(ci_hi) upper confidence bounds

Functions

e(sample) marks estimation sample

References

Lazarus, E., D. J. Lewis, J. H. Stock, and M. W. Watson. 2018.
HAR inference: Recommendations for practice.
Journal of Business & Economic Statistics 36: 541-559.

Lazarus, E., D. J. Lewis, and J. H. Stock. 2021.
The size-power tradeoff in HAR inference.
Econometrica 89: 2497-2516.

Sun, Y. 2013.
A heteroskedasticity and autocorrelation robust F test using an orthonormal
series variance estimator.
Econometrics Journal 16: 1-26.

Ye, X., and Y. Sun. 2018.
Heteroskedasticity- and autocorrelation-robust F and t tests in Stata.
Stata Journal 18: 951-980.

Acknowledgements

This command builds on the har command provided by Xiaoqing Ye and
Yixiao Sun and the neweyfixedb command provided by Tim Vogelsang.
We thank the authors of those commands.

Authors

Eben Lazarus, UC Berkeley

lazarus@berkeley.edu

Daniel J. Lewis, University College London

daniel.j.lewis@ucl.ac.uk