On Fri, 23 May 2008, Ignacio Diaz-Emparanza wrote:
I would like to save in two strings the year and quarter of the last
observation of a quarterly series. I got to obtain the quarter but I don't
know how to save the year.
In the script below, the string @send contains the last observation = 1993:4
and the string @per contains the quarter =4. Any ideas about how to obtain the
year?
<script>
open data9-3
scalar endobs=lastobs(reskwh)
sprintf send "%s", date(endobs)
string per = @send + 5
print "@send"
print "@per"
</script>
If you're using CVS or the snapshot, you can use one of the latest bright
inventions by Allin, that is sscanf:
<script>
open data9-3
scalar endobs=lastobs(reskwh)
sprintf send "%s", date(endobs)
scalar yr
scalar qt
sscanf send "%d:%d", yr, qt
</script>
Note for the programmers: I suggest two new commands, year() and
period(),
similar to date() to obtain these strings.
I have considered this possibility many times, but there is a
complication: we don't always have data in the year:period format. We may
have cross-section data, daily data, panel data. I agree in principle that
functions like the ones you propose are useful, but the syntax will need
to be more general.
Riccardo (Jack) Lucchetti
Dipartimento di Economia
Università Politecnica delle Marche
r.lucchetti(a)univpm.it
http://www.econ.univpm.it/lucchetti