[Gretl-users] Tramo script
Ignacio Diaz-Emparanza
ignacio.diaz-emparanza at ehu.es
Wed Feb 14 10:02:11 EST 2007
I finally rewrote my Tramo-linearization script to take into account some of
the new features introduced by Allin, and trying to make the script usable in
both, Linux and Windows. You may find it in the attached files.
This script uses Tramo to interpolate missing values and correct for outliers,
returning the corrected series to the control of gretl. In the example, the
series produced by Tramo are always added the suffix "_a". If Tramo detects
some missing values and/or outliers it generates a "linearized" series and so
a label "Linearized" is added to de descriptive label of the produced series;
if Tramo does not detect missing values or outliers it also produces the
series with suffix "_a" but now it is labeled as "Original".
You should "allow for shell commands" in gretl preferences to use this script.
There are two things that I would add to the gretl "wishes list" (not urgent,
Allin, if you think that it is not the time now) with respect to this type of
script:
1- If gretl automatically produces an "environment variable" indicating
whether it is being executed in Linux/Windows, we could go without the
parameter "linux=0/1" used in this script.
2- Another problem with the decimal point: as Tramo uses points, this script
only works well if the user unselect "use locale settings as decimal points"
in preferences. May be posible to have a "set" variable to force the use of
decimal points inside a function?
--
Ignacio Díaz-Emparanza
Dpto. de Economía Aplicada III (Econometría y Estadística)
UPV-EHU
-------------- next part --------------
open data9-9
list xlist = nocars pop Y price primert
#The following two lines pass the values
#of the tramodir and tramo executable path
#as defined by default in gretl preferences.
#You can also change this using for example
#string tramodi = "/home/etpdihei/gretl/tramo"
#string tram = "/usr/bin/tramo"
sprintf tramodi "@tramodir"
sprintf tram "@tramo"
include tl-linwin.inp
scalar linux=1
loop foreach i xlist --quiet
genr $i_a = tramolin($i, 1976, 1, linux)
endloop
-------------- next part --------------
function tramolin clear
function tramolin(series sername, scalar year, scalar startp, scalar linux)
set echo on
set messages on
if (!isstring(tram) | !isstring(tramodi))
funcerr "The strings 'tram' (tramo executable) and 'tramodi' (tramo directory) must be defined"
end if
scalar nobser = $nobs
if linux=0
outfile --write "@tramodi\sername"
else
outfile --write "@tramodi/sername"
endif
printf "sername\n"
printf "%.8g %.8g %.8g %.8g\n", nobser, year, startp, $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
if linux=0
set shelldir @tramodi\graph\series
! del /Q *.t && cd @tramodi && @tramo -i sername -k sername.ser && cd @tramodi\graph\series && if exist xlin.t. (echo ser_lin > sername.txt) else (echo ser_orig > sername.txt)
! if exist xlin.t. (more +6 xlin.t >> sername.txt) else (more +6 xorigt.t >> sername.txt)
append "@tramodi\graph\series\sername.txt"
else
set shelldir @tramodi/graph/series
! rm -f *.t
! cd @tramodi && @tram -i sername -k sername.ser
! cd @tramodi/graph/series && if [ -e "xlin.t" ]; then echo "ser_lin" > sername.txt; else echo "ser_orig" > sername.txt ; fi
! if [ -e "xlin.t" ]; then tail --lines=+7 xlin.t >> sername.txt ; else tail --lines=+7 xorigt.t >> sername.txt ; fi
append "@tramodi/graph/series/sername.txt"
endif
if ok(isseries(ser_lin))=0
rename ser_orig adjusted
setinfo adjusted -d "Original"
else
rename ser_lin adjusted
setinfo adjusted -d "Linearized"
endif
return series adjusted
end function
More information about the Gretl-users
mailing list