Hi there,
Just wondering what would be the easiest way to implement something akin to a switch-case statement in EViews. Is there some sort of dictionary or map function, or are nested if-statements the best option as in the code below?
Thanks in advance,
Michael
for %ind CN RL AU
if %ind="CN" then
%naics = "23"
else
if %ind="RL" then
%naics = "53"
else
if %ind="AU" then
%naics = "71"
endif
endif
endif
...
...
next
Case-switch
Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13604
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Case-switch
Nested ifs :(
Re: Case-switch
:( indeed. It could get pretty ugly.
Thanks anyway.
Thanks anyway.
-
EViews Glenn
- EViews Developer
- Posts: 2682
- Joined: Wed Oct 15, 2008 9:17 am
Re: Case-switch
You can fake a dictionary using something like
Here I'm using %temp to show the paired strings at the bottom of the screen.
If you need to do this a lot, I'd make a subroutine for the inner matching loop and pass in the comparison and lookup vectors. Then you'd have something like
where the subroutine lookup is defined appropriately.
Code: Select all
%list1 = "cn rl au gb fc"
svector a = @wsplit(%list1)
%list2 = "23 53 71 53 94"
svector b = @wsplit(%list2)
for %z cn rl au
for !i=1 to @rows(a)
if (%z = a(!i)) then
%naics = b(!i)
%temp = %z + ": " + %naics
statusline %temp
break
endif
next
next
If you need to do this a lot, I'd make a subroutine for the inner matching loop and pass in the comparison and lookup vectors. Then you'd have something like
Code: Select all
%list1 = "cn rl au gb fc"
svector a = @wsplit(%list1)
%list2 = "23 53 71 53 94"
svector b = @wsplit(%list2)
for %z cn rl au
call lookup(%naics, a, b)
next
Re: Case-switch
Thanks for that Glenn. This should do the trick, and the subroutine makes it far cleaner.
Cheers,
Michael
Cheers,
Michael
Who is online
Users browsing this forum: No registered users and 2 guests
