inverse of stack() function
by Riccardo (Jack) Lucchetti
We have the very nice stack() function, that helps you turn a list of
series into a single panel series. Unless I'm missing something, I don't
think we have the opposite function, that is a function turning a
panel series into a multi-column object. So, I ended up writing this:
<hansl>
set verbose off
function matrix unstack(series x, series names)
errorif($datatype != 3, "This function needs panel data")
scalar N = $nobs / $pd
set skip_missing off
matrix mat = mshape({x}, $pd, N)
strings lab0 = strvals(names)
strings lab1 = array(N)
ndx = uniq(names) # ordering could be garbled
loop i = 1 .. N
j = ndx[i]
lab1[i] = fixname(lab0[j])
endloop
cnameset(mat, lab1)
return mat
end function
###
### example
###
open grunfeld.gdt
matrix mat = unstack(invest, firmname)
# save as a dataset and reopen it
y0 = sprintf("%d", min(year))
fname = "@dotdir/tmp.gdt"
store "@fname" --matrix=mat
open "@fname" --preserve
setobs 1 @y0
</hansl>
My question is: is there a simpler way to accomplish the above? And if
there isn't, would it be worthwhile to add this function to the extra
package?
-------------------------------------------------------
Riccardo (Jack) Lucchetti
Dipartimento di Scienze Economiche e Sociali (DiSES)
Università Politecnica delle Marche
(formerly known as Università di Ancona)
r.lucchetti(a)univpm.it
http://www2.econ.univpm.it/servizi/hpp/lucchetti
-------------------------------------------------------
3 years, 8 months
inconsistent naming of periodic dummies
by Artur Tarassow
Hi,
just by chance I found that periodic dummies are not named consistently.
Currently we have:
- quarterly data: dq1 to dq4
- monthly data: dm1 to dm12
- daily (5 days): dummy_1 to dummy_5
I am wondering whether some harmonization is useful here?
<hansl>
clear
set verbose off
# quarterly dq*
open AWM18.gdt -q
list L = dataset
genr dummy
list N = dataset - L
N
# monthly -- dm*
open hamilton.gdt -q
list L = dataset
genr dummy
list N = dataset - L
N
# Daily (5 days) -- dummy_*
open b-g.gdt -q
eval $datatype
list L = dataset
genr dummy
list N = dataset - L
</hansl>
Best,
Artur
3 years, 8 months
nonlinearity tests, etc. (2)
by Allin Cottrell
On Sun, 28 Feb 2021, Sven Schreiber wrote:
>>> I guess it would be useful if we could include the popular BDS test:
>>> Brock, Dechert and Scheinkman (1987) (and later published as Brock,
>>> Dechert, Scheinkman and LeBaron, 1996; apparently there is some C code
>>> by LeBaron from 1997, LeBaron, B.(1997). “A Fast Algorithm for the BDS
>>> Statistic”, Studies in Nonlinear Dynamics and Econometrics, 2, 53-59,
>>> but maybe not necessary?) [...]
I can see this could be useful if you just have a residual series
you want to test (e.g. after ARMA). So I've put it into git on a
trial basis. There's a new C-plugin, bdstest, which supports (for
now) a "hidden" function, _bdstest(). It's based on LeBaron's "fast"
code. The signature of the hidden function is:
matrix _bdstest(series x, int m, scalar eps)
where m is the embedding level (>= 2) and eps the cut-off for
"closeness". Right now eps is just a raw number in the units of x,
but if we pursue this it should probably be expressed as a fraction
of the standard deviation of x (a rule of thumb seems to be eps =
0.5*sd(x)).
The return value is a column vector of m-1 z-scores, for testing at
embedding levels 2 to m.
I'm attaching LeBaron's sample data as x.txt, and the output from
his original program as output.txt. You can replicate this via
<hansl>
open x.txt
matrix B = _bdstest(x, 5, 100)
print B
</hansl>
The plugin file bdstest.c can also be copied out of the source tree
and compiled as a stand-alone "libgretl program", by defining
STANDALONE to 1 near the top of the file. In that mode the program
does Monte Carlo, which reveals that the test over-rejects quite
substantially for series of typical econometric length -- so if we
pursue this we may want to look into MBDS. The MC parameters are
mostly hard-wired; edit the C to change things.
Allin
3 years, 8 months
the getinfo() function: request for comments
by Riccardo (Jack) Lucchetti
The getinfo() function, as you know, is used to for retrieving the
metadata of a series. For example, the code
<hansl>
open data4-1 -q
b = getinfo(sqft)
print b
</hansl>
returns
<output>
bundle b:
coded = 0
transform = "none"
parent = ""
discrete = 0
name = "sqft"
description = "square feet of living area (Range 1065 - 3000)"
lag = 0
has_string_table = 0
</output>
The function currently returns an error if applied to a series that is
created "on the fly", as in "getinfo(log(sqrt))". This is IMO undesirable,
so I was going to modify the function to have it return a bundle anyway.
The question is: what should it contain? I was inclined to fill all the
slots with "sensible" values, perhaps setting "name" as "anonymous" and
"description" with something meaningful if possible. Or should we just
return an empty bundle? Would it make sense to include an "anonymous"
binary flag? Something else?
-------------------------------------------------------
Riccardo (Jack) Lucchetti
Dipartimento di Scienze Economiche e Sociali (DiSES)
Università Politecnica delle Marche
(formerly known as Università di Ancona)
r.lucchetti(a)univpm.it
http://www2.econ.univpm.it/servizi/hpp/lucchetti
-------------------------------------------------------
3 years, 8 months
nonlinearity tests, etc. (1)
by Allin Cottrell
I'm moving this thread to devel, it's not really "user" stuff.
And I'm replying in two parts: on the gretl internals question then
on the BDS nonlinearity test.
On Sun, 28 Feb 2021, Sven Schreiber wrote:
>>> (Side remark: At the top of the file it says "library.c for gretl --
>>> main interface to libgretl functions", so I don't understand why it
>>> lives under "gui" in the source tree. A hansl batch script on the CLI
>>> would also seem to use this.)
>>
>> In that context "gretl" means the GUI program, as opposed to gretlcli.
>> The CLI programs gretlcli and gretlmpi have their own interfaces to
>> libgretl, which have to differ in various ways. Nothing but the GUI
>> program uses, or could use, gui/library.c.
>
> Aha, good to know. I guess then the other interface is in
> lib/src/libglue.c?
Not really. The CLI-specific library interface is in gretlcli.c and
gretlcli-mpi.c. The job of lib/src/libglue.c is to bridge between
the user-command level and the internal functions level, for certain
commands that require pre-processing. For example, commands that
usually operate on series but that support a --matrix=whatever
option, in which case we construct an on-the-fly internal dataset.
> What does it mean to execute a script in the GUI script editor,
> does that count as GUI or as CLI in this context?
Well, it shares a log with CLI execution, but when a script is
called from the GUI we need various callbacks to keep the GUI in
sync (e.g. populating the main window when series are added or
deleted, populating the "icon view" window when required). So it's a
bit of both.
In gui/library.c you'll see that most commands get passed on to
gretl_cmd_exec(), in src/lib/src/interact.c, but some are so
intimately connected to the GUI that it's best to handle them
locally.
Allin
3 years, 8 months
BUG: mread() using relative paths
by Artur Tarassow
Hi,
using latest git on Ubuntu 20.10, mread() using relative paths fails
here. Here is a sample script:
<hansl>
clear
set verbose off
# Set according to your path
string BASE_PATH = "/home/at/tmp"
string DATA_NAME = "matrix.csv"
print "Absolute path"
string filename = sprintf("%s/mread_csv/%s", BASE_PATH, DATA_NAME)
catch matrix m = mread(filename)
if $error
print "Failed to read matrix 'm'"
else
print m
endif
printf "\nUse relative path\n"
set workdir "BASE_PATH"
string filename = sprintf("./mread_csv/%s", DATA_NAME)
catch matrix a = mread(filename)
if $error
print "Failed to read matrix 'a'"
else
print a
endif
# open command works using relative path
open "@filename"
summary
quit
</hansl>
mread() works fine with an absolute path though. The "open" command
handles relative paths without any problem.
Best,
Artur
3 years, 8 months
"overly significant" whitespace in package spec file?
by Sven Schreiber
Hi,
building a package with a hand-crafted spec file failed for me right now
(on Windows), saying there were no public interfaces. Changing the start
of the line "public =" (with two blanks) to "public =" (one blank)
seemed to fix it.
Is it perhaps a bit too pedantic to require exactly a single blank there?
thanks
sven
3 years, 8 months
Problems with quit keyword
by Artur Tarassow
Hi,
Just by chance I've found this (weird?) behavior of the quit keyword
when using the GUI:
1) The following script fails to run.
2) I get the somehow misleading message:
"Unbalanced "loop"/"endloop" in script"
<hansl>
loop i=1..4
if $i < 3
print "Gretl is awesome."
elif $i == 3
print "Let's quit now."
quit
endif
endloop
</hansl>
Another issue: The following script:
1) Prints the message
2) stdout prints "Script done"
3) The GUI shows prints the error:
"Unmatched "if" in script (fixed)"
<hansl>
FOO = 1
if FOO == 1
print "gretl is awesome"
quit
endif
</hansl>
Thanks,
Artur
3 years, 8 months
fractional power of pos-def matrix
by Sven Schreiber
Hi,
I just stumbled over old hansl code by Jack that implements the
fractional power of a pd matrix (see at the end). The comment hints at
the plan to integrate this somewhere, but it never happened. Should it
go into the 'extra' addon?
thanks
sven
----
function matrix pdmatpower(const matrix A, scalar pow)
# Helper function by Jack Lucchetti to calculate
# a fractional power (e.g. root) of a pos-def matrix.
# Once this feature is in extra.gfn or in core gretl
# it can be retired.
matrix ret = {}
catch l = eigensym(A, &ret)
err = $error
if err
msg = sprintf("%d - %s", err, errmsg(err))
funcerr "@msg"
elif minc(l)<0
msg = sprintf("matrix %s is not pd", argname(A))
funcerr "@msg"
else
l = l .^ (pow/2)
ret = ret .* l'
ret = ret*ret'
endif
return ret
end function
3 years, 8 months
foreach loop over (bundled) list
by atecon
Hi,
I am not sure that this is really a bug or part of the spec: While the
foreach-loop iterates 4 times when applied to list X, it only iterates a
single time when iterating over B.X where B is a bundle.
<hansl>
clear
set verbose off
open denmark.gdt -q
list X = dataset
bundle B = _(X)
loop foreach i X
print "$i"
endloop
printf "\n\nnow loop over B.X:\n"
loop foreach i B.X # I guess that is a new feature
print "$i" # NOTE: single loop iteration
endloop
</hansl>
Best,
Artur
3 years, 9 months