Hello.
Could someone please tell me where this mata code is wrong ? It gives
an error as " unexpected end of line ". I am making some basic mistake
which I can't figure out.
Thank you,
Ashim.
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
clear
use data
keysortrows(x1 x2), key(k1 k2)
list
On 9/12/08, Ashim Kapoor <[email protected]> wrote:
> Hello Marten,
>
> Thank you for your reply. I never quite could understand what ///
> means ? Is that a comment ? Could you please tell me what that is ? I
> was modifying a code where I found that.
>
> Thank you,
> Ashim
>
> On 9/12/08, Maarten buis <[email protected]> wrote:
> > I haven't looked at the rest of the program, but you should have
> > commented out a hard return after the line: -key(string)-
> >
> > program define keysortrows
> > version 9
> > syntax varlist(min=2) , ///
> > [ ///
> > key(string) ///
> > ]
> >
> > (You don't want to know how often I made that mistake when adding a new
> > option...)
> >
> > -- Maarten
> >
> > --- Ashim Kapoor <[email protected]> wrote:
> >
> > > 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/
> > >
> >
> >
> > -----------------------------------------
> > Maarten L. Buis
> > Department of Social Research Methodology
> > Vrije Universiteit Amsterdam
> > Boelelaan 1081
> > 1081 HV Amsterdam
> > The Netherlands
> >
> > visiting address:
> > Buitenveldertselaan 3 (Metropolitan), room N515
> >
> > +31 20 5986715
> >
> > http://home.fsw.vu.nl/m.buis/
> > -----------------------------------------
> >
> >
> >
> > *
> > * 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/
> >
>
*
* 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/