Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: re: matrix manipulation


From   Kit Baum <baum@bc.edu>
To   statalist@hsphsun2.harvard.edu
Subject   st: re: matrix manipulation
Date   Thu, 11 Dec 2008 11:00:15 -0500

<>
Susan said

I would like to create a binary matrix (say matrix B) using
the existing information from current matrix A.

Specifically, for each cell (i,j) of matrix B, I want to
replace its value with 1 if the value of the corresponding
cell (i,j) of matrix A is less than the specified threshold
value. In other words, matrix B[i,j] = 1 if A[i,j] <
THRESHOLD.


No subscripting required:

--------------------------------
mata: mata clear
mata:
void underbar(string scalar mat,
              real scalar thresh)
{
	st_matrix("B", (st_matrix(mat) :< thresh))
}
end

sysuse auto,clear
qui reg price trunk weight length turn
mat list e(V)
mata: underbar("e(V)",0.0001)
mat list B
-----------------------------------

You could pass the name of the result matrix to Mata as well if you wanted this to be a bit more general.

Kit Baum, Boston College Economics and DIW Berlin
http://ideas.repec.org/e/pba1.html
An Introduction to Modern Econometrics Using Stata:
http://www.stata-press.com/books/imeus.html


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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