On Tue, 2 Oct 2007, Ignacio Diaz-Emparanza wrote:
I have a monthly dataset with the sample starting in 2003.10
If I execute the command
genr dummy
(or add/periodic dummies in the GUI) the generated variables does not contain
the "1" in the correct month. In concrete the variable "ddic" has the
"1" in
september.
Confirmed. The trouble is that the string "10" ends with the character
"0". If I'm not mistaken, the following patch should fix it. Basically, it
avoids conversion to strings. Allin, I ran just a limited series of tests,
so I'm not committing it myself. Could you take a look?
Index: lib/src/dataio.c
===================================================================
RCS file: /cvsroot/gretl/gretl/lib/src/dataio.c,v
retrieving revision 1.327
diff -u -w -u -r1.327 dataio.c
--- lib/src/dataio.c 27 Sep 2007 14:40:19 -0000 1.327
+++ lib/src/dataio.c 2 Oct 2007 17:02:30 -0000
@@ -912,27 +912,15 @@
ret = t % pdinfo->pd;
} else {
/* quarterly, monthly, hourly... */
- double x = date(t, pdinfo->pd, pdinfo->sd0);
- char *p, s[32];
- int i, n;
- sprintf(s, "%f", x);
- n = strlen(s);
- for (i=n-1; i>0; i--) {
- if (s[i] == '0') {
- s[i] = '\0';
- } else {
- break;
- }
- }
- p = strchr(s, '.');
- if (p == NULL) {
- p = strchr(s, ',');
- }
- if (p != NULL) {
- sscanf(p + 1, "%d", &ret);
- ret -= 1;
+ double ln10 = 2.30258509299404568401;
+ double x = date(t, pdinfo->pd, pdinfo->sd0);
+ x -= floor(x);
+ int i, scale = (int) (1 + log(pdinfo->pd)/ln10);
+ for(i=0; i<scale; i++) {
+ x *= 10;
}
+ ret = (int) x;
}
return ret;
Riccardo (Jack) Lucchetti
Dipartimento di Economia
Università Politecnica delle Marche
r.lucchetti(a)univpm.it
http://www.econ.univpm.it/lucchetti