File Exchange

image thumbnail


version (77.4 KB) by Oleg Komarov
Regstats enhanced. Robust std.errors; loops on a matrix of responses, 'onlydata' model.


Updated 01 Oct 2011

View License

This enhanced version of regstats has implemented several methods to estimate robust standard errors for coefficients:

- HC0: White robust t statistics (Eicker,1963,1967; Huber,1967; White,1980)
- HC1: With dfe correction (Hinkley,1977)
- HC2: White weighted by 1-h (MacKinnon & White,1985)
- HC3: White weighted by (1-h)^2 (Davidson & MacKinnon,1993)
- HC4: White weighted by (1-h)^delta (Cribari & Neto,2004)
- HAC: Newey West t statistics (Newey & West,1987)

Other fields (available from p5v2; visible from p5v5):
- 'empty': if the regression is performed on all NaN series the regstats2 skips the computations and sets to true this field.
- 'rankdef': if after the autoremoval of the NaNs, the design matrix is rank defiecient, regstats2 skips the computations and sets his field to true.

Those fields are meant to easily individuate those series that would otherwise interrupt the looping of the regression.

This fcn allows to supply a matrix of responses, where each columns is considered as a distinct series, instead of just a vector. The engine will loop through each column returning a set of results for each regression.

From p5v6 the MODEL argument can also be 'onlydata'. Under this option the DATA is left as it is (no constant or interaction terms are addded).

From p5v7 QLIKE loss function as in Patton (2011b).

- The GUI is oversized due to the additions. Use the Help to choose the statistics and supply a cellarray with the names of the statistics.

For major details see the help of the fcn
The published M-file contains a direct comparison with the original regstats fcn.

Comments/suggestions/error reports are welcome.


Comments and Ratings (13)



Sven Thies

I'm sorry. I just saw the post of Baltas and your answer.
Kind regards

Sven Thies

Dear Mr. Komarov,

I am just searching the Internet for an application to compute the HAC-Standard Error of Newey and West (1987) that I want to use to calculate an unbiased t-statistic of a sample I created.
The sample contents Buy-and-Hold excess returns of Firms over periods larger then 2 years. With a limited data sample you will only have enough observations when the Formation- and Holding periods are overlapping.
The question is now how I can extract the HAC standard error from your script regstats2.m to calculate the t-statistic with a robust standard error or especially if that’s possible.

I tried to write a PN but that didn't work. (Unknown e-mail address)

Thanks for the Help!

edit regstats2 >> on line 515 you can change "L = round(4*(nobs/100)^(2/9));"


Dear Oleg, thanks for your code, it's great. I have a question, how can I change the lags for the HAC estimator? What's the default?

Thanks a lot and keep up the good work,

Oleg Komarov

I didn't understand Baltas' point. Next release will allow to regress the responses on the sole matrix of regressors without adding a constant (the model argument should be supplied as 'onlydesign', or something similar).

Oleg Komarov

Dear Baltas,
I kindly ask you to post here only those comments strictly related to code problems but you can always send me an email.

You're missing the point of regression analysis. In words you're saying that some values are equal to themselves...

Nick Baltas

Hi Oleg,

great stuff.

I am doing portfolio evaluation and I have a time-series of monthly returns. These are autocorrelated, given the formation algorithm that I am using. I need to get the t-stats and adjust for autocorrelation. I am using your function to regress my data on a contanct, thus, I am using: regstats2(data,zeros(length(data),1),'linear',{'beta','hac'}), since linear model will add the constant on its own, hence I am adding some artificial zero-constant regressor, otherwise I cannot make the function work (e.g. have an empty matrix).

The outcome when it comes to betas is correct, i.e. the constant term is indeed the mean of my series..however all the elements of hac field are NaN, and I suspect that this comes from the zero vector used in the function call....

To cut a long story short...regressing on a single constant and getting the Newey-west st.error, is it feasible??

Thanks a lot,

HAC t-stats but si

Oleg Komarov

Bug fixed...I just noted that it's not totally clear in the Updates section.

Oleg Komarov

Bug in hc3 if called with hc2. Bug in hc4 if called with hc3 or with hc2. I will update asap. Also I'll made visible the empty and rankdef fields.

Thanks for the report Dajun Tuo.
Fixed the bug...waiting for update.

Can you write the entire line used to call regstats2 and the result of whos on the inputs, please?

I'm not sure if I already fixed this problem but forgot to update...



Dajun Tuo


I just used your sample but returned a error msg:

Subscripted assignment between dissimilar structures.

Error in ==> regstats2 at 501
allSeriesStats(ser) = stats;



Added QLIKE loss functions as in Patton (2011b)

Per Nick Baltas suggestion: added 'onlydata' model which leaves data as it is. Added warning in case R^2 or F stat is requested under this model.

Per Sebastian Eisenbach suggestion: empty and rankdef fields are now 'visible'.
Bug in hc3 and hc4 if called together or with hc2. Edited help and description.

Per Dajun Tuo suggestion: fixed assignment error between dissimilar structures

Added hidden fields 'empty' and 'rankdef'. If the responses are an n by m matrix and all NaN series (or after NaN removal rank deficient design matrix) are present, regstats skips those series setting to true those fields.

Added link to FEX page inside the help

Eliminated useless folder in the .zip file

MATLAB Release Compatibility
Created with R2009b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Discover Live Editor

Create scripts with code, output, and formatted text in a single executable document.

Learn About Live Editor