On Mon, 14 May 2012, Kevin Vermeiren wrote:
I am working with panel data and I want to run a loop with
time dummies. Unfortunately, I encounter a problem when
trying to do so. [...]
loop i=1..4
genr k=($i*12)
genr Z=k-11
matrix Big=zeros(25,14)
list R= dt_$Z..dt_$k
You can't use $foo as a general means of substituting the
value of the variable foo as a string: that's a special
construction for loop indices. So your "$Z" and "$k" won't
work.
You can use string variables to hold the names of the starting
and ending series in the list, and use "@" to invoke string
substitution:
loop i=1..4 -q
scalar k = i*12
sprintf lmax "dt_%d", k
sprintf lmin "dt_%d", k-11
list R = @lmin..@lmax
list R print
endloop
Or you could compose the R list in a subsidiary loop:
loop i=1..4 -q
scalar j0 = i*12-11
list R = null
loop j=j0..j0+11 -q
R += dt_$j
endloop
list R print
endloop
Allin Cottrell