You are now following this Submission
- You will see updates in your followed content feed
- You may receive emails, depending on your communication preferences
% PURPOSE: computes OLS and reports Robust SE, and Newey-West and Hansen-Hodrick adjusted heteroscedastic-serial consistent standard errors.
% Inputs:
% y = T x 1 vector, left hand variable data
% X = T x n matrix, right hand variable data
% L = number of lags to include in NW corrected standard errors
% H = number of lags to include in HH corrected standard errors
%
%Note: you must make one column of X a vector of ones if you want a
% constant.
% Output:
% beta = regression coefficients 1 x n vector of coefficients
% R2 = unadjusted
% R2adj = adjusted R2
% X2(Degrees of Freedom) = : Chi-squared statistic for all coefficients
% jointly zero.
% std = corrected standard errors.
% t_ = t-stat for NW and HH
%Note: For chi-square test program checks whether first is a constant and ignores that one for
% test. If there is only one beta the program does not report X^2
% results since t_stat^2= X2.
%Note: program automatically displays outputs in an organized format. If you want
%to disable the automatic display just comment lines 129-136.
Cite As
Sandra (2026). OLS with Newey-West and Hansen-Hodrick SE (https://www.mathworks.com/matlabcentral/fileexchange/43259-ols-with-newey-west-and-hansen-hodrick-se), MATLAB Central File Exchange. Retrieved .
Acknowledgements
Inspired by: Newey-West Standard Errors
General Information
- Version 1.2.0.0 (2.34 KB)
MATLAB Release Compatibility
- Compatible with any release
Platform Compatibility
- Windows
- macOS
- Linux
| Version | Published | Release Notes | Action |
|---|---|---|---|
| 1.2.0.0 | Now you can get results for Newey West, Hansen Hodrick and Robust SE all at once. If there is only one beta the code does not report a chi-square statistic since it is just the square of the single t_stat. Overall, I cleaned up the code. |
||
| 1.1.0.0 | changed beta from a 1 by n vector to a n x 1 |
||
| 1.0.0.0 |
