Hello
I use eviews7.
I got a matrix(7,2) containing 2 vectors (V1,V2).
I would like to "sort", "rank" or "order" (whatever the command name), by descending order, the matrix using V1 (V2 reorders as well depending on V1 and is not fixed).
Then identify the 2nd max of V1 (logically the 2nd row), and index the name.
Then extract the corresponding 2nd line of V2 to check if the value is bellow a threshold.
I know that Eviews allows group.sort(X1,X2)
but how can I handle it with matrix?
thanks
how to sort a matrix from one of its vector?
Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13604
- Joined: Tue Sep 16, 2008 5:38 pm
Re: how to sort a matrix from one of its vector?
use the capplyranks function.
Re: how to sort a matrix from one of its vector?
Thanks but I don't understant how to use this command.
m1: input matrix (8 lines, 2 columns) with 2 columns named respectively C1 and C2
m2: output ordered matrix
matrix m2 = @capplyranks(m1, C1) 'doesn't work
m1: input matrix (8 lines, 2 columns) with 2 columns named respectively C1 and C2
m2: output ordered matrix
matrix m2 = @capplyranks(m1, C1) 'doesn't work
-
EViews Glenn
- EViews Developer
- Posts: 2682
- Joined: Wed Oct 15, 2008 9:17 am
Re: how to sort a matrix from one of its vector?
This is off the top of my head, but
should do what you want. The first line extracts the ranks from the first column of M1, and the second applies the ranks to the rows of M1. You should, of course, be able to put this in one long line as in
Note also that I'm using @rapplyranks which sorts the rows. You can guess what @capplyranks does :)
Code: Select all
vector rks1 = @ranks(@columnextract(m1, 1))
matrix m2 = @rapplyranks(m1, rks1)Code: Select all
matrix m2 = @rapplyranks(m1, @ranks(@columnextract(m1, 1)))Re: how to sort a matrix from one of its vector?
When I apply proposed code to a matrix that contains around 30.000 rows, I obtain the following error message: "Invalid permutation index vector".
Is there a size limit for @rapplyranks?
Is there a size limit for @rapplyranks?
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13604
- Joined: Tue Sep 16, 2008 5:38 pm
Re: how to sort a matrix from one of its vector?
I don't believe so - here's one that works for me with a matrix with 40,000 rows:
Code: Select all
create u 100
matrix(40000,4) m1
rnd(m1)
vector rks1 = @ranks(@columnextract(m1, 1))
matrix m2 = @capplyranks(m1, rks1)
Re: how to sort a matrix from one of its vector?
Hi, I am facing a problem very similar to the one described by thierrydb ( a while ago now!),
and it seems to me that the problem when the number of rows is very large is that some rows have the same rank.
Here is an example of the problem in rows 1221 and 1222.
R1217 1217
R1218 1218
R1219 1219
R1220 1220
R1221 1221.5
R1222 1221.5
R1223 1223
R1224 1224
R1225 1225
I guess that when the entries the same the ranking vector gives them equal rank. This unfortunately gets in the way of sorting the matrix. Would be grateful for any suggestions to get around this.
Thank you
Michele
and it seems to me that the problem when the number of rows is very large is that some rows have the same rank.
Here is an example of the problem in rows 1221 and 1222.
R1217 1217
R1218 1218
R1219 1219
R1220 1220
R1221 1221.5
R1222 1221.5
R1223 1223
R1224 1224
R1225 1225
I guess that when the entries the same the ranking vector gives them equal rank. This unfortunately gets in the way of sorting the matrix. Would be grateful for any suggestions to get around this.
Thank you
Michele
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13604
- Joined: Tue Sep 16, 2008 5:38 pm
Who is online
Users browsing this forum: No registered users and 2 guests
