Statalist


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

st: sorting rows with a key.


From   "Ashim Kapoor" <[email protected]>
To   [email protected]
Subject   st: sorting rows with a key.
Date   Fri, 12 Sep 2008 10:26:54 +0530

Hello everyone,

I have written a small program which sorts rowwise using a "key". I am
new to mata so maybe I am not getting the syntax correct although I
believe I have the logic of the code right.
The code gives me an error " invalid syntax " after the execution of the line
 "keysortrows(x1 x2), key(k1 k2) "

Could someone please point out my mistake?

Below is the code :-

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

    marksample touse, strok novarlist

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


end


clear

use data

keysortrows(x1 x2), key(k1 k2)

list

version 9
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