View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from

Join the 15-year community celebration.

Play games and win prizes!

» Learn more

5.0 | 1 rating Rate this file 27 Downloads (last 30 days) File Size: 77.4 KB File ID: #26169 Version: 1.9
image thumbnail



Oleg Komarov (view profile)


22 Dec 2009 (Updated )

Regstats enhanced. Robust std.errors; loops on a matrix of responses, 'onlydata' model.

| Watch this File

File Information

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.



This file inspired Forecasting The Ftse 100 With High Frequency Data: A Comparison Of Realized Measures.

Required Products Statistics and Machine Learning Toolbox
MATLAB release MATLAB 7.9 (R2009b)
Other requirements Should work on previous releases. For compatibility issues refer to the original fcn.
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (13)
11 Oct 2012 ZENG YU


22 Feb 2012 Sven Thies

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

Comment only
22 Feb 2012 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!

Comment only
01 May 2011 Oleg Komarov

Oleg Komarov (view profile)

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


Comment only
04 Apr 2011 Fernando Duarte

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,

Comment only
14 Feb 2010 Oleg Komarov

Oleg Komarov (view profile)

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).

Comment only
11 Feb 2010 Oleg Komarov

Oleg Komarov (view profile)

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...

Comment only
11 Feb 2010 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

Comment only
11 Feb 2010 Oleg Komarov

Oleg Komarov (view profile)

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

Comment only
10 Feb 2010 Oleg Komarov

Oleg Komarov (view profile)

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.

Comment only
05 Feb 2010 Oleg Komarov

Oleg Komarov (view profile)

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

Comment only
05 Feb 2010 Oleg Komarov

Oleg Komarov (view profile)

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...



Comment only
27 Jan 2010 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;


Comment only
22 Dec 2009 1.1

Eliminated useless folder in the .zip file

05 Jan 2010 1.4

Added link to FEX page inside the help

15 Jan 2010 1.5

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.

05 Feb 2010 1.6

Per Dajun Tuo suggestion: fixed assignment error between dissimilar structures

11 Feb 2010 1.7

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.

15 Feb 2010 1.8

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.

01 Oct 2011 1.9

Added QLIKE loss functions as in Patton (2011b)

Contact us