[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: how can I make a string matrix?
Edgard Alfonso Polanco Aguilar <email@example.com> 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 <firstname.lastname@example.org> 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.
* For searches and help try: