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
-------------------------------------------------------