looping in VAR

For questions regarding programming in the EViews programming language.

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

nic_sun
Posts: 6
Joined: Mon Jan 07, 2013 8:14 pm

looping in VAR

Postby nic_sun » Fri Feb 08, 2013 11:44 am

I have a sample of 40 countries (id =1,2,...40) with variables x and y (x1,y1,x2,y2...x40,y40) . I wanted to loop in VAR with some specific conditions. For example,if a country has an id 4,7,10,15,32,34 I want to use lag length of 1, but if country has an id 1,2,9,11,23 I want to use lag length of 2, if a country has an id 19,33,20 I want to use lag length of 3 and for other lag length of 4. I use a following sample code:

Code: Select all

for !j=1 to 40 if !j=4 or 7 or 10 or 15 or 32 or 34 then var m{j}.ls(p) 1 1 y{j} x{j} else if !j=1 or 2 or 9 or 11 or 23 then var m{j}.ls(p) 1 2 y{j} x{j} else if !j=19 or 33 or 20 then var m{j}.ls(p) 1 3 y{j} x{j} else var m{j}.ls(p) 1 4 y{j} x{j} endif endif endif endif next
However, eviews gives me the syntax error for this. Any help in this regard will be highly appreciated.

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

Re: looping in VAR

Postby EViews Gareth » Fri Feb 08, 2013 11:57 am

A line like:

Code: Select all

if !j=4 or 7 or 10 then
should be:

Code: Select all

if !j=4 or !j=7 or !j=10 then

nic_sun
Posts: 6
Joined: Mon Jan 07, 2013 8:14 pm

Re: looping in VAR

Postby nic_sun » Fri Feb 08, 2013 12:27 pm

A line like:

Code: Select all

if !j=4 or 7 or 10 then
should be:

Code: Select all

if !j=4 or !j=7 or !j=10 then
Thanks. But, still I get the error . Can I have an extra hint?

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

Re: looping in VAR

Postby EViews Gareth » Fri Feb 08, 2013 12:31 pm

What error message do you receive?

nic_sun
Posts: 6
Joined: Mon Jan 07, 2013 8:14 pm

Re: looping in VAR

Postby nic_sun » Fri Feb 08, 2013 12:49 pm

What error message do you receive?
Still the syntax error
I think the last line code is wrong. Do I have to still write the if condition for last condition. There are 4 conditions but I only wrote three conditions and I assume that if they are not satisfied it will run the VAR with the order 4. Am I correct?

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

Re: looping in VAR

Postby EViews Gareth » Fri Feb 08, 2013 2:07 pm

You are correct. However you have three "if" statements and four "endif" statements. There's probably something going wrong there.

nic_sun
Posts: 6
Joined: Mon Jan 07, 2013 8:14 pm

Re: looping in VAR

Postby nic_sun » Sat Feb 09, 2013 10:14 am

You are correct. However you have three "if" statements and four "endif" statements. There's probably something going wrong there.
Thanks once again for the input.

ellenneln
Posts: 5
Joined: Mon Feb 11, 2013 5:51 am

Re: looping in VAR

Postby ellenneln » Mon Feb 18, 2013 3:50 am

Try to delete the else and use just if, not nested :

for !j=1 to 40
if !j=4 or 7 or 10 or 15 or 32 or 34 then
var m{j}.ls(p) 1 1 y{j} x{j}
endif
if !j=1 or 2 or 9 or 11 or 23 then
var m{j}.ls(p) 1 2 y{j} x{j}
endif
if !j=19 or 33 or 20 then
var m{j}.ls(p) 1 3 y{j} x{j}
else
var m{j}.ls(p) 1 4 y{j} x{j}
endif
next


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests