Richard Boylan <[email protected]> asked
> I am wondering how one can use a matrix created in STATA (outside MATA) and
> use in MATA.
>
> Specifically, I would like a .do file to do something like this:
. ... ...
. matrix adjp = (adj1', adj2', adj3', adj4')
. mata r = rank(adjp)
. gen newr = r
The Mata function st_matrix() (see -help mata st_matrix()-) is what Richard is
looking for. st_matrix(string scalar name) returns the contents of Stata
matrix name; st_matrix("adjp") returns the contents of Stata matrix adjp.
Richard could type
. ... ...
. matrix adjp = (adj1', adj2', adj3', adj4')
. mata r = rank(st_matrix("adjp"))
. gen newr = r
I feel obligated to add my oft-repeated comment that the rank of a matrix is
in the eye of the beholder, or at least, the formulas of the corresponding
inverter and solver.
A matrix is numerically full rank when the result of some calculation is
greater than some tolerance. You might calculate rank(X) using Mata and
discover the matrix is full rank and, even so, later, were you to use luinv()
to invert it, find that luinv() reports the matrix is not full rank! That is
possible because luinv() uses a different formula than that used by rank().
All of this, and more, is mentioned in -help mata rank()-.
-- 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/