Getting series name roots from labels
Posted: Mon May 04, 2015 10:25 pm
The following shows how to generate a set of name "roots" from a list of series on a file. The data file has a set of series labeled with a city name followed by "0" (for instance, "tokyo0"). The %slike returns a list of the series numbers (handles) which match that pattern. The ewise then takes those names and takes all but the final character from each, leaving a VECT[LABEL] with the city names only.
If you have a similar file, but with (say) the series names as CPI_cityname, then you would alter that to
compute cpilist=%slike("CPI_*")
and
ewise cpiroot(i)=slabel=%l(cpilist(i)),%mid(slabel,5,-1)
(%mid with a negative for the number of characters takes everything from position 5 to the end).
If you have a similar file, but with (say) the series names as CPI_cityname, then you would alter that to
compute cpilist=%slike("CPI_*")
and
ewise cpiroot(i)=slabel=%l(cpilist(i)),%mid(slabel,5,-1)
(%mid with a negative for the number of characters takes everything from position 5 to the end).
Code: Select all
cal(a) 1970:1
all 2011:1
*
open data general0.rat
data(format=rats) 1970:1 2011:1
compute cpilist=%slike("*0")
dec vect[label] cpiroot(%size(cpilist))
ewise cpiroot(i)=slabel=%l(cpilist(i)),%left(slabel,%strlen(slabel)-1)
disp cpiroot