Statalist


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

Re: st: sorting rows with a key.


From   "Ashim Kapoor" <ashimkapoor@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: sorting rows with a key.
Date   Fri, 12 Sep 2008 11:56:48 +0530

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 <maartenbuis@yahoo.co.uk> 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 <ashimkapoor@gmail.com> 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/



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