On Wed, 25 Mar 2015, Henrique Andrade wrote:
Dear Gretl community,
I'm not a good "if-else" user so I need a little help. What's wrong
with
the following code?
<hansl>
open australia.gdt
series E_hp = E - hpfilt(E, 1600)
if E > E_hp
series E_reg1 = E
series PAUreg1 = PAU
series PUSreg1 = PUS
else
series E_reg1 = NA
series PAUreg1 = NA
series PUSreg1 = NA
endif
<hansl>
When I execute it I get the messages: "error evaluating 'if'"
"Error
executing script: halting".
The problem is that "if" needs a scalar true/false condition. In your
script the condition "E > E_hp" produces a series result (with the
condition satisfied at some observations but not others).
To do what I think you want here you can using the conditional
operator "?:", as in
series E_reg1 = E > E_hp ? E : NA
series PAUreg1 = E > E_hp ? PAU : NA
and so on.
Allin