If Statement with string vector elements as conditions
Posted: Thu Nov 24, 2016 4:10 am
Hi,
I am trying to use an If statement within a For loop to apply some manipulation to certain variables only. In the If statement I have two conditions. One is that !i<>!j which seems to work. In the second condition I am breaking down the elements in the string vector sv_cc, which contains country names. For some countries, I want it to perform this [series {%prfij}= ({%prd}/{%prf})^w(!i,!j)], for others I want it to perform this other calculation [series {%prfij}= (({%prd}/{%prf})^w(!i,!j))*{%gdpw}]. However, when I run the code the if statement for the second condition does not work, and applies the first formulas to all the elements in sv_cc.
Do you know where my mistake is? Also, I am not sure whether I should use two different If statements as below or only one, linking both criteria with "and". Could you please have a look and let me know where my error is?
I am using eViews 9.
Thank you,
Marta
For !i=1 to @rows(w)
%reer= "_reer_" + sv_cc(!i)
%c = sv_cc(!i)
series {%reer}= 1
For !j=1 to @columns(w)
If !i<>!j then
If (@eqna(%c,"ca") or @eqna(%c,"uk") or @eqna(%c,"jp") or @eqna(%c,"us")) then
%prfij= "_prf_" + sv_cc(!i)+sv_cc(!j)
%prd= "_prd_" + sv_cc(!i)
%prf="_prd_" + sv_cc(!j)
series {%prfij}= ({%prd}/{%prf})^w(!i,!j)
{%reer}={%reer}*{%prfij}
else
If (@neqna(%c,"ca") or @neqna(%c,"uk") or @neqna(%c,"jp") or @neqna(%c,"us")) then
%gdpw=sv_cc(!i)+"_gdpw"
%prez="_prez_"+sv_cc(!i)
series {%prez}=0
series {%prfij}= (({%prd}/{%prf})^w(!i,!j))*{%gdpw}
series {%prez}={%prez}+{%prfij}
endif
endif
'delete {%prfij}
endif
Next
{%reer}={%reer}*{%prez}
delete {%prez}
Next
I am trying to use an If statement within a For loop to apply some manipulation to certain variables only. In the If statement I have two conditions. One is that !i<>!j which seems to work. In the second condition I am breaking down the elements in the string vector sv_cc, which contains country names. For some countries, I want it to perform this [series {%prfij}= ({%prd}/{%prf})^w(!i,!j)], for others I want it to perform this other calculation [series {%prfij}= (({%prd}/{%prf})^w(!i,!j))*{%gdpw}]. However, when I run the code the if statement for the second condition does not work, and applies the first formulas to all the elements in sv_cc.
Do you know where my mistake is? Also, I am not sure whether I should use two different If statements as below or only one, linking both criteria with "and". Could you please have a look and let me know where my error is?
I am using eViews 9.
Thank you,
Marta
For !i=1 to @rows(w)
%reer= "_reer_" + sv_cc(!i)
%c = sv_cc(!i)
series {%reer}= 1
For !j=1 to @columns(w)
If !i<>!j then
If (@eqna(%c,"ca") or @eqna(%c,"uk") or @eqna(%c,"jp") or @eqna(%c,"us")) then
%prfij= "_prf_" + sv_cc(!i)+sv_cc(!j)
%prd= "_prd_" + sv_cc(!i)
%prf="_prd_" + sv_cc(!j)
series {%prfij}= ({%prd}/{%prf})^w(!i,!j)
{%reer}={%reer}*{%prfij}
else
If (@neqna(%c,"ca") or @neqna(%c,"uk") or @neqna(%c,"jp") or @neqna(%c,"us")) then
%gdpw=sv_cc(!i)+"_gdpw"
%prez="_prez_"+sv_cc(!i)
series {%prez}=0
series {%prfij}= (({%prd}/{%prf})^w(!i,!j))*{%gdpw}
series {%prez}={%prez}+{%prfij}
endif
endif
'delete {%prfij}
endif
Next
{%reer}={%reer}*{%prez}
delete {%prez}
Next