Hi,
I'm facing the problem how to store a series as a 1-element list in a
bundle inside a function which returns that bundle. The background is to
mirror the structure of the $model bundle which results from the 'panel'
command; there the dependent variable is in the form of the 'ylist' list
type member of the bundle. (Why that is so is maybe also worthy of
clarification, but is another question.)
The best I can come up with is to "secretely" change the input argument
type of the function from 'series' to 'list', and the caller is still
allowed to specify the name of a single series; like this:
<hansl>
function bundle ylistb(list Ly)
errorif(nelem(Ly)>1, "just want 1-elem list")
/* some basic tests
series y = Ly[1] # to see if conversion works
ols y 0 --quiet # trivial test for the converted series y
*/
list ylist = Ly # work with a "copy"
return _(ylist)
end function
open denmark
bundle b = ylistb(LRM) # single series given as anonymous 1-element list
eval sum(abs(LRM - b.ylist[1])) # 0 as wanted
list ylist = b.ylist # copy needed for printing
list ylist print # LRM as wanted
</hansl>
This works in this simple isolated setting, but there's a little problem
when I want to get it working also as the GUI function for a contributed
package. In that case it would be cleaner to really have the 'series'
type for the input field of the dependent variable. For example, for the
'series' type you get a nice drop-down list to choose from existing
series with the mouse.
So, is there another technique which can be used to put a series inside
a bundle as a 1-element list, surviving the transfer from the function
scope to the outer scope?
thanks
sven