Gracias nacho :)

On Thu, Nov 19, 2009 at 8:29 AM, Ignacio Diaz-Emparanza <ignacio.diaz-emparanza@ehu.es> wrote:
El mié, 18-11-2009 a las 13:36 -0500, Allin Cottrell escribió:
> On Wed, 18 Nov 2009, [ISO-8859-1] Patricio Cuarn wrote:
>
> > Hello. I'm new to gretl and I'm trying to create a simple script that will,
> > for instance, seasonally adjust all variables. And I've run into troubles.
> > So...
> > 1. how do I generate variable *variable names* to genr? for instance, I want
> > to call each detrended variable "sa_" & the original variable name
> > 2. how do I pass the parameter to deseas()? deseas(gdp) works fine, but
> > deseas(varname(4)) doesn't (assuming varname(4)="gdp", varname returns a
> > string and deseas doesn't work that way. I also tried looping through a list
> > of all the variables, but the same error of erroneous argument type is
> > brought up by deseas().
>
> Look at chapter 9 of the User's Guide, on loop constructs.
>
> <sample-script>
> open data9-7
> list L = QNC PRICE INCOME UNEMP
> loop foreach i L
>   sa_$i = deseas($i)
> endloop
> </sample-script>
>
> You can say
>
>  list L = dataset
>
> if all the variables in the dataset are seasonally varying.
>

Another alternative is to do it through a function:

<script>
function list sadjust (series y )
   string vn=argname(y)
   series @vn = y
   series @vn_sa = deseas(@vn)
   series @vn_seas = @vn - @vn_sa
   list comp = @vn_sa @vn_seas
   return comp
end function

open data9-7
list L = QNC PRICE INCOME UNEMP
loop foreach i L
   list comp_$i = sadjust($i)
endloop
</script>


In this script we are defining the new 'sadjust' function that divides the series in a seasonally adjusted component
and a seasonal component, and puts them together in a list. The command

string vn=argname(y)

retrieves as a string the name that you are using when you run the sadjust(series) function. The second line,

series @vn = y

is very important because the names of the outer variables (QNC, PRICE, ...) are not known inside the function.
The loop creates a list for each original variable, for example the list comp_QNC will contain the two components
QNC_sa (seasonally adjusted) and QNC_seas (seasonal). All this components will appear magically in your gretl
main window when you run this script.

--
Ignacio Diaz-Emparanza
DEPARTAMENTO DE ECONOMÍA APLICADA III (ECONOMETRÍA Y ESTADÍSTICA)
UPV/EHU
Avda. Lehendakari Aguirre, 83 | 48015 BILBAO
T.: +34 946013732 | F.: +34 946013754
www.ea3.ehu.es


_______________________________________________
Gretl-users mailing list
Gretl-users@lists.wfu.edu
http://lists.wfu.edu/mailman/listinfo/gretl-users