On Sun, 6 Apr 2025, Sven Schreiber wrote:
Hi all,
sorry, this is going to be long and a bit involved. While working on a
package, I encountered some weirdness when creating new gretl list objects
off of a $model coming from a GUI model window after doing OLS. I do have a
stripped-down package test.gfn which I'm attaching for
illustration.[...]
Thanks for the report.
So Sven has in mind a function package which offers attachment to
the "Analysis" menu in a gretl model window. It's intended to
perform an action for which a particular list of series is needed,
namely, the list of regressors for the model in question, minus any
lags of the dependent variable (and also minus the constant).
A function in this context has access to the $model accessor and
Sven wishes to construct the needed list thus:
bundle mod = $model
list Lexo = mod.xlist - lags(mod.maxlag, mod.ylist) - const
where the call "lags(mod.maxlag, mod.ylist)" is meant to create the
lagged dependent list to subtract from mod.xlist, which contains all
the regressors.
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.
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>
and in the primary function we do
bundle mod = $model
list Lexo = exog_list(mod.xlist, mod.ylist)
Allin