Am 07.04.2025 um 16:53 schrieb Allin Cottrell:
Now here's the dataset context in the example Sven describes.
* The "denmark" dataset contains the four series LRM, LRY, IBO and
IDE, with IDs 1 to 4.
* A regression of the form "ols LRM const IBO LRM(-1 to -2)" is run,
which results in the addition to the dataset of the lags LRM_1 and
LRM_2, with series IDs 5 and 6.
So mod.xlist holds "1 0 3 5 6" and the lagged dependent list is the
subset "5 6".
Now what happens when the packaged function is called? It turns out
that the call "lags(mod.maxlag, mod.ylist)" results in the
(re-)creation of the two LRM lags, appended to the dataset as series 7
and 8. The original versions, under IDs 5 and 6, are not "visible"
within the function because they were not passed as arguments (nor via
a standard list, but just inside a bundle). So the list subtraction
doesn't work: gretl tries to drop series 7 and 8 from mod.xlist, but
they're not present.
Thanks, Allin. Yes, I also did some digging into those lists and saw
this phenomenon.
I'm not sure I fully understand that "visibility" is the actual problem.
Note the example in the packaging guide for the (otherwise unrelated)
list-maker facility. The similar line there is "list L = m.xlist -
m.instlist", so all those bundled lists and their members seem to be
visible alright? It feels more like gretl doesn't recognize the lag
property of the former series.
Anyway, the packaging guide reminded me that not only the $model
accessor is available in the model window context, but the $xlist
accessor should be, too. Maybe using that would be more successful? I
will test...
It seems that it ought to be possible to ensure that when a
list-containing bundle is passed as a function argument, the listed
series become "visible" -- then Sven's approach would work. However,
in the meantime here's an approach that does work. We define a helper
function as follows
<hansl>
function list exog_list (list xlist, list ylist)
string yl = varnames(ylist)[1] ~ "_"
strings xnames = varnames(xlist)
list drop
loop i=1..nelem(xlist)
if strstr(xnames[i], yl) != ""
drop += xlist[i]
endif
endloop
list Lexo = xlist - drop - const
return Lexo
end function
</hansl>
Thanks for this concrete workaround, Allin. I think I have used the
series names for comparisons like this in other contexts in the past as
well, which is a bit like a brute-force attack.
Here's a version of your function without an explicit loop, which I hope
is equivalent:
<hansl>
function list exog_list (list xlist, list ylist)
string yl = varnames(ylist)[1] ~ "_"
strings xnames = varnames(xlist)
strings xnamesini = substr(xnames, 1, strlen(yl)) # like "LRM_"
matrix where = instrings(xnamesini, yl)
list drop = xlist[where]
list Lexo = xlist - drop - const
return Lexo
end function
</hansl>
Not sure what the minimum gretl requirement is for these constructs, though.
thanks
sven