Page 1 of 1

looping in VAR

Posted: Fri Feb 08, 2013 11:44 am
by nic_sun
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.

Re: looping in VAR

Posted: Fri Feb 08, 2013 11:57 am
by EViews Gareth
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

Re: looping in VAR

Posted: Fri Feb 08, 2013 12:27 pm
by nic_sun
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?

Re: looping in VAR

Posted: Fri Feb 08, 2013 12:31 pm
by EViews Gareth
What error message do you receive?

Re: looping in VAR

Posted: Fri Feb 08, 2013 12:49 pm
by nic_sun
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?

Re: looping in VAR

Posted: Fri Feb 08, 2013 2:07 pm
by EViews Gareth
You are correct. However you have three "if" statements and four "endif" statements. There's probably something going wrong there.

Re: looping in VAR

Posted: Sat Feb 09, 2013 10:14 am
by nic_sun
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.

Re: looping in VAR

Posted: Mon Feb 18, 2013 3:50 am
by ellenneln
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