Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: I did it! sorting with a key.


From   "Ashim Kapoor" <[email protected]>
To   [email protected]
Subject   st: I did it! sorting with a key.
Date   Fri, 12 Sep 2008 14:28:05 +0530

Hi guys!

I wrote a code which is the SAME as sortrows but it sorts with a KEY.

Here is the ado file :-

 program define keysortrows
    version 9
    syntax varlist(min=2) ,         ///
    [                               ///
        key(string)		    ///	
    ]

    marksample touse, strok novarlist

    mata:_keysortrower("`varlist'", "`key'","`touse'")
end

mata:
void _keysortrower(string scalar varlist,string scalar key,string scalar touse)
{

	 real matrix x

	 st_view(X,.,tokens(varlist),touse)
	 st_view(Y,.,tokens(key), touse)


	for(i=1;i<=rows(X);i++){
	x=(X[i,.]\Y[i,.])

	x=sort(x',2)

	x=x'
	X[i,.]=x[1,.]
	Y[i,.]=x[2,.]
	}
}
end
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index