On Thu, 7 Sep 2006, Arnaud Bervas wrote:
The following example is the beginning of a script for computing
Fisher stat
repeatedly:
loop for i= 0..10
ols Y const X(0 to -$i)
genr SR$i = $ess
genr DL$i = ($nobs- $i -$ncoeff)
endloop
Then I want to create a loop in order to compute FISHER = (SR(i) - SR(i+1))/
(DL(i)-DL(i+1))/(SR(i+1)/D(i+1))
I tried different tricks, but couldn't find out any solution yet
Ah, I see. I think that what you're aiming at here could be
done more simply. The following sticks closely to your design,
but uses matrices.
matrix SR = zeros(11, 1)
matrix DL = zeros(11, 1)
set echo off
set messages off
loop for i= 0..10 --quiet
scalar j = i + 1
ols Y const X(0 to -$i) --quiet
matrix SR[j,] = $ess
# Is the following line right? Perhaps should be
# just $nobs - $ncoeff (?)
matrix DL[j,] = $nobs - $i - $ncoeff
endloop
matrix SR print
matrix DL print
loop for i= 1..10 --quiet
scalar j = i + 1
scalar dfn = DL[i,] - DL[j,]
scalar dfd = DL[j,]
scalar Fval = ((SR[i,] - SR[j,]) / dfn) / (SR[j,] / dfd)
scalar pv = pvalue(F, dfn, dfd, Fval)
printf "Fisher: F(%d,%d) = %g (p-value = %.4f)\n", dfn, dfd,
Fval, pv
endloop
Allin.