Statalist


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

st: Re: how do I suppress output in Mata?


From   Kit Baum <[email protected]>
To   [email protected]
Subject   st: Re: how do I suppress output in Mata?
Date   Mon, 16 Nov 2009 06:34:43 -0500

<>
I imagined that you wanted it in Stata, as you were returning it. This illustrates how you can get the object back to another Mata routine without having it displayed.

mata:
void district(real matrix distmat) 
{
	st_view(d, ., "dist")
	distmat = J(rows(d),rows(d),0)
	for(i=1; i<=rows(d); i++) {
		for(j=1; j<i; j++) {
			distmat[i,j] = (d[i]==d[j])
		}
	}
	_makesymmetric(distmat)
	return
}

void calldist() 
{
"Now in calldist"
district(distmat)
"No output yet"
distmat[.,1]
}
end

mata: calldist()



Kit

On Nov 16, 2009, at 2:33 AM, statalist-digest wrote:

> Kit - Thank you for not only suggesting the command "st_matrix" but for reworking my code to make it so much more efficient.  When you use the "return()" command instead, the whole matrix prints to the screen, which is unfortunate when the matrix is large.  
> 
> The one question I have is that the "st_matrix" command saves the matrix district() creates to Stata, not mata.  I can then import the matrix to mata using the st_matrix command, but that seems like a waste of memory.  Is there a way to put it in mata in the first place?


Kit Baum   |   Boston College Economics & DIW Berlin   |   http://ideas.repec.org/e/pba1.html
                              An Introduction to Stata Programming  |   http://www.stata-press.com/books/isp.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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index