On Fri, 13 Jun 2014, Allin Cottrell wrote:
John Paravantis recently posed an interesting data-parsing
challenge [...]
As I said, the data file in question was a panel with a half-hourly
time dimension, and although it did not contain an index for the
half-hours it did contain two string-valued series that held the key
to forming such an index, namely
DATE: "DD-MM-YYYY" and
TIME: "hh:mm"
In my previous posting I showed how a time index could be
constructed, but admittedly in a somewhat clunky way which involved
writing out series as text and reading them back in as strings.
In current CVS and snapshots it's considerably easier. The thing is
that string-valued series are relative newcomers in gretl and our
treatment of them is not fully worked out. But here's an
improvement: when you use an expression of the form
seriesname[observation]
in a hansl script what you get back now depends, as it should, on
whether the series is string-valued or not. If not, you get a
numerical value; if so, a string value. So an index of half hourly
periods can now be created (with no file I/O) as follows.
<hansl>
scalar yr, mon, day, hr, min
series ed, hm, halfhr
loop i=1..$nobs -q
sscanf(DATE[i], "%d-%d-%d", day, mon, yr)
ed[i] = epochday(yr, mon, day)
sscanf(TIME[i], "%d:%d", hr, min)
hm[i] = hr*60 + min
endloop
ed = 1 + ed - min(ed)
halfhr = 24*60*ed + hm
halfhr = 1 + (halfhr - min(halfhr))/30
</hansl>
Allin