PROC HUF * Procedure to perform Robinson's Heteroskedasticity of Unknown Form Estimator * by K.J. White SET NODOECHO * Inputs: * DEPVAR: name of dependent variable * INDEPS: names of independent variables * ZVARS: names of variables in the Z matrix (may be same as INDEPS) * N: number of observations * K: number of neighbors to use * ZCOLS: number of columns in the ZVARS matrix * Scratch Variables * U_ UU_ CL_ SIG2I_ SIG2_ W_ Z_ ZI_ K1_ NORM_ NONE_ KONE_ T_ * IF YOU WANT TO SEE INTERMEDIATE OUTPUT UNCOMMENT THE PRINT STATEMENTS ?OLS [DEPVAR] [INDEPS] / RESID=U_ GENR UU_=U_**2 DIM SIG2_ [N] * Define the Cl constants DIM NONE_ [N] ZONE_ [ZCOLS] * GET A VECTOR OF N ONES AND ANOTHER VECTOR OF K ONES, DIM MAKES THEM ZERO MATRIX NONE_=NONE_+1 MATRIX ZONE_=ZONE_+1 GENR K1_=[K]+1 ?DO #=1,[N] * PUT ALL THE ZVARS IN Z_ COPY [ZVARS] Z_ * PULL OUT OBSERVATION I OF Z_ MATRIX ZI_=Z_(#,0) * SUBTRACT OBSERVATION I FROM EACH ROW OF Z_ MATRIX Z_=Z_-NONE_*ZI_ * COMPUTE NORM FOR EACH OBSERVATION MATRIX NORM_=(Z_**2)*ZONE_ * NEXT WE NEED TO FIND THE K ELEMENTS OF NORM_ THAT ARE SMALLEST * GENERATE A TIME INDEX TO USE FOR SORT INDICATORS GENR T_=TIME(0) ?SORT NORM_ T_ * NOW OBS 2 TO K+1 OF T_ SHOW WHICH ELEMENTS TO USE *PRINT NORM_ T_ GENR CL_=0 * FIRST SET ALL ELEMENTS OF CL_ TO ZERO * THEN SET THE ONES YOU WANT TO 1/K ?DO %=2,K1_ IF(TIME(0).EQ.T_(%)) CL_=1/[K] ?ENDO *PRINT CL_ * SIG2I is a 1x1 element MATRIX SIG2I_=CL_'UU_ GEN1 SIG2_:#=SIG2I_ ?ENDO * For fun show the results at the last observation PRINT NORM_ T_ * Now run Weighted Least Squares GENR W_=SQRT(SIG2_) OLS [DEPVAR] [INDEPS] / WEIGHT=W_ PRINT SIG2_ SET DOECHO PROCEND