[Gretl-users] operate on all variables
ignacio.diaz-emparanza at ehu.es
Thu Nov 19 06:29:17 EST 2009
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.
> open data9-7
> list L = QNC PRICE INCOME UNEMP
> loop foreach i L
> sa_$i = deseas($i)
> 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:
function list sadjust (series y )
series @vn = y
series @vn_sa = deseas(@vn)
series @vn_seas = @vn - @vn_sa
list comp = @vn_sa @vn_seas
list L = QNC PRICE INCOME UNEMP
loop foreach i L
list comp_$i = sadjust($i)
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
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.
DEPARTAMENTO DE ECONOMÍA APLICADA III (ECONOMETRÍA Y ESTADÍSTICA)
Avda. Lehendakari Aguirre, 83 | 48015 BILBAO
T.: +34 946013732 | F.: +34 946013754
More information about the Gretl-users