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 longterm interest rate. Here is the tricky part: the longterm interest rate in each quarter is a weighted sum of the shortterm rate over the following 40 quarters. To calculate the longterm 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 longrate is an explanatory variable in the GDP equation, so it cannot simply be calculated after the model has solved.
Thanks for your help,
Matt
can you include a loop inside a model?
Moderators: EViews Gareth, EViews Moderator

 EViews Developer
 Posts: 2622
 Joined: Wed Oct 15, 2008 9:17 am
Re: can you include a loop inside a model?
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).
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?
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
Matt

 EViews Developer
 Posts: 2622
 Joined: Wed Oct 15, 2008 9:17 am
Re: can you include a loop inside a model?
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.
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?
Ok, I understand what you mean now.
Thanks,
Matt
Thanks,
Matt

 EViews Developer
 Posts: 2622
 Joined: Wed Oct 15, 2008 9:17 am
Re: can you include a loop inside a model?
Great. Let us know how it works and if there are any gotchas.
Re: can you include a loop inside a model?
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.
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.

 EViews Developer
 Posts: 2622
 Joined: Wed Oct 15, 2008 9:17 am
Re: can you include a loop inside a model?
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)...
Who is online
Users browsing this forum: No registered users and 1 guest