Command IF inside the loop

For questions regarding programming in the EViews programming language.

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

a.do88
Posts: 27
Joined: Sat May 27, 2017 10:01 pm

Command IF inside the loop

Postby a.do88 » Fri Nov 03, 2017 9:24 am

Hi

I used this command to report the coefficient and its pvalue of all equations in one table in column 1 and 2 and it works.

!row=1
!col=1
!col1=!col+0
!tabrow=24
for %i au
for %j au hk jp sg uk us
for %c c7
equation eq_{%i}_{%j}.arch(1,1, archm=sd, egarch, ged) {%i} c {%j}(-1)
freeze(table) eq_{%i}_{%j}
result_{%c}(!row,!col1) = @val(table(!tabrow,2))
result_{%c}(!row, !col1+1)=@val(table(!tabrow,5))
!row=!row+1
d table
d eq_{%i}_{%j}
next

Then I would like to set the !tabrow that would be automatically changed when I change the value in the variable %c.

So I add the command IF to this loop:
!row=1
!col=1
!col1=!col+0
for %i au
for %j au hk jp sg uk us
for %c c7
equation eq_{%i}_{%j}.arch(1,1, archm=sd, egarch, ged) {%i} c {%j}(-1)
freeze(table) eq_{%i}_{%j}
if %c = "c7" then !tabrow=24
!tabrow=1
endif

result_{%c}(!row,!col1) = @val(table(!tabrow,2))
result_{%c}(!row, !col1+1)=@val(table(!tabrow,5))
!row=!row+1
d table
d eq_{%i}_{%j}
next

Then I got N/A in my table.

Any comment/suggestion is greatly appreciated.

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

Re: Command IF inside the loop

Postby EViews Gareth » Fri Nov 03, 2017 9:26 am

This code has a few issues.

Code: Select all

for %c c7

This line creates a for loop with only one value. The loop is meaningless.

Code: Select all

if %c = "c7" then
!tabrow=24
!tabrow=1
endif

This if condition is meaningless, since %c is always equal to "c7" (given your above for loop).

Plus the if condition changes the same thing twice.
Follow us on Twitter @IHSEViews

a.do88
Posts: 27
Joined: Sat May 27, 2017 10:01 pm

Re: Command IF inside the loop

Postby a.do88 » Sat Nov 04, 2017 5:58 pm

Thanks Gareth for your reply.

How about this command IF

The message is" NA found in matrix in IF{%i} = AU THEN"
!col=1
for %i au ger
if {%i} = au then !n = 0
else
!n = 1
endif
!col1=!col+2*!n
next

Your help is really appreciated.

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

Re: Command IF inside the loop

Postby EViews Gareth » Sat Nov 04, 2017 7:06 pm

Code: Select all

if %i = "au" then
!n=0
else
!n=1
endif
Follow us on Twitter @IHSEViews


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 23 guests