On Sat, 29 Feb 2020, Artur Tarassow wrote:
Hi all,
I am bit puzzled about the following behaviour. Even though, the sample is
restricted to "t>3" obs. only, the strvals() function returns the distinct
string-values of series x of the full data set. Is this intended, or a bug? I
use latest git version on Ubuntu 19.04.
<hansl>
clear
set verbose off
nulldata 6 -p
genr time
series x = 1
smpl time > 3 --restrict
x = 2
smpl full
strings names = defarray("A", "B")
stringify(x, names)
eval strvals(x) # shows ["A", "B"]
smpl time > 3 --restrict
eval strvals(x) # still shows ["A", "B"]
</hansl>
I would say that's intended, since the "strvals" are a property of the
data series, irrespective of the current sample selection. In your
particular case, the workaround "strvals(x)[values(x)]" after subsampling
works because values(x) turns out to be a scalar, but that would need to
be generalised, as the following example shows:
<hansl>
set seed 666
nulldata 20
x = randgen(i, 1, 6)
s = defarray("a", "b", "c", "d", "e",
"f")
stringify(x, s)
print x
eval strvals(x)
smpl 6 10
eval strvals(x)[values(x)]
</hansl>
-------------------------------------------------------
Riccardo (Jack) Lucchetti
Dipartimento di Scienze Economiche e Sociali (DiSES)
Università Politecnica delle Marche
(formerly known as Università di Ancona)
r.lucchetti(a)univpm.it
http://www2.econ.univpm.it/servizi/hpp/lucchetti
-------------------------------------------------------