[Gretl-devel] Small bug in seasonal dummies

Riccardo (Jack) Lucchetti r.lucchetti at univpm.it
Tue Oct 2 13:19:59 EDT 2007


On Tue, 2 Oct 2007, Allin Cottrell wrote:

> On Tue, 2 Oct 2007, Riccardo (Jack) Lucchetti wrote:
>
>> 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? ...
>
> Ah, we worked on this simultaneously.  Do you think the fix I
> committed is OK?

It seems to me it is. However, I'd rather avoid strings. Would this one 
(which grabs a couple of things from yours) be ok to you?

Index: lib/src/dataio.c
===================================================================
RCS file: /cvsroot/gretl/gretl/lib/src/dataio.c,v
retrieving revision 1.328
diff -u -w -u -r1.328 dataio.c
--- lib/src/dataio.c	2 Oct 2007 17:04:10 -0000	1.328
+++ lib/src/dataio.c	2 Oct 2007 17:16:22 -0000
@@ -912,19 +912,14 @@
  	ret = t % pdinfo->pd;
      } else {
  	/* quarterly, monthly, hourly... */
-	double x = date(t, pdinfo->pd, pdinfo->sd0);
-	int d = ceil(log10(pdinfo->pd));
-	char *p, s[32];

-	sprintf(s, "%.*f", d, x);
-	p = strchr(s, '.');
-	if (p == NULL) {
-	    p = strchr(s, ',');
-	}
-	if (p != NULL) {
-	    sscanf(p + 1, "%d", &ret);
-	    ret -= 1;
+	double x = date(t, pdinfo->pd, pdinfo->sd0);
+	x -= floor(x);
+	int i, d = ceil(log10(pdinfo->pd));
+	for(i=0; i<d; i++) {
+	    x *= 10;
  	}
+	ret = (int) x;
      }

      return ret;


Riccardo (Jack) Lucchetti
Dipartimento di Economia
Università Politecnica delle Marche

r.lucchetti at univpm.it
http://www.econ.univpm.it/lucchetti


More information about the Gretl-devel mailing list