Statalist


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

Re: st: Converting macro string of numbers to matrix or vector


From   Phil Schumm <pschumm@uchicago.edu>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Converting macro string of numbers to matrix or vector
Date   Thu, 15 May 2008 17:46:02 -0500

On May 15, 2008, at 5:13 PM, E. Paul Wileyto wrote:
I have a string macro that contains a list of numbers, and I need to convert that list to a vector.

. loc mylist "1 2 3"

. mata: strtoreal(tokens(st_local("mylist")))
1 2 3
+-------------+
1 | 1 2 3 |
+-------------+


or, if you want to create a Stata vector,


. mata: st_matrix("foo", strtoreal(tokens(st_local("mylist"))))

. mat li foo

foo[1,3]
c1 c2 c3
r1 1 2 3


For more info, see -help mata functions-; in particular, the Stata interface functions and string functions.


-- Phil

*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* 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