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 <kramersdomain@yahoo.com>
To   statalist@hsphsun2.harvard.edu
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 <kitbaum@me.com> wrote:

> From: Kit Baum <kitbaum@me.com>
> Subject: st: re: how do I suppress output in Mata?
> To: statalist@hsphsun2.harvard.edu
> 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
> kitbaum@me.com
> 
> 
> 
> *
> *   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index