macro newrob y x.1-x.k betahat w mconstant k hbar arc sumr0 sumr1 medr maxiter iter tol mcolumn y x.1-x.k res pi w0 w d d2 absor betahat noecho #This is a program to perform the robust regression procedure of Chatterjee and #Machler. Input is y and k regressorsx.1 - x.k brief 0 # to suppress output from intermediate regressions #get initial weights and set the step 1 estimates regr y k x.1-x.k; resi res; hi pi. let hbar=sum(pi) / count(pi) rmax pi hbar w0 let w0=1/w0 #these are the initial weights regr y k x.1-x.k; resi res; weights w0. let sumr0=sum(res**2) #get sum of squared residuals. let arc=10 #set the absolute relative change in sum of squared residuals to a high value let maxiter=10 let iter=1 let tol=0.001 while (arc gt tol ) and (iter le maxiter) # this controls the looping #get the new weights for the second step let d=(1-pi)**2 let absor=abso(res) #get the absolute value of the n residuals let medr=medi(absor) #this is the median of the absolute residual rmax absor medr d2 let w=d/d2 #these are step 2 weights regr y k x.1-x.k; resi res; coef betahat; weights w. let sumr1=sum(res**2) let arc=abso(sumr1 - sumr0)/sumr0 let iter=iter+1 let sumr0=sumr1 endwhile if arc le tol brief 2 let iter=iter-1 print arc iter note note This is the final C-M robust analysis note regr y k x.1-x.k; weight w; coef betahat. else note note The irls method failed to converge note the final values of the coefficients are : note print betahat note note The last value of the absolute relative change in the sum note of squared residuals is : note print arc endif echo endmacro