[Gretl-users] Creating variables

Riccardo (Jack) Lucchetti r.lucchetti at univpm.it
Thu Jun 11 01:44:54 EDT 2009

On Wed, 10 Jun 2009, Data Analytics Corp. wrote:

> Hi,
> I'm new to GRETL so please excuse the following naive question.


> How do I create a new variable in a script?  Here's my problem.  I have 
> a monthly times series from 1960:1 to 2009:4.  One variable is the 
> monthly cpi.  I merely want to calculate the percent change on an annual 
> basis.  I used the following:
>       genr pct = (((cpi/lags(1, cpi))^12)-1)*100

the "lags" function returns a _list_ of variables. To lag an existing 
series, you just use the "x(-n)" syntax, as in

genr pct = (((cpi/cpi(-1))^12)-1)*100

note, however, that there are several ways to accomplish the above, like 
for instance

genr pct = 100*exp(12*ldiff(cpi)-1)

that I personally find cleaner.

Riccardo (Jack) Lucchetti
Dipartimento di Economia
Università Politecnica delle Marche

r.lucchetti at univpm.it

More information about the Gretl-users mailing list