[Allin] : <<I'm not sure what you mean by "the immediately smaller value".>>

Assume I have a discrete series X of size n= 5 as follows : x(1) = 5, x(2) = -3, x(3)= 2, x(4) = 2, x(5) =5.

The range of the variable is discrete, X in {-3, 2, 5}.

Then the Y variable series I need would be

y(1) = 2 (because in the range of X, the immediately smaller value from 3, which is the value of x(1), is 2)

y(2) = Since x(2) has the minimum value in the range of X, the value of y(2) should be set/fixed a priori.

y(3) = -3 (because in the range of X, the immediately smaller value from 2, which is the value of x(3), is -3)

y(4) = -3 (because in the range of X, the immediately smaller value from 2, which is the value of x(4),  is -3)

y(5) = 2 (because in the range of X, the immediately smaller value from 5, which is the value of x(5),  is 2)

The comparison/relation  is not with previous values of X along the index of the series, but it is related to the unique values in the range of X.

Why do I want the Y-series ? Because I have a likelihood where at each observation (i), an integral must be evaluated with upper limit x(i) and lower limit y(i). The X series is part of the sample. The Y series must be created.

Conceptually it requires a "lookup" action: we take the value of x(i), we lookup the unique values in the range of X, we choose the "immediately smaller" value in there, and we set it as the value of y(i). If we find that the value of x(i) is the smallest value in the range of X, we have set a priori a given value to be taken by y(i).


Initial message

2) I was unable to determine the combination of Gretl commands that will give me the following:

Let X be a series, X(i), i=1,...,n. I want to create the following series

Y(i) = "the immediately smaller value than X(i) in the X series".

(If the Y series is created using a loop, I guess I can deal with what happens when X(i) is the minimum value in the series by an "if" command)

E.g. if the X series has unique values {-3,  -1,     5,   17}, then X(i) = 5 => Y(i) = -1, X(j) = -1 => Y(j) = -3,   etc. I would much appreciate any ideas.

-- 
Alecos Papadopoulos PhD
Athens University of Economics and Business
web: alecospapadopoulos.wordpress.com/
cell:+30-6945-378680
skype:alecos.papadopoulos