Stata中使用的robust SE的MATLAB等效命令

MATLAB equivalent command of robust SE used in Stata

Stata中线性回归稳健标准误差的MATLAB等效命令是什么(例如reg y x, robust)?

我想 HAC 可能是答案 (http://www.mathworks.com/help/econ/hac.html)。

谁能展示一个简单的 MATLAB 示例,它可以生成与使用下面列出的 Stata 代码生成的结果相同的结果。

webuse iris, clear
reg  seplen sepwid
reg  seplen sepwid, r

在MATLAB中,我找到了robustfit(http://www.mathworks.com/help/stats/robustfit.html),但它应该不是等价的命令,因为它会影响估计的beta值的值,robustfit和稳健标准误差之间有什么关系?

正如 Nick Cox 在评论中所述,您不会使用 robustfit。相反,您将像下面使用 hac 的一小段代码一样单独估计稳健标准误差。使用 fitlm 命令找到系数估计值。

% Load/define data
load fisheriris;
sepwid = meas(:,2);
seplen = meas(:,1);

% Estimates
fit = fitlm(sepwid,seplen);
[~,SE,coef] = hac(fit,'type','HC','weights','HC1','display','off');

% Output non-robust
fit.Coefficients(:,1:2)

% Output Robust
[coef SE] 

请注意,MATLAB 将 constant/intercept 放在顶部而不是底部(如 Stata)。或者,您可以使用 Oleg Komarov (*) 的 regstats2,它也会为您提供 p 值等。

% Estimates
fit2 = regstats2(seplen,sepwid,'linear','all');

% Output
[fit2.beta fit2.hc1.se]

(*) http://www.mathworks.com/matlabcentral/fileexchange/26169-regstats2