Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Nick Cox <njcoxstata@gmail.com> |
To | "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |
Subject | Re: st: mata orgtype |
Date | Tue, 23 Apr 2013 08:19:23 +0100 |
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/