Page 1 of 1
multiple repetitive if statements
Posted: Fri Sep 18, 2015 3:54 pm
by Jonathan
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
Re: multiple repetitive if statements
Posted: Fri Sep 18, 2015 4:11 pm
by startz
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)
or something like that
Re: multiple repetitive if statements
Posted: Fri Sep 18, 2015 4:32 pm
by Jonathan
Okay, I guess looping through a table of paired values is best for a long list. Thanks for the fast reply!
Jonathan
Re: multiple repetitive if statements
Posted: Fri Sep 18, 2015 4:42 pm
by EViews Gareth
Create an svector with the short values you want in it, then just do this:
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
(where I called my short svector "shorts").
Re: multiple repetitive if statements
Posted: Tue Sep 22, 2015 10:15 am
by Jonathan
Thanks for that. The use of recode is something I need to consider more.
Jonathan