Jul

23

2012

## Output gap, polynomial trends and gretl

Posted by Vitalie CiubotaruA while ago I needed to estimate Moldova’s output gap. The only data series that covered a long enough period of time and had quarterly frequency was gross domestic product. It can be downloaded from the online database of Moldova’s National Bureau of Statistics. So I used quarterly data on Moldova’s GDP and employed Gretl. In order to model the potential level of output I chose a third-order polynomial trend.

1. Get the data and save it as CSV file. The file should contain two columns: the dates and the values.

2. Import your data to gretl (File -> Open data -> Import -> Text/CSV). If the datafile is formatted properly, no additional treatment is required. Otherwise, one might need to explicitly specify the dataset structure, frequency, and the starting and ending dates.

`open /path/to/your/file.csv`

setobs 4 1995:1 --time-series

3. Generate the time index and it’s powers. Since I estimated the third-order polynomial trend, I needed squares and cubes of the time index:

`genr index`

genr index_2 = index*index

genr index_3 = index*index*index

4. Run the regression. In my case it looked like this:

`ols gdp const index index_2 index_3`

5. Retrieve the coefficients for further use. For example, I wanted to compare them to what MS Excel and Libreoffice Calc compute when creating trends in their charts:

`b = $coeff`

6. Retrieve the absolute values of the deviation from trend (the output gap in my case):

`gap = $uhat`

To see the result, one can type something like:

`gnuplot gap --time-series --with-lines`

7. Compute the fitted values, i.e. the trend itself:

`trend = gdp - gap`

To see the input data and the trend line on one graph, one can type something like:

`gnuplot gdp trend --with-lines --time-series`

Here is my result: