can you include a loop inside a model?

For technical support, tips and tricks, suggestions, or any other information regarding the EViews model object.

Moderators: EViews Moderator, EViews Gareth, EViews Chris

can you include a loop inside a model?

Postby mattemde on Mon Jul 26, 2010 1:05 pm

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
mattemde
 
Posts: 9
Joined: Fri Jul 16, 2010 9:02 am

Re: can you include a loop inside a model?

Postby EViews Glenn on Mon Jul 26, 2010 2:19 pm

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).
EViews Glenn
EViews Developer
 
Posts: 1392
Joined: Wed Oct 15, 2008 9:17 am

Re: can you include a loop inside a model?

Postby mattemde on Tue Jul 27, 2010 6:15 am

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
mattemde
 
Posts: 9
Joined: Fri Jul 16, 2010 9:02 am

Re: can you include a loop inside a model?

Postby EViews Glenn on Tue Jul 27, 2010 9:52 am

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.
EViews Glenn
EViews Developer
 
Posts: 1392
Joined: Wed Oct 15, 2008 9:17 am

Re: can you include a loop inside a model?

Postby mattemde on Tue Jul 27, 2010 10:14 am

Ok, I understand what you mean now.

Thanks,
Matt
mattemde
 
Posts: 9
Joined: Fri Jul 16, 2010 9:02 am

Re: can you include a loop inside a model?

Postby EViews Glenn on Tue Jul 27, 2010 10:19 am

Great. Let us know how it works and if there are any gotchas.
EViews Glenn
EViews Developer
 
Posts: 1392
Joined: Wed Oct 15, 2008 9:17 am

Re: can you include a loop inside a model?

Postby mattemde on Tue Jul 27, 2010 1:18 pm

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.
mattemde
 
Posts: 9
Joined: Fri Jul 16, 2010 9:02 am

Re: can you include a loop inside a model?

Postby EViews Glenn on Tue Jul 27, 2010 2:48 pm

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)...
EViews Glenn
EViews Developer
 
Posts: 1392
Joined: Wed Oct 15, 2008 9:17 am


Return to Models

Who is online

Users browsing this forum: No registered users and 1 guest