Good morning. A few months back I queried regarding executing MLE from the script window with a piecewise density.
It was suggested that
<<
it should be quite easy if you use functions:

<pseudo-hansl>
function series f(series u, scalar a, scalar b)
    [whatever]
end function

function series g(series u, scalar a, scalar b)
    [whatever]
end function

function series loglik(series y, list X, matrix coef,
                        scalar a, scalar b)

     series u = y - lincomb(X, coef)
     series logl = (u>0) ? g(u, a, b) : f(u, a, b)
     return logl
end function


mle ll = logl(y, X, coef, a, b)
     coeff coef a b
end mle
</pseudo-hansl>

Hope this helps!

-------------------------------------------------------
   Riccardo (Jack) Lucchetti
   Dipartimento di Scienze Economiche e Sociali (DiSES)
>>

 
Based on the above, I tried a simpler case, estimating parameters (no regression), (and with a sample of 3 so as to do it also by hand and check results), as follows
(I use the density of the difference of two independent exponentials with different parameters)

nulldata 3

#series Z = {-1, 1, 2}

scalar s1 =1
scalar s2 = 1
function series negbr(series Z, scalar s1, scalar s2)
    -ln(s1+s2)+ (1/s2)*Z
end function

function series posbr(series Z, scalar s1, scalar s2)
    -ln(s1+s2)-(1/s1)*Z
end function

function series loglik(series Z, scalar s1, scalar s2)
    series liky = (Z>0)? posbr(series Z, scalar s1, scalar s2): negbr(series Z, scalar s1, scalar s2)
    return liky 
end function


mle logl = loglik(Z, s1, s2)
params s1 s2
end mle --verbose

and what I get as a reply is

gretl version 1.9.92
Current session: 2015-02-04 06:48

> series liky = (Z>0)? posbr(series Z,
Expected ',' but found 'Z'
> series liky = (Z>0)? posbr(series Z,
Expected ':' but found 'Z'
Syntax error
*** error in function loglik, line 1
> series liky = (Z>0)? posbr(series Z, scalar s1, scalar s2): negbr(series Z, scalar s1, scalar s2)

Error executing script: halting
> end mle --verbose


I guess this is pretty simple, and the problem is just my inexperience, but I cannot understand the expectations of the software here. So I am calling for help again. Thank you.

Alecos Papadopoulos
Athens University of Economics and Business, Greece
Department of Economics
cell:+30-6945-378680
fax: +30-210-8259763
skype:alecos.papadopoulos