[Gretl-users] TRAMO in Gretl: two qustions

Allin Cottrell cottrell at wfu.edu
Sat Apr 25 15:07:06 EDT 2009


On Sat, 25 Apr 2009, Allin Cottrell wrote:

> On Sat, 25 Apr 2009, Ofer Cornfeld wrote:
>
> > I have series in Gretl that need to be corrected according to TRAMO with the
> > following rules...

> > How can I activate it via a script? (As the above, needs to be done on a
> > regular basis).
>
> Sorry, can't be done via gretl at present, though that could be
> added...

I had forgotten that Ignacio Diaz-Emparanza worked on this sort of
issue, and came up with a clever script.  I'm attaching a copy;
you should be able to modify it for your purposes.

Allin Cottrell
-------------- next part --------------
function tramolin (series sername)
  set force_decpoint on
  scalar nobser = $nobs
  scalar ausprim = firstobs(sername)-firstobs(t) #ID 11/10/07
  scalar ausp1 = ausprim+1
  scalar ausfin = lastobs(t)-lastobs(sername)
  scalar ausf1 = lastobs(sername)+1
  if WIN32
    outfile --write "@tramodir\sername"
  else
    outfile --write "@tramodir/sername"
  endif
  printf "sername\n"
  printf "%.8g %.8g %.8g %.8g\n", nobser, 1960, 1, $pd
  loop j=1..nobser --quiet
    if missing(sername[j])
      printf "-99999\n"
    else
      printf "%.8g\n", sername[j]
    end if
  endloop
  printf "$INPUT RSA=3 $\n"
  printf "\n"
  outfile --close
  #******To solve the problem of missing data at the beginning or
  #******end of the sample:
  if WIN32
    outfile --write "@tramodir\ausentesp"
  else
    outfile --write "@tramodir/ausentesp"
  endif
  if ausprim!=0
    loop j=1..ausprim --quiet
      print "NA"
    endloop
  endif
  outfile --close
  if WIN32
    outfile --write "@tramodir\ausentesf"
  else
    outfile --write "@tramodir/ausentesf"
  endif
  if ausfin!=0
    loop j=1..ausfin --quiet
      print "NA"
    endloop
  endif
  outfile --close
  #************
  if WIN32
    set shelldir @tramodir\graph\series
    ! del /Q *.t && cd @tramodir && @tramo -i sername -k sername.ser && cd @tramodir\graph\series && echo "ser_adj" > sername.txt
    ! type "@tramodir\ausentesp" >> sername.txt
    ! if exist xlin.t. (more +6 xlin.t >> sername.txt) else (more +6 xorigt.t >> sername.txt)
    ! type "@tramodir\ausentesf" >> sername.txt
    append "@tramodir\graph\series\sername.txt"
  else
    set shelldir @tramodir/graph/series
    ! rm -f *.t
    ! cd @tramodir && @tramo -i sername -k sername.ser > /dev/null
    ! cd @tramodir/graph/series && echo "ser_adj" > sername.txt
    ! cat "@tramodir/ausentesp" >> sername.txt
    ! if [ -e "xlin.t" ]; then tail --lines=+7 xlin.t >> sername.txt ; else tail --lines=+7 xorigt.t >> sername.txt ; fi
    ! cat "@tramodir/ausentesf" >> sername.txt
    append "@tramodir/graph/series/sername.txt"
  endif
  series diferencia = sername - ser_adj
  scalar suma = sum(diferencia)
  if suma=0
    setinfo ser_adj -d "Original"
  else
    setinfo ser_adj -d "Linearized"
  endif
  set force_decpoint off
  return series ser_adj
end function

## example call

open data9-7.gdt
QNC_adj = tramolin(QNC)



More information about the Gretl-users mailing list