* * Chapter 8 - Norway & Finland data, forecasts * open data norwayfinland.txt calendar(a) 1970 data(format=free,org=columns,skips=1) 1970:01 2003:01 year norway finland * set logfinland = log(finland) set lognorway = log(norway) * * The local level model is used for the Norway data in section 2.3. * @LocalDLMInit(irreg=sigsqeps) lognorway nonlin sigsqeps sigsqxi compute sigsqxi=sigsqeps*.01 * dlm(a=1.0,c=1.0,sv=sigsqeps,sw=sigsqxi,exact,y=lognorway,$ method=bfgs,yhat=yhat,svhat=svhat) * 2008:1 xstates vstates * * Because RATS dates the "filtered" state differently from the book, the * in-sample forecasts are computing using the yhat option. * set forecast 1970:2 2008:1 = %if(t<=2003:1,%scalar(yhat),%scalar(xstates(t))) set fvariance 1970:2 2008:1 = %if(t<=2003:1,%scalar(svhat),%scalar(vstates(t))) * set upper * 2008:1 = forecast+1.64*sqrt(fvariance) set lower * 2008:1 = forecast-1.64*sqrt(fvariance) * graph(footer="Figure 8.13 In-sample one step forecasts and \\"+$ "five year out-of-sample forecasts for Norway") 4 # lognorway # forecast * 2008:1 2 # upper * 2008:1 3 # lower * 2008:1 3 * * The local trend model with a zero variance for the level shock is used * for the Finland data in section 3.4. * @LocalDLM(type=trend,shocks=both,a=at,c=ct,f=ft) @LocalDLMInit(irreg=sigsqeps,trend=sigsqzeta) logfinland compute sigsqxi=sigsqeps*.01 nonlin sigsqeps sigsqxi=0.0 sigsqzeta dlm(a=at,c=ct,sv=sigsqeps,f=ft,sw=%diag(||sigsqxi,sigsqzeta||),exact,y=logfinland,$ method=bfgs,yhat=vhat,svhat=svhat) * 2008:1 xstates vstates * set forecast 1970:3 2008:1 = %if(t<=2003:1,%scalar(yhat),%scalar(xstates(t))) set fvariance 1970:3 2008:1 = %if(t<=2003:1,%scalar(svhat),%scalar(vstates(t))) * set upper * 2008:1 = forecast+1.64*sqrt(fvariance) set lower * 2008:1 = forecast-1.64*sqrt(fvariance) * graph(footer="Figure 8.14 In-sample one step forecasts and \\"+$ "five year out-of-sample forecasts for Finland") 4 # lognorway # forecast * 2008:1 2 # upper * 2008:1 3 # lower * 2008:1 3