Using gret l for Principles of Econometrics, 4th Edition
Exponential Smoothing
Another popular model used for predicting the future value of a variable based on its history is exponential smoothing. Like forecasting with an AR model, forecasting using exponential smoothing does not use information from any other variable.
The basic idea is that the forecast for next period is a weighted average of the forecast for the current period and the actual realized value in the current period.
Ут +1 = аут + (1 - а)ут (9.16)
The exponential smoothing method is a versatile forecasting tool, but one needs a value for the smoothing parameter a and a value for yT to generate the forecast yT_ 1 . The value of a can reflect one’s judgment about the relative weight of current information; alternatively, it can be estimated from historical information by obtaining within-sample forecasts
yt = ayt_і + (1 - a)yt_і
and choosing that value of a that minimizes the sum of squares of the one-step forecast errors
vt = yt - yt = yt - (ayt-1 + (1 - a)yt-1)
Smaller values of a result in more smoothing of the forecast. Gretl does not contain a routine that performs exponential smoothing, though it can perform other types.
Below, the okun. gdt data are used to obtain the exponentially smoothed forecast values of GDP growth. First the data are opened. Then the series to be smoothed is placed in a matrix called y. The number of observations is counted and an another matrix called sm1 is created; it is na T x 1 vector of zeros. We will populate this vector with the smoothed values of y. In line 5 the smoothing parameter is set to 0.38.
There are several ways to populate the first forecast value. A popular way is the take the average of the first (T + 1)/2 elements of the series. The scalar stv is the mean of the first 50 observations. The full sample is then restored.
The loop is quite simple. It loops in increments of 1 from 1 to T. The —quiet option is used to suppress screen output. For the first observation, the vector sm1[1] receives the initial forecast, stv. For all subsequent smoothed values the exponential smoothing is carried out. Once the loop ends the matrix is converted back into a series so that it can be graphed using regular gretl functions.
1 open "@gretldirdatapoeokun. gdt"
2 matrix y = { g }
3 scalar T = $nobs
4 matrix sm1 = zeros(T,1)
5 scalar a = .38
6 smpl 1 round((T+1)/2)
7 scalar stv = mean(y)
8 smpl full
9 loop i=1..T —quiet
10 if i = 1
11 matrix sm1[i]=stv
12 else
13 matrix sm1[$i]=a*y[$i]+(1-a)*sm1[i-1]
14 endif
15 endloop
16 series exsm = sm1
17 gnuplot g exsm —time-series
The time-series plot of GDP growth and the smoothed series is found in Figure 9.18. Increasing the smoothing parameter to 0.8 reduces the smoothing considerably. The script appears at the end of the chapter, and merely changes the value of a in line 5 to 0.8. The figure appears below in the bottom panel of Figure 9.18.
1 scalar tmid = round(($nobs+1)/2)
2 scalar a = .38
3 series exsm = movavg(g, a, tmid)