IF command for samples in a model

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Jason, EViews Moderator, EViews Matt

jnieto
Posts: 1
Joined: Mon Apr 12, 2021 1:47 am

IF command for samples in a model

Postby jnieto » Wed Apr 14, 2021 2:16 am

Hi, I am programming a model with Eviews10 and I have a query about using the IF command on it.

What I am trying to do:

I have a model with several equations already stored in the workfile and I'm writing the model as "Text" in the model view. My yearly sample runs from 1971 to 2018 and what I need (due to some data availability issues) is that the model picks one equation to estimate certain variable from 1971 to 1998 and another equation from 1999 onwards.

What I am writing:

So, in the "Text" tab of the model view, I'm writing something like this: IF smpl<1999 then :EQ04 else :EQ05 endif. So the model should take :EQ04 before 1999 and :EQ05 afterwards. But it does not and an error message pops up. It might not have a programming solution, but it must be done through scenarios or other Eviews' option, but I have also tried and still doesn't work.

I hope this all makes sense. I had a look at the Eviews' help and the forum and I couldn't find anything describing a situation like this. My apologies if I'm posting something already discussed and many thanks in advance for any help I could get on this.

EViews Matt
EViews Developer
Posts: 560
Joined: Thu Apr 25, 2013 7:48 pm

Re: IF command for samples in a model

Postby EViews Matt » Wed Apr 14, 2021 10:02 am

Hello,

I'm afraid models do not support conditional inclusion of equations. That leaves you with basically two options, (1) using two separate model objects, one including EQ04 and one including EQ05, and solving them over different subsamples, or (2) combining the two equations into a single expression that incorporates your condition. Let me begin with a small program demonstrating this idea:

Code: Select all

create a 1990 2010
series x1 = rnd
series x2 = rnd + 1
series y = rnd
equation eq04.ls y x1 c
equation eq05.ls y x2 c
model m
%combined = @wleft(eq04.@varlist, 1) +  " = (@year < 1999) * (" + @wmid(eq04.@subst, 3) + ") + (@year >= 1999) * (" + @wmid(eq05.@subst, 3) + ")"
m.append {%combined}

The two estimated equations I want included at different times, e.g.,

Y = -0.341609426116*X1 + 0.669414463222
Y = 0.183908868529*X2 + 0.208574867244

are combined into a single equation by translating your condition into on-the-fly dummy expressions, i.e.,

Y = (@year < 1999) * (-0.341609426116 * X1 + 0.669414463222) + (@year >= 1999) * (0.183908868529 * X2 + 0.208574867244)

You can do this by hand of course, but it isn't too difficult to accomplish programmatically as above.


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 20 guests