Page 1 of 1

can you include a loop inside a model?

Posted: Mon Jul 26, 2010 1:05 pm
by mattemde
Hi,

I'm wondering if it is possible to include a loop inside a model. My model consists of single equations for GDP, inflation, the Fed funds rate, and the long-term interest rate. Here is the tricky part: the long-term interest rate in each quarter is a weighted sum of the short-term rate over the following 40 quarters. To calculate the long-term rate, I use the following loop:

genr z = 0
for !x = 0 to 39
genr zz = rtb(!x)*(0.98^!x)*(1 - 0.98)/(1 - 0.98^40)
genr z = z + zz
next

where (0.98^!x)*(1 - 0.98)/(1 - 0.98^40) are the weights. (I posted a question in the data manipulation section asking if there was a summation command that would do this so that I could avoid using a loop, but the answer is no.) The long-rate is an explanatory variable in the GDP equation, so it cannot simply be calculated after the model has solved.

Thanks for your help,
Matt

Re: can you include a loop inside a model?

Posted: Mon Jul 26, 2010 2:19 pm
by EViews Glenn
Unfortunately, no.

I think it might be possible, with a bit of fuss, to get my other method of computing this into a group http://forums.eviews.com/viewtopic.php?f=3&t=2710).

Re: can you include a loop inside a model?

Posted: Tue Jul 27, 2010 6:15 am
by mattemde
So you can't see a way to solve my problem, either by eliminating the need for a loop or including a loop in the model?

Matt

Re: can you include a loop inside a model?

Posted: Tue Jul 27, 2010 9:52 am
by EViews Glenn
I don't believe that's quite what I said.

As I suggested, I believe that if you create the group outside of the model, then the @rsum approach can be placed inside the model, as can any equations that modify the series inside the group. I haven't verified this, but it should, in principle work.

Re: can you include a loop inside a model?

Posted: Tue Jul 27, 2010 10:14 am
by mattemde
Ok, I understand what you mean now.

Thanks,
Matt

Re: can you include a loop inside a model?

Posted: Tue Jul 27, 2010 10:19 am
by EViews Glenn
Great. Let us know how it works and if there are any gotchas.

Re: can you include a loop inside a model?

Posted: Tue Jul 27, 2010 1:18 pm
by mattemde
I included the following in the model:

mod1.append r = @rsum(all)

The model compiles with no errors, but when the model can't solve ("unable to compute due to missing data").

So I decided to do it the long way: I appended each of the 40 leads (from zz = rtb(!x)*(0.98^!x)*(1 - 0.98)/(1 - 0.98^40)) separately to the model and then appended another equation to add them up. It looks ugly, but it works.

Re: can you include a loop inside a model?

Posted: Tue Jul 27, 2010 2:48 pm
by EViews Glenn
Glad it worked. You might have been able to get away with not putting the leads in the model and making the series in the group frmls which update with the generated data (I'm assuming the X is in the model)...