Hi,
Is there a clean way to do something like the following:
if %mif %m_long="January" then
%m_short = "01"
else
if %m_long="February" then
%m_short = "02"
else
if %m_long="March" then
%m_short = "03"
.
.
.
endif
endif
endif
That works but it's really clunky, especially for states or MSAs or any list of more than three or four. Thanks!
Jonathan
multiple repetitive if statements
Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt
-
startz
- Non-normality and collinearity are NOT problems!
- Posts: 3798
- Joined: Wed Sep 17, 2008 2:25 pm
Re: multiple repetitive if statements
Hi,
Is there a clean way to do something like the following:
if %mif %m_long="January" then
%m_short = "01"
else
if %m_long="February" then
%m_short = "02"
else
if %m_long="March" then
%m_short = "03"
.
.
.
endif
endif
endif
That works but it's really clunky, especially for states or MSAs or any list of more than three or four. Thanks!
Jonathan
Code: Select all
%m_short = @recode(%m_long="January","01",%m_short)
%m_short = @recode(%m_long="February","02",%m_short)
Re: multiple repetitive if statements
Okay, I guess looping through a table of paired values is best for a long list. Thanks for the fast reply!
Jonathan
Jonathan
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13604
- Joined: Tue Sep 16, 2008 5:38 pm
Re: multiple repetitive if statements
Create an svector with the short values you want in it, then just do this:
(where I called my short svector "shorts").
Code: Select all
svector longs = @uniquevals({%m_long})
for !i=1 to @rows(longs)
%long = longs(!i)
%short = shorts(!i)
{%m_short} = @recode({%m_long} = %long, %short, {%m_short})
next
Re: multiple repetitive if statements
Thanks for that. The use of recode is something I need to consider more.
Jonathan
Jonathan
Who is online
Users browsing this forum: No registered users and 2 guests
