Recursive forecasting in procedure

Use this forum to post questions about syntax problems or general programming issues. Questions on implementing a particular aspect of econometrics should go in "Econometrics Issues" below.
jonasdovern
Posts: 97
Joined: Sat Apr 11, 2009 10:30 am

Recursive forecasting in procedure

Unread post by jonasdovern »

Hallo,

I think I came across a similar problem once...but I couldn't figure out anymore how it was solved back then. I want to produce recursive forecasts with a model in a procedure and I also want to re-estimate the involved equations in a recursive fashion. I.e. something like

Code: Select all

PROCEDURE MODELFIT
	*
	option model	*mod
	option integer	neqns
        (...some more options...)
        *
	* Recursive estimation and forecasting
	do time=sfroml,sto
		do k=1,neqns
	   		linreg(noprint,equation=%modeleqn(mod,k)) %modeldepvars(mod)(k) efrom time-1
		end do k
		forecast(print,model=mod,results=fcs,from=time,steps=fsteps)
        end do time
END PROCEDURE
Apparently, this type of code doesn't really use the recursively estimated equations for forecasting but always the original parameter values recorded for the equations of the model. So, what do I have to change to "update" the model during the time-loop?
jonasdovern
Posts: 97
Joined: Sat Apr 11, 2009 10:30 am

Re: Recursive forecasting in procedure

Unread post by jonasdovern »

Is it not working because %modeleqn(m,k) only generates a copy of an equation? In that case: What would be an easy way to access the "true" equation connected to the model inside the procedure?

Jonas
moderator
Site Admin
Posts: 269
Joined: Thu Oct 19, 2006 4:33 pm

Re: Recursive forecasting in procedure

Unread post by moderator »

Right, you need to do something else to actually change the coefficients in the model. There are a lot of ways to do this. Here's one approach, which:

* saves the current model coefficients into an array
* runs the regression for equaiton K
* replaces column K of the coefficient array with the new coefficients.
* resets the model coefficients using the revised coefficient array

Code: Select all


do time=sfroml,sto

 * Create an array containing current model coefficients
 compute mc = %modelgetcoeffs(mod)

 do k=1,neqns
  linreg(noprint,equation=%modeleqn(mod,k)) %modeldepvars(mod)(k) efrom time-1

  * Replace column K of MC with new coefficients for equation K (the %VALID() check on beta 
  *    is required because the equations could have different sizes)

   ewise mc(i,j) = %if( j==k, %if( %valid(%beta(i)),%beta(i),0.0 ) , mc(i,j) )

 end do k

 * Store new coefficients back into the MODEL: 
 compute %modelsetcoeffs(mod,mc)

 forecast(print,model=mod,results=fcs,from=time,steps=fsteps)
end do time

jonasdovern
Posts: 97
Joined: Sat Apr 11, 2009 10:30 am

Re: Recursive forecasting in procedure

Unread post by jonasdovern »

Thanks indeed. This is a nice short - and most importantly - generally applicable way to handle such situations.
Post Reply