Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: MATA/matarix

From (William Gould, Stata)
Subject   Re: st: MATA/matarix
Date   Fri, 16 Sep 2005 10:40:23 -0500

Richard Boylan <> 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
*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index