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)
The need arose in estimating AR(1) procecess with a near-unit root. Following
Hamilton's advise in order to avoid crashing the iterative algorithm, I
reparametrize the autoregressive coefficient rho by
rho = lambda / (1 + abs(lambda)
Then
lambda = rho / (1- sgn{rho} *rho).
Certainly one can write
sign(rho) = (1- (rho==0) )* (1- 2*(rho <0)),
or something more efficient,
but the sign seems pretty fundamental to be an expression or a user-defined
function. Is it hidden somewhere? :)
Hm, how is "lambda = rho / (1- sgn{rho} *rho)" different from
"lambda = rho / (1-abs(rho))"?
That said, conditional assignment is your friend. The sign of x can be
easily wriiten as
s = x==0 ? 0 : (x>0 ? 1 : -1)
but expressions like "z = sign(x) * y" translate into even easier
constructs:
z = x > 0 ? y : -y
HTH,
-------------------------------------------------------
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
-------------------------------------------------------