Thanks for the clarification, Allin.
Best,
Artur
Am 19.12.18 um 00:11 schrieb Allin Cottrell:
On Tue, 18 Dec 2018, Allin Cottrell wrote:
> On Tue, 18 Dec 2018, Artur T. wrote:
>
>> Just one question for clarification. Running the following yields an
>> -- at least for me -- unexpected behaviour where series foo results
>> in a constant ("Entry_c") even though S[i] is different for each i.
>>
>> <hansl>
>> nulldata 14000
>> series foo = 1 # SET to 1
>> strings S = array($nobs)
>> loop i=1..$nobs -q
>> S[$i] = sprintf("Entry_%d", $i)
>> endloop
>> stringify(foo,S)
>> print S # results in "Entry_1" for all obs
>>
>> series foo = 2 # SET to 2
>> strings S = array($nobs)
>> loop i=1..$nobs -q
>> S[$i] = sprintf("Entry_%d", $i)
>> endloop
>> print S # results in "Entry_2" for all obs
>> </hansl>
>
> Shouldn't really be unexpected.
>
> Per stringify(), the strings from array @S are used only as needed to
> encode the values of the series in question. Since the series you
> define have only one value each (i.e. they are constant) they require
> only one string, namely S[1].
Oops, not quite accurate: S[2] gets used in the second case. But that's
in line with the documentation in the chapter on "String-valued series"
in the User's Guide. Although a string-valued series in principle
represents an encoding that starts at 1, we allow for the possibility
that not all the integer values are included in a finite sample.
Properly functioning example follows:
<hansl>
nulldata 20
series s = index
strings S = array($nobs)
loop i=1..$nobs -q
S[i] = sprintf("Value_%d", i)
endloop
stringify(s, S)
print s --byobs
</hansl>
Allin
_______________________________________________
Gretl-users mailing list
Gretl-users(a)lists.wfu.edu
http://lists.wfu.edu/mailman/listinfo/gretl-users