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/