RFC: strscrape function
by Allin Cottrell
I'm wondering whether people would consider this function (which I'm
calling "strscrape" for now) worth having: it takes a string argument
and returns a row vector containing any numerical values encountered
in the string (or an empty matrix if none are found). There's a test
version in git but it's not documented; I'm not committed to keeping
it if doesn't attract much support.
Unlike using sscanf() to retrieve a matrix, the idea with this
function is that the numbers may be embedded in arbitrary text.
Numbers are identified as starting with either a minus sign (followed
directly by a digit) or a digit, and their length in characters is
decided by the C function strtod (so scientific notation is
acceptable). As the function stands, the decimal character is
unconditionally '.'.
One use for such a function would be "remedial" -- getting values back
from a gretl command when there's no relevant accessor. Here's a
semi-general illustration:
<hansl>
function matrix scrapevals (const string cmd, const list L[null])
string fname = sprintf("%s/_tmp.txt", $dotdir)
set force_decpoint on
outfile @fname --write --quiet
@cmd
outfile --close
string s = readfile(fname)
remove(fname)
return strscrape(s)
end function
open data4-10
list L = ENROLL CATHOL
matrix m = scrapevals("corr L --kendall", L)
print m
</hansl>
However, it could also be useful for processing text other than
gretl's own output. Here's a generic example:
<hansl>
string s="Here is some text 1.5e-4with embedded 12345 numbers \
stuck int0 1t."
matrix vals = strscrape(s)
print vals
</hansl>
which gives
vals (1 x 4)
0.00015000 12345. 0.0000 1.0000
Allin
7 years, 11 months
gzipped bundle files
by Allin Cottrell
In response to a request which (IIRC) appeared on this list not so
long ago, the bwrite() function -- which writes gretl bundles to XML
-- now supports the .gz extension.
<hansl>
bundle b
matrix b.m = I(1000)
string b.s = "Just testing"
bwrite(b, "b.xml") # uncompressed
bwrite(b, "b.xml.gz") # gzip-compressed
bundle b2 = bread("b.xml")
print b2
bundle b3 = bread("b.xml.gz")
print b3
eval maxc(maxr(abs(b3.m - b2.m)))
</hansl>
The last result should be 0. And on this machine I'm seeing:
-rw-rw-r-- 1 allin allin 2001243 Dec 11 21:18 b.xml
-rw-rw-r-- 1 allin allin 6982 Dec 11 21:18 b.xml.gz
(Less compression will be achieved if the bundle contains big
"random" data.)
Allin
7 years, 12 months
duration functions
by Allin Cottrell
I have a student who's working on duration models, and in trying to
help him it seemed to me we could do with some functionality to
compute nonparametric estimates of the integrated hazard and survival
functions. So I've added a couple of built-ins: naalen (Nelson-Aaalen
hazard estimate) and kmeier (Kaplan-Meier survival estimate). Basic
documentation is also added.
I plan to add a section to the User's Guide on using these functions
(along with generalized residuals) to assess the specification of a
duration model, but that'll have to wait for a while.
Allin
7 years, 12 months
problem with -= in a function
by Artur T.
Dear all,
I want to get rid of the "time" variable from a list. This works fine
out of a function but not within a function:
<hansl>
open denmark.gdt -q
list y = const time
# WORKS
y -= const
y
y -= time
y # list is null
# DOESN'T WORK
function void foo (list y)
y -= const
y
y -= time
y # time is still in the list
end function
foo(y)
I am using the current git version on ubuntu.
Best,
Artur
8 years
Problem restricting the intercept
by Artur T.
Dear all,
For some reason testing the linear restriction b[1]=0 (the intercept)
does not work. However, it works fine for all remaining
coefficients/variables as the following example shows. I am using the
current git version on ubuntu.
Best,
Artur
<hansl>
set echo off
set messages off
clear
open denmark.gdt -q
# DOES WORK: b[2]=0
ols LRM 0 LRM(-1 to -1) LRY(0 to -1)
matrix Rmat = zeros(1,nelem($coeff))
Rmat[1,2]=1
matrix qvec = zeros(1,1)
Rmat
qvec
restrict
R = Rmat
q = qvec
end restrict
# DOES NOT WORK: b[1]=0
ols LRM 0 LRM(-1 to -1) LRY(0 to -1) --quiet
matrix Rmat = zeros(1,nelem($coeff))
Rmat[1,1]=1
matrix qvec = zeros(1,1)
Rmat
qvec
restrict
R = Rmat
q = qvec
end restrict
</hansl>
8 years
gretl workdir created if not present
by Sven Schreiber
Hi,
I've noticed that if the workdir that is set in gretl's preferences
doesn't exist, then gretl creates it -- probably not right away, but
when a (data) file is saved.
I'm not saying this is a bug, because it could be the desired behavior.
OTOH I'm not sure if this is really intended by the gretl gods. Is it?
thanks,
sven
8 years
problems with automatic matrix-to-scalar conversion
by Sven Schreiber
Hi,
another appearance of the subtle pitfalls of moving back and forth
between a 1x1 matrix and a scalar.
<hansl>
function void matin( const matrix in)
print in
end function
matin( {cdf(N, {3})} ) # works
matin(cdf(N, {3})) # fails
</hansl>
So the cdf() function "destroys" the matrix property here, while I think
it shouldn't. (Don't know which other functions do as well.)
thanks,
sven
8 years
mwrite help: a possible mistake
by Henrique Andrade
Dear Allin and Jack,
I think there is a mistake in the mwrite funtion help. According to it:
"If fname has the suffix ".gz" the the file is written with gzip
compression. The format is basically as described above except that the
matrix elements are written in a single column, in column-major order."
Running the following script and openning testPLAIN and testGZ in a text
editor I get the same output (the matrix elements are not written in a
single column):
M = {1,2; 3,4; 5,6; 7,8; 9,10}
mwrite(M, "testPLAIN")
mwrite(M, "testGZ.gz")
Best regards,
Henrique Andrade
8 years