Sorry for coming back on this; it may appear a bit nitty-gritty, but it may be helpful to point to users that the safe approach to comparing a string with an empty string consists of making use of the functions @isempty(), or @equna().
Strictly spoken, your reply applies to comparisons with alpha series containing the value of an empty string, but not to quite to direct comparisons with an empty string or with a program variable referring to an empty string. With regard to the latter two, I still think there is a bug, or at least an inconsistency which may point to an issue of how strings and string variables are dealt with internally in EVIEWS.
The example code 1 below goes through various ways of checking
inequality with an empty string, generating the message strings message1-message8 and the corresponding indicator series m1-m8. All indicators series should come out as being equal to 1.
All messages and indicator series come out correctly and as expected, with the exceptions of a) message3 and the corresponding indicator series m3, and b) message 2, but here, the respective indicator series m2 is computed correctly as unity.
Regarding message3 and m3, they depict the outcome of the variant comparing (%test<>alpha_emptystring, and they give results in line with what you have said in your reply: message3 gives the wrong result of " "1" = alpha_emptystring " and the series m3 becomes a missing value.
message2 and m2 depict the outcome of the comparison (%test<>%emptystring). Here, message2 gives the incorrect outcome " "1" = emptystring " whereas series m2=(%test<>%emptystring) computes correctly to unity.
In contrast, message1, depicting the outcome of comparison (%test<>"" ), is correctly computed as " "1" <> "" " (and the corresponding indicator series m1=1 comes out correctly as well). The right outcome in message1 using an empty string directly contrasts with the wrong one in message2 using a program variable referring to an empty string.
Finally, it is funny that the same approaches of checking
equality with an empty string as in example code 2 gives overall consistent results. All indicator series compute to 0, with the exception of m3=(%test=alpha_emptystring) which yields a missing value; the respective message string message3 comes out correctly as " "1" <> alpha_emptystring ".
Best, mamo
Example code 1 - approaches to checking INEQUALITY with an empty stringCode: Select all
' Approaches to checking INEQUALITY with an empty string
wfcreate u 1
%test="1"
%emptystring=""
alpha alpha_emptystring=""
series m1=(%test<>"" )
if %test<>"" then
string message1=@addquotes(%test)+" <> """""
else
string message1 string message1=@addquotes(%test)+" = """""
endif
series m2=(%test<>%emptystring)
if %test<>%emptystring then
string message2=@addquotes(%test)+" <> emptystring"
else
string message2=@addquotes(%test)+" = emptystring"
endif
series m3=(%test<>alpha_emptystring)
if %test<>alpha_emptystring then
string message3=@addquotes(%test)+" <> alpha_emptystring"
else
string message3=@addquotes(%test)+" = alpha_emptystring"
endif
series m4=not @eqna(%test, "")
if not @eqna(%test, "") then
string message4=@addquotes(%test)+" is not equal to """""
else
string message4=@addquotes(%test)+" is equal to """""
endif
series m5=not @eqna(%test,%emptystring)
if not @eqna(%test,%emptystring) then
string message5=@addquotes(%test)+" is not equal to emptystring"
else
string message5=@addquotes(%test)+" is equal to emtpystring"
endif
series m6=not @eqna(%test,alpha_emptystring)
if not @eqna(%test,%emptystring) then
string message6=@addquotes(%test)+" is not equal to alpha_emptystring"
else
string message6=@addquotes(%test)+" is equal to alpha_emtpystring"
endif
series m7=not @isempty(%test)
if not @isempty(%test) then
string message7=@addquotes(%test)+" is not empty"
else
string message7=@addquotes(%test)+" is empty"
endif
series m8=not @isempty(%test)
if not @eqna(%test,%emptystring) then
string message8=@addquotes(%test)+" is not emptystring"
else
string message8=@addquotes(%test)+" is emptystring"
endif
for !i=1 to 8
show message{!i}
next
Example code 2 - approaches to checking EQUALITY with an empty stringCode: Select all
' Approaches to checking EQUALITY with an empty string
wfcreate u 1
%test="1"
%emptystring=""
alpha alpha_emptystring=""
series m1=(%test="" )
if %test="" then
string message1=@addquotes(%test)+" = """""
else
string message1=@addquotes(%test)+" <> """""
endif
series m2=(%test=%emptystring)
if %test=%emptystring then
string message2=@addquotes(%test)+" = emptystring"
else
string message2=@addquotes(%test)+" <> emptystring"
endif
series m3=(%test=alpha_emptystring)
if %test=alpha_emptystring then
string message3=@addquotes(%test)+" = alpha_emptystring"
else
string message3=@addquotes(%test)+" <> alpha_emptystring"
endif
series m4=@eqna(%test, "")
if @eqna(%test, "") then
string message4=@addquotes(%test)+" is equal to """""
else
string message4=@addquotes(%test)+" is not equal to """""
endif
series m5=@eqna(%test,%emptystring)
if @eqna(%test,%emptystring) then
string message5=@addquotes(%test)+" is equal to emptystring"
else
string message5=@addquotes(%test)+" is not equal to emtpystring"
endif
series m6=@eqna(%test,alpha_emptystring)
if @eqna(%test,%emptystring) then
string message6=@addquotes(%test)+" is equal to alpha_emptystring"
else
string message6=@addquotes(%test)+" is not equal to alpha_emtpystring"
endif
series m7=@isempty(%test)
if @isempty(%test) then
string message7=@addquotes(%test)+" is empty"
else
string message7=@addquotes(%test)+" is not empty"
endif
series m8=@isempty(%test)
if @eqna(%test,%emptystring) then
string message8=@addquotes(%test)+" is emptystring"
else
string message8=@addquotes(%test)+" is not emptystring"
endif
for !i=1 to 8
show message{!i}
next