Page 1 of 1

Row index of the n-highest value

Posted: Mon May 11, 2020 6:04 pm
by Laurel
How do I find the row index of the n-highest value in a group similar to @rimax (n = 2nd, 3rd,...etc.)? Thanks.

Re: Row index of the n-highest value

Posted: Tue May 12, 2020 11:26 am
by EViews Matt
Hello,

You can construct a matrix where the n-th column holds the indices of the n-th largest value in each row. You could then utilize the column of interest. For example, for a group named "g",

Code: Select all

matrix tmp1 = @transpose(@colcumsum(@ones(@columns(g), @rows(g)))) matrix tmp2 = @rowranks(@convert(g), "d") for !i = 1 to @rows(tmp1) rowplace(tmp1, @rapplyranks(@rowextract(tmp1, !i), @rowextract(tmp2,!i)), !i) next
The index matrix is "tmp1" in this example. It's first column would match the results of @rimax.