Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: Mata data question


From   Benjamin Allaire <[email protected]>
To   <[email protected]>
Subject   Re: st: Mata data question
Date   Tue, 2 Aug 2011 10:43:04 -0400

Many thanks to tzygmund mcfarlane and Rafal. This worked.

I have an additional question about the spmat utility.  

I can't seem to get it to band the matrix in the example, why?

. 
. mata:
-------------------------------------------------------
:         void blkdiag(real matrix gr, real matrix G_in, real matrix G_out) {
>                         if (G_in == .) G_out = gr
>                         else G_out = blockdiag(G_in, gr)        
>         }

: end
---------------------------------------------------

. 
. 
. mata: blkdiag(J(3,3,1)-I(3),G=.,G)

. mata: blkdiag(J(2,2,1)-I(2),G,G)

. mata: blkdiag(J(4,4,1)-I(4),G,G)

. 
. mata: G
[symmetric]
       1   2   3   4   5   6   7   8   9
    +-------------------------------------+
  1 |  0                                  |
  2 |  1   0                              |
  3 |  1   1   0                          |
  4 |  0   0   0   0                      |
  5 |  0   0   0   1   0                  |
  6 |  0   0   0   0   0   0              |
  7 |  0   0   0   0   0   1   0          |
  8 |  0   0   0   0   0   1   1   0      |
  9 |  0   0   0   0   0   1   1   1   0  |
    +-------------------------------------+

. 
. 
. spmat putmatrix Gsp G, replace

. 
. spmat summarize Gsp

Summary of spatial-weighting object Gsp
----------------------------------------
        Matrix |            Description
---------------+------------------------
    Dimensions |                  9 x 9
     Stored as |                  9 x 9
 Values        |
           min |                      0
         min>0 |                      1
          mean |               .2469136
           max |                      1
----------------------------------------

. spmat tobanded Gsp, replace
spmat object Gsp not found
r(498);

end of do-file


 		 	   		  
*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index