Connecting if statement with a table

For questions regarding programming in the EViews programming language.

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

sierov
Posts: 7
Joined: Thu Aug 01, 2019 7:26 am

Connecting if statement with a table

Postby sierov » Tue Aug 06, 2019 2:01 am

Hey there,

I am trying to describe a logical process using EViews. I would do with a bit of advice. Is it possible to do the following?

I have 5 series that I use as explanatory variables for an equation: x1, x2, x3, x4, and x5. Each series is filled with natural numbers from 1 to 10. After some analysis I have generated the following table:
x3 7
x1 3
x5 10
x4 1
x5 4
x2 3
. .
. .

Somehow I would like to describe the following process:
smpl 2000m01 smpl2000m01
to select table(1,1) and check whether series x3 = 7,
if not
select x1 and check whether x1=3
if not
select x5 and check whether x5=10
and so on until it returns "true"
for example x2 = 3, "true"
eq1.ls y c x2

after that, I would like to repeat it for the next observation which would not be a problem. The main problem is to create that logic which would check which explanatory variable to use for a certain observation.

Thank you in advance! I would appreciate any suggestion!:)

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13312
Joined: Tue Sep 16, 2008 5:38 pm

Re: Connecting if statement with a table

Postby EViews Gareth » Tue Aug 06, 2019 7:44 am

I'm not sure I follow what you're trying to do.
Follow us on Twitter @IHSEViews

sierov
Posts: 7
Joined: Thu Aug 01, 2019 7:26 am

Re: Connecting if statement with a table

Postby sierov » Thu Aug 08, 2019 1:24 am

Gareth, sorry for making it overcomplicated. Maybe I could try with a more precise question. Is there a way to create a reference to a table or matrix withing an equation?
For example:

eq.ls y c "reference"
by the reference, I mean a link to a cell/matrix element (i,j) which itself is a name of a series?

For instance, table(2,1) = "x5". I have a series called x5. In the end, I just need eq.ls y c x5.
Or a matrix element (2,1) = 5 and I would need an equation which would refer to it: eq.ls y c x{reference to matrix element(2,1)} which would give me the same: eq.ls y c x5.

I've developed a model which generate the mentioned above table/matrix automatically, therefore I need a reference.
I use EViews 10 but will have 11th probably next week.
Thank you in advance for your time!

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13312
Joined: Tue Sep 16, 2008 5:38 pm

Re: Connecting if statement with a table

Postby EViews Gareth » Thu Aug 08, 2019 7:27 am

Code: Select all

%reg = mytable(2,1)
eq.ls y c {%reg}


or

Code: Select all

!reg = mymatrix(2,1)
eq.ls y c x!reg
Follow us on Twitter @IHSEViews

sierov
Posts: 7
Joined: Thu Aug 01, 2019 7:26 am

Re: Connecting if statement with a table

Postby sierov » Thu Aug 08, 2019 9:57 am

Thanks a lot!

sierov
Posts: 7
Joined: Thu Aug 01, 2019 7:26 am

Re: Connecting if statement with a table

Postby sierov » Fri Aug 09, 2019 1:49 am

It doesn't really work :(

In the example with a matrix it produces an error "x!reg is not defined in equation eq.ls y c x!reg"
In the example with a table it produces an error "x is not defined in do_eq.ls y c x 1.000000."

Any thoughts?

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13312
Joined: Tue Sep 16, 2008 5:38 pm

Re: Connecting if statement with a table

Postby EViews Gareth » Fri Aug 09, 2019 6:32 am

Code: Select all

create u 100
series y=nrnd
series x5=nrnd

table mytable
mytable(2,1) = "x5"

matrix(3,3) mymatrix
mymatrix(2,1) = 5


%reg = mytable(2,1)
equation eq1.ls y c {%reg}

!reg = mymatrix(2,1)
equation eq2.ls y c x!reg
Follow us on Twitter @IHSEViews

sierov
Posts: 7
Joined: Thu Aug 01, 2019 7:26 am

Re: Connecting if statement with a table

Postby sierov » Fri Aug 09, 2019 8:38 am

Hm, now it seems to work. Thank you!

But the same logic won't apply if I want to refer have !reg expression in the if statement?:
For example:

smpl 1 1
x5 = 3
if x!reg = 3 then
equation eq2.ls y c x!reg
endif

Is there a way to do it?

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13312
Joined: Tue Sep 16, 2008 5:38 pm

Re: Connecting if statement with a table

Postby EViews Gareth » Fri Aug 09, 2019 9:24 am

You cannot use if statements on series.
Follow us on Twitter @IHSEViews


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 18 guests