I think the reason this fails is that the condition should result in a boolean scalar,
whereas here it is a series of booleans.
In this case you can use the ternary operator to set up a conditional assignment (see User
Guide p. 140):
<hansl>
open australia.gdt
series E_hp = E - hpfilt(E, 1600)
series E_reg1= (E > E_hp) ? E : NA
series PAUreg1 = (E > E_hp) ? PAU : NA
series PUSreg1 = (E > E_hp) ? PUS : NA
<hansl>
HTH,
Jan Annaert
UNIVERSITEITANTWERPEN | Faculty of Applied Economics (TEW) | Dept. Accounting &
Finance
Room S.B.335 | Prinsstraat 13 | B-2000 Antwerp | Belgium
Phone +32 32654163 |Fax +32 32654064
https://www.uantwerp.be/en/staff/jan-annaert/
http://ssrn.com/author=143473
From: Henrique Andrade
<henrique.coelho@gmail.com<mailto:henrique.coelho@gmail.com>>
Reply-To: "gretl-users@lists.wfu.edu<mailto:gretl-users@lists.wfu.edu>"
<gretl-users@lists.wfu.edu<mailto:gretl-users@lists.wfu.edu>>
Date: woensdag 25 maart 2015 17:15
To: "gretl-users@lists.wfu.edu<mailto:gretl-users@lists.wfu.edu>"
<gretl-users@lists.wfu.edu<mailto:gretl-users@lists.wfu.edu>>
Subject: [Gretl-users] "If-Else" syntax help
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".
Best regards,
Henrique Andrade