Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: RE: RE: Sorting rows in Mata


From   Andrew Maurer <Andrew.Maurer@qrm.com>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   st: RE: RE: RE: Sorting rows in Mata
Date   Mon, 24 Feb 2014 17:52:54 +0000

Hi Simone,

Try this:
mata
mymat=(0,3,2,4\3,0,1,6\2,1,0,5\4,6,5,0)

for (i=1;cols(mymat);i++) {
	mymat[., i] = sort(mymat[.,i], 1)
}

mymat
end

(I'm not sure why it gives the error " <istmt>:  3301  subscript invalid", but it produces the output you require)

Best,
Andrew Maurer 


-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Simone Angioloni
Sent: Monday, February 24, 2014 11:40 AM
To: statalist@hsphsun2.harvard.edu
Subject: st: RE: RE: Sorting rows in Mata

Hi Andrew,

I knew this command, but it seems not perfectly fit.

My matrix is like this:

mymat=(0,3,2,4\3,0,1,6\2,1,0,5\4,6,5,0)

and I need something like:

0,2,3,4
0,1,3,6
0,1,2,5
0,4,5,6

Thank you
Simone

________________________________________
From: owner-statalist@hsphsun2.harvard.edu <owner-statalist@hsphsun2.harvard.edu> on behalf of Andrew Maurer <Andrew.Maurer@qrm.com>
Sent: Monday, February 24, 2014 12:05 PM
To: statalist@hsphsun2.harvard.edu
Subject: st: RE: Sorting rows in Mata

Hi Simone,

Is mata's sort() function what you're looking for? Try "help mata sort()"

Eg:
mata
mymat = (3 \ 1 \ 4 \ 2), (6 \ 7 \ 8 \ 9) mymat
sort(mymat,1)
end

Best,
Andrew Maurer

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Simone Angioloni
Sent: Monday, February 24, 2014 10:57 AM
To: statalist@hsphsun2.harvard.edu
Subject: st: Sorting rows in Mata

Hi,

Is there a canned command to sort rows in ascending order in Mata without exporting the matrix to Stata and using the rowsort()?

I need to do that in Mata because the marix is very large (more than 1000 by 1000) and once I export the matrix to Stata I have rounding errors that make the matrix slightly different from the original.

Thank you in advance.

Simone Angioloni

University of Georgia


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/



*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/



*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index