ivhet.m (1335B)
1 % IVHET.m -- 2SLS procedure, with Weighted LS Het correction 2 % 3 % z == the variables to be used in constructing sigma_i: e.g. X or X^2 4 % 5 % Runs three regressions: 6 % ols ==> e 7 % e^2 on z with truncation at the 25th percentile 8 % wls 9 10 11 function [u,N,K,stdest,beta,vcv,robvcv] = ivhet(y,x,w,z,title,depv,indv,instv,zv); 12 13 e=iv(y,x,w,['2SLS: ' title],depv,indv,instv); 14 e2 = e.^2; 15 16 u=ols(e2,z,'Estimating variances','e2',zv); 17 N=length(u); 18 ybar = 1/N*(ones(N,1)'*e2); 19 rsq = 1-(u'*u)/(e2'*e2 - N*ybar^2); 20 TR2=N*rsq; 21 P=size(z,2); 22 fprintf('TR^2: %6.2f P-Value: %5.3f\n',[TR2 1-chi2cdf(TR2,P)]); 23 e2hat=e2-u; 24 e225=prctile(e2hat,25); % The 25th percentile 25 fprintf('The 25th percentile of the fitted e2: %8.5f\n',e225); 26 e2hat=replace(e2hat,e2hat<e225,e225); 27 28 shat=sqrt(e2hat); 29 30 ytil=y./shat; 31 xtil=div(x,shat); 32 wtil=div(w,shat); 33 [v,N,K,stdest,beta,vcv] = iv(ytil,xtil,wtil,['WLS: ' title],depv,indv,instv); 34 35 u = y-x*beta; 36 dof = N-K; 37 sigma2=u'*u/dof; 38 stdest=sqrt(sigma2); 39 ybar = 1/N*(ones(N,1)'*y); 40 rsq = 1-(u'*u)/(y'*y - N*ybar^2); 41 rbar = 1-sigma2/((y'*y - N*ybar^2)/(N-1)); 42 43 fprintf('R-Squared: %4.2f SSR: %8.4f\n',[rsq u'*u]); 44 fprintf('RBar^2: %4.2f S.E.E.: %8.4f\n',[rbar stdest]); 45 disp '============================================================================='; 46