procedure RegHeteroTests
local integer lm exlm
local vect[integer] selreg
local series usq logusq
local rect[integer] fulltable seltable
local integer nselect i j

dbox(action=define,title='Regression-Based Tests')
dbox(stext='Which Tests Do You Want?')

dbox(checkbox='u**2 form') lm
dbox(checkbox='log u**2 form') exlm

dbox(stext='Select Regressors',special=gap)
dbox(scroll,regressors) selreg

dbox(action=run,status=ok)
if .not.ok
   return

*
* How many regressors were selected?
*

compute nselect=%rows(selreg)

*
* Pull them out from the regressor table
*

compute fulltable=%eqntable(0)
dim seltable(2,nselect)
ewise seltable(i,j)=fulltable(i,selreg(j))

*
* Create the transformed residuals series
*

set usq = %resids**2
set logusq = log(usq)

if lm {
   linreg(noprint) usq
   # %rlfromtable(seltable)
   cdf(title='LM Test on U**2') chisqr %nobs*%rsquared nselect-1
}
if exlm {
   linreg(noprint) logusq
   # %rlfromtable(seltable)
   cdf(title='LM Test on log(u**2)') chisqr %nobs*%rsquared nselect-1
}
end RegHeteroTests

