On Fri, 24 Apr 2020, Sven Schreiber wrote:
Am 24.04.2020 um 18:33 schrieb Riccardo (Jack) Lucchetti:
> On Fri, 24 Apr 2020, Alecos Papadopoulos wrote:
>
>> I thought we had a sign function in gretl but I cannot find it
>> (returning 1 if positive -1 if negative, 0 if zero)
>> ...
>>
>> but the sign seems pretty fundamental to be an expression or a
>> user-defined function. Is it hidden somewhere? :)
>
> That said, conditional assignment is your friend. The sign of x can be
> easily wriiten as
>
> s = x==0 ? 0 : (x>0 ? 1 : -1)
>
another example of the relativity of "easy" ;-)
Ok, let's say "concisely", then :)
But you're right on the relativity of "easy": for example, I find it
extremely difficult to come to terms with the fact that many people
consider conditional assignmment an obscure geeky thing, and then happily
use the IF() function in spreadsheets with no apparent effort.
I agree that in most practical appliations you don't really want
to
blindly write down the sign function that appears in the printed formula
because more efficient reformulations exist. But I still think Alecos
may have a point here. At least another candidate for the 'extra' package?
Such as
<hansl>
function matrix sign(matrix X)
return (X.=0) ? 0 : ((X.>0) ? 1 : -1)
end function
</hansl>
?
-------------------------------------------------------
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
-------------------------------------------------------