Am 18.11.2020 um 14:39 schrieb Sven Schreiber:
I do think and agree that we should have more friendly tools to make
this switch easier. This doesn't have to be in core gretl in C, AFAICS,
packages written in hansl would do nicely.
Here's an initial example of the kind of helper tools I have in mind.
The following function accepts the $system accessor bundle from an
estimation with the 'var' command (plus an optional string for the name
of the new system for the 'system' command) and spits out a string with
ready-to-use code that will set up the equivalent 'system'. See below
for a test case.
BTW, internal development note: It would be nice if the $system bundle
saved by the var command also included a 'command' entry like a $model
bundle does.
<hansl>
function string systemcodefromvar(const bundle varsysbdl, string sysname[null])
# the following check is a workaround because the estimator isn't
# currently stored in $system after 'var'
errorif(inbundle(varsysbdl, "sysA"), "doesn't look like coming
from 'var'")
errorif(varsysbdl.ecm, "only works for plain VARs so far, not VECMs")
# let user override the default new system name
string sysname = exists(sysname) ? sysname : "newsysfromvar"
set verbose off
string ret
outfile --buffer=ret
# the LHS of the system
printf "list sysendo = deflist(%s)\n", varname(varsysbdl.ylist)
# lagged endogenous
printf "list RHS = lags(%d, sysendo)\n", varsysbdl.order
# add the exogenous terms
if inbundle(varsysbdl, "xlist")
printf "RHS = RHS || deflist(%s)\n", varname(varsysbdl.xlist)
endif
# add deterministic terms
if varsysbdl.detflags[1] # constant
print "RHS = RHS || const"
endif
if varsysbdl.detflags[2] # trend
print "RHS = RHS || time"
endif
if varsysbdl.detflags[3] # seasonals (centered)
print "RHS = RHS || seasonals(, TRUE)"
endif
# repeat the identical RHSs for the system
print "lists sysRHSs = array(nelem(sysendo))"
print "loop i=1..nelem(sysendo)"
print " sysRHSs[i] = RHS"
print "endloop"
# the actual system formulation
printf "%s <- system\n", sysname # (could also add
"method=ols" here)
print " equations sysendo sysRHSs"
print "end system"
end outfile
return ret
end function
</hansl>
OK, so using this function you can do for example the following:
# test case:
open denmark
var 2 LRM LRY ; IBO --quiet
string code = systemcodefromvar($system, "fancysystem")
print code
and then you can run this code directly, followed by a restrict ... end
restrict block that was ultimately your idea if I understand correctly.
Again, this is just an example and obviously not fully automated and so
forth. But maybe it's a base from which to start.
cheers
sven