On Wed, 22 Apr 2020, Allin Cottrell wrote:
On Wed, 22 Apr 2020, Sven Schreiber wrote:
> Am 22.04.2020 um 07:56 schrieb Artur Tarassow:
>> Hi all,
>>
>> I've detected a weird gretl behaviour when trying to apply the
"foreach"
>> loop type over vector entries. Loop index "i" is printed very round
but
>> the printf-command in the loop-block is only shown at the very last
>> iteration for the very first iteration.
>
> Actually I thought this use isn't supported.
It's not supported. What Artur is seeing is the effect of gretl treating id
as a string (matrices not being accepted). There's only one iteration because
only one string: "eval $i" prints id (a column vector); the number i equals 1
on the single iteration.
To be a little clearer (perhaps), Artur's code
<hansl>
matrix id = seq(1,3)'
loop foreach i id
smpl full
eval $i
smpl firm == i --restrict
printf "\n%.0f -- %d\n", i, min(firm)
endloop
</hansl>
translates to the following:
<hansl>
matrix id = seq(1,3)'
smpl full
eval id
smpl firm == 1 --restrict
printf "\n%.0f -- %d\n", 1, min(firm)
</hansl>
and as such the output is correct.
Allin