Statalist


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

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


From   Kramer <[email protected]>
To   [email protected]
Subject   Re: st: re: how do I suppress output in Mata?
Date   Sun, 15 Nov 2009 23:19:25 -0800 (PST)

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?

Thank you again,

Kramer

--- On Sun, 11/15/09, Kit Baum <[email protected]> wrote:

> From: Kit Baum <[email protected]>
> Subject: st: re: how do I suppress output in Mata?
> To: [email protected]
> Date: Sunday, November 15, 2009, 4:27 AM
> <>
> I''m not sure what Kramer is unable to suppress, but this
> problem can be solved with much less code, I think:
> 
> clear all
> set obs 100
> g schl = _n
> g u = runiform()
> sort u
> egen dist = cut(u), group(10)
> g v = runiform()
> sort v
> drop u v
> 
> 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)
>     st_matrix("distmat", distmat)
> }
> end
> 
> mata: district()
> l schl dist
> mat list distmat  
> 
> 
> 
> Kit Baum
> [email protected]
> 
> 
> 
> *
> *   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/
> 


      

*
*   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