if statement not working

For questions regarding programming in the EViews programming language.

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

Elderfield.A
Posts: 78
Joined: Thu Jul 11, 2019 10:47 pm

if statement not working

Postby Elderfield.A » Tue Mar 03, 2020 4:41 pm

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
Last edited by Elderfield.A on Tue Mar 03, 2020 4:45 pm, edited 1 time in total.

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

Re: if statement not working

Postby EViews Gareth » Tue Mar 03, 2020 4:44 pm

Probably a case issue. Object names are uppercase.
Follow us on Twitter @IHSEViews

Elderfield.A
Posts: 78
Joined: Thu Jul 11, 2019 10:47 pm

Re: if statement not working

Postby Elderfield.A » Tue Mar 03, 2020 4:46 pm

right, so something like @lower(%3) should work?


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 19 guests