Code: Select all
'create some data - 20 X variables and a Y variable that depends upon X11-X15.
'X variables are put into a group called XS
create u 1000
rndseed 1
group xs
group g
for !i=1 to 20
series x!i=nrnd
%name="x"+@str(!i)
xs.add {%name}
g.add {%name}
next
series y = nrnd + 3
for !i=11 to 15
y = y + !i*x{!i}
next
'perform backwards stepwise regression - first run a model with all Xs, then remove Xs one at a time based upon tstat.
equation e1
!tstop=5
!stop=0
while !stop=0
e1.ls y c xs
!mint=10000
!removedvar=0
for !i=1 to xs.@count
!currentt = @abs(e1.@tstats(!i+1)) 'note plus one is since the equation has a constant as the first variable, but we are not testing the constant
if !currentt < !mint then
!mint = !currentt
!removedvar=!i
endif
next
if !mint>!tstop then
!stop=1
else
if !removedvar>0 then
%removedvarname=xs.@seriesname(!removedvar)
xs.drop {%removedvarname}
endif
endif
wend
show e1
'run an automatic stepwise and see if it matches
equation e2.stepls(METHOD=UNI,BTOL=5,BACK,TSTAT) y c @ g
show e2