On Mon, 10 Oct 2016, guido giaume wrote:
Dear Sven
thanks for your quick answer.
My Gretl version is 2016-c but it does not matter.
You are right, I didnt tell all the story. But was not for cheating. I
tried to cut short the description of the problem.
I mentioned a matrix, but indeed I was working with a 1 row "matrix".
My real problem is ranking some time series, day by day;
And the trouble is the sorting mismatch the names of the series with
their values.
(E.G.) If I have A, B, C, D daily series and I want (recursively) rank
their values at day t, and then at day t+1, and so on, I am in
trouble,
because all my attempt of sorting does not keep the values with the
original series names, while in Excel is trivial.
I tried in many ways, unsuccessfully.
My last attempt was
a) limiting the whole dataset to only 1 day, (by
smpl)
b) declaring it as a one row matrix
c) giving it the right names
(via colnames)
d) ranking the values
but as before, I got the (values) rank but I lost the match with the names of time
series.
So any help, or reference to the User Guide, will be greatly appreciated.
I don't think this problem is considered in the User's Guide.
However, it's not beyond hansl's capacity. If I understand you
correctly, the following script should provide a template. We start
with a "raw" matrix M containing 4 "series" (columns) followed by
consective ID numbers of those series. After the loop we have a
matrix Ms where each row is sorted by value of the "series", and the
ID numbers are also reordered to show if it's series 1, 2, 3 or 4
that has the smallest values, the next smallest value, and so on.
<hansl>
scalar T = 100
# raw data
matrix M = mnormal(T,4) ~ mshape(seq(1,4), 4, T)'
matrix Ms = zeros(T,8)
loop i=1..T -q
matrix tmp = msortby((M[i,1:4] | M[i,5:])',1)
Ms[i,] = tmp[,1]' ~ tmp[,2]'
endloop
print M
# sorted data
print Ms
</hansl>
Allin Cottrell