[Gretl-users] change frequency

Allin Cottrell cottrell at wfu.edu
Thu Nov 19 12:54:55 EST 2009


I realize there was a bug in my script implementation of the
Uspensky and Heaslet "day of the week" function.  There's a
corrected version below.

In addition, since this is a bit tricky, I've added a built-in
function "weekday" (in CVS and snapshot)  which does the
calculation given year, month and day.  The script below
retains the hand-rolled function.

<script>
function scalar day_of_week (scalar yr, scalar mo, scalar day)
    /* Uspensky and Heaslet, Elementary Number Theory (1939):
       Sunday = 0, Monday = 1, ...
    */
    scalar c, d, i1, i2, i3

    if (mo < 3)
	yr--
	mo += 10
    else
	mo -= 2
    endif

    c = int(yr / 100)
    d = int(yr % 100)
    i1 = int(floor(2.6 * mo - 0.2)) % 7
    i2 = int(floor(d / 4.0)) % 7
    i3 = int(floor(c / 4.0)) % 7

    return ((day%7)+i1+(d%7)+i2+i3-((2*c)%7))%7
end function

open djclose.gdt

scalar T = $nobs
scalar yr, mo, day
string datestr
series monday = 0

set messages off

loop i=1..T -q
  smpl i i
  outfile @dotdir/date.txt --write
  print djclose -o
  outfile --close
  string date = $(tail -n+4 @dotdir/date.txt)
  sscanf date, "%d/%d/%d", &yr, &mo, &day
  printf "yr = %d, mo = %d, day = %d\n", yr, mo, day
  scalar dow = day_of_week(yr, mo, day)
  if dow == 1
     monday[i] = 1
  endif
endloop

smpl --full
print djclose monday -o
</script>

Allin Cottrell


More information about the Gretl-users mailing list