Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: mata orgtype


From   George Vega Yon <g.vegayon@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: mata orgtype
Date   Tue, 23 Apr 2013 08:46:33 -0300

May be you can try cheating mata. This is by adding an empty first element like

Prods="",tokens(...

And start the loop from the second element. This way you will be sure
that you are working with a rowvector.

Cheers,

George Vega Yon
7 647 2552
http://cl.linkedin.com/in/georgevegayon


2013/4/23 Nick Cox <njcoxstata@gmail.com>
>
> I don't recall seeing this varying behaviour, but then again I don't
> think I have ever tried this.
>
> I think we'd need a reproducible example to comment.
>
> Meanwhile, the main purpose of -levelsof- was, and is, to make
> analyses easier in Stata. A near equivalent in Mata is to apply
> -uniqrows()- to variables read in as vectors. I'd expect that to be
> faster too.
>
> Nick
> njcoxstata@gmail.com
>
>
> On 23 April 2013 00:29, Tomáš Houška <xbender@gmail.com> wrote:
>
> > I have a Stata macro generated by -levelsof- and I am trying to parse
> > it in mata with -tokens- so that I can run mata loops with it...
> > example:
> >
> > levelsof product, local(product_id)
> > mata
> > prods=tokens(st_local("product_id"))
> > for(i = 1; i<=length(prods); i++) {
> > ... commands including prods[i] ...
> > }
> > end
> >
> > My problem is that on some types of variables, the resulting mata item
> > (in this case "prods") is a row vector, but sometimes it is a scalar
> > string. Once it is a scalar string, I cannot refer to items on
> > individual positions by -prods[i]- as I can do when it is a row
> > vector.
> > Is there a rule to which type gets created and when? Or is there a way
> > to make sure that row vector  gets created?
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


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