Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.

# st: Mata question: putting matrices along the diagonal

 From To statalist@hsphsun2.harvard.edu Subject st: Mata question: putting matrices along the diagonal Date Thu, 27 May 2010 14:02:43 -0400 (EDT)

```Dear Listers:

I am interested in making one large "diagonal" matrix out of a bunch of matrices in Mata. For example, suppose I have 3 2x2 matrices labeled m1, m2, and m3. I want to construct the matrix M, where M is something like:
M=
(m1[1,1],m1[1,2],     0,        0,           0, 0               \
m1[2,1],m1[2,2],     0,        0,           0, 0               \
0    ,   0,       m2[1,1],m2[1,2],     0, 0               \
0    ,   0,       m2[2,1],m2[2,2],     0,  0              \
0    ,   0,             0,        0,      m3[1,1],m3[1,2] \
0    ,   0,             0,        0,      m3[2,1],m3[2,2] )

That is, I seek to place each of the individual matrices along the diagonal, zeros elsewhere. In my problem, both the number of matrices and the dimensions of each matrix may be rather large.