Page 1 of 1

if statement not working

Posted: Tue Mar 03, 2020 4:41 pm
by Elderfield.A
Hi,

I am trying to use an if statement within a loop, which goes through a group and adjust a variable with another variable which is tagged "_adj_exc", the if statement is looking at the variable name and if it meets the condition, adjust the variable differently.

The code is below, the first part simply finds each variable name in the group, removes the last 8 letters (which is the string "_adj_exc") and creates the program string variable %3, this is then passed to the if statement testing the condition that the %3 = "var1" or "var2" (which it does, because I have tested it by printing %3 within the loop). However, the condition fails and the the resulting variable is constructed based on the "else" part of the code.

I am probably missing something really obvious here, but I just cant see it!

Any ideas?



Code: Select all


group excadj *_adj_exc
for !1 =1 to excadj.@count
   %2 = excadj.@seriesname(!1)
   !a = @length(%2)-8
   %3 = @left(%2,!a)
   smpl @all
   {%2} = @recode({%2}=na,0,{%2})

   model.scenario "1"
   model.exclude(m) {%3}(%period)
   model.override(m) {%3}(%period)

   model.scenario "2"
   model.exclude(m) {%3}(%period)
   model.override(m) {%3}(%period)   
   
   
   for %1 1 2
      smpl @all
      series {%3}_{%1} = {%3}_bl
      smpl %period
      if %3 = "var1" or %3 = "var2"  then
         series {%3}_{%1} = {%3}_bl+{%2}
      else
         series {%3}_{%1} = {%3}_bl*(1+{%2}/100)
      endif
   next
   
next



However, the condition seems to be ignored within the loop

Re: if statement not working

Posted: Tue Mar 03, 2020 4:44 pm
by EViews Gareth
Probably a case issue. Object names are uppercase.

Re: if statement not working

Posted: Tue Mar 03, 2020 4:46 pm
by Elderfield.A
right, so something like @lower(%3) should work?