## 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 Gareth, EViews Moderator

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

### can you include a loop inside a model?

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.

Matt

EViews Glenn
EViews Developer
Posts: 2627
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).

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

### 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

EViews Glenn
EViews Developer
Posts: 2627
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.

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

### Re: can you include a loop inside a model?

Ok, I understand what you mean now.

Thanks,
Matt

EViews Glenn
EViews Developer
Posts: 2627
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.

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

### 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.

EViews Glenn
EViews Developer
Posts: 2627
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)...