Yes, I was looking for an alternative to the ternary statement. I should’ve picked up the
boolean-on-a-series problem.
Cheers,
PS
Sent from my iPad
On Sep 7, 2024, at 7:05 AM, Riccardo (Jack) Lucchetti
<p002264(a)staff.univpm.it> wrote:
***This email is from an external source. Only open links and attachments from a Trusted
Sender.***
> On 07/09/2024 11:18, Sven Schreiber wrote:
>> Am 06.09.2024 um 22:53 schrieb Summers, Peter:
>>
>> Hi all,
>>
>> When trying to use the console to create a new variable, I get an error message
after typing “if (female == 1)” saying “error evaluating ‘if’”. I’ve also tried it with a
script and get the same result. This is on Windows, latest snapshot (office desktop) and
also with the previous win64.zip snapshot (classroom). I’ve tried spacing/no spacing,
parentheses & not, all with no change.
>>
> If 'female' is a series, then 'female==1' will also yield a (dummy)
series, and that won't work with a boolean check, because what should the result be?
So an if-block needs a scalar/unique input for evaluation. Perhaps you should give more
context as to what you are trying to achieve. For example, a ternary statement is often
useful.
I'm assuming you want to perform some action on a subsample only. In that case, the
most general way to do so is to use a "smpl" statement, as in
<hansl>
smpl female == 1 --restrict
ols foo const bar baz
# ... more commands ...
</hansl>
and you use a "smpl full" statement to go back to the full sample. As Sven
said, in case all you want to do is assign to a variable conditionally, the ternary
assignment operator is very handy, as in
<hansl>
series femage = (female == 1) ? age : NA
</hansl>
where I added parentheses for clarity., but they aren't necessary.
-------------------------------------------------------
Riccardo (Jack) Lucchetti
Dipartimento di Scienze Economiche e Sociali (DiSES)
Università Politecnica delle Marche
(formerly known as Università di Ancona)
r.lucchetti(a)univpm.it
http://www2.econ.univpm.it/servizi/hpp/lucchetti
-------------------------------------------------------
_______________________________________________
Gretl-users mailing list -- gretl-users(a)gretlml.univpm.it
To unsubscribe send an email to gretl-users-leave(a)gretlml.univpm.it
Website:
https://gretlml.univpm.it/postorius/lists/gretl-users.gretlml.univpm.it/