function hc=correcthc(reg,res)

% main procedures which activates the computation of robust standard errors

[nt,d]= size(reg);
b     = zeros(d,1);
bmat  = zeros(d,d);
vstar = zeros(nt-1,d);
vmat  = zeros(nt,d);

% First construct the matrix z_t*u_t.

for i=1:d
    vmat(:,i)=reg(:,i).*res;
end

hc = vmat'*vmat/(nt-d); %HETERO robust
    