Statalist The Stata Listserver


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

Re: st: how can I make a string matrix?


From   [email protected] (William Gould, StataCorp LP)
To   [email protected]
Subject   Re: st: how can I make a string matrix?
Date   Tue, 15 May 2007 08:28:12 -0500

Edgard Alfonso Polanco Aguilar <[email protected]> writes

> I'm working is Stata9 SE and I need to create a string matrix. Stata's 
> matrix commands don't allow me to make such a thing and I've tried 
> defining it on Mata and then call it from Stata but I haven't found a 
> way to do it. Does anybody knows a command or a way to make such a thing?

My first reaction is to agree with Maarten Buis <[email protected]> who
wrote, "Why do you think you need a string matrix? Stata is designed in such a
way that it is extremely rare that you need such a thing."  Maartin's point is
that there may be an easier way to Solve Edgard's problem.

Edgard didn't didn't say what he wanted to do with the matrix in Stata, 
so let's just assume Edgard will need the elements one a time.  One way 
from Stata to access the [1,3] element of global Mata matrix A, and store the
result in local macro -mymac-, is 

        . mata: st_local("mymac", A[1,3])

After that, in Stata, one would refer to `mymac' (in single quotes) to 
obtain the contents, as in 

        . display "The 1,3 element is `mymac'"

To store the contents of local macro mymac in preexisting matrix B, say 
element B[2,7], one could code 

	. mata: B[2,7] = "`mymac'"

I emphasize that the above -- use of Mata, global matrices, macros, and 
element-by-element access from Stata -- is not the way Mata is usually used.


-- Bill
[email protected]
*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index