Statalist


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

Re: st: rowshape of a matrix - stata10-


From   Maarten buis <maartenbuis@yahoo.co.uk>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: rowshape of a matrix - stata10-
Date   Wed, 2 Sep 2009 19:50:29 +0000 (GMT)

--- On Wed, 2/9/09, Herve STOLOWY wrote:
> I get the matrix m1 with the following command:
> 
> statsmat foreign_rel, s(N mean) by(year_d2) mat(m1), if
> treatment==1
> 
> m1[2,2]
>            N 
>      mean
> 0        379  .18760868
> 1        484  .31070169
> 
> I would like to reshape this matrix to get  everything
> in one line:
> 
>  N       mean    N Mean
> 0/1       379 
> .18760868  484  .31070169.
> 
> It is possible?
> 
> I found the rowshape command but don't know how to use it.
> I understood that it is based on Mata but never used Mata. I
> tried something:
> 
> mata
> rowshape (m1,2)
> 
> but get an error message: <istmt>:  3499 
> m1 not found.

You have to get that matrix into Mata using the -st_matrix()-
command (and you can get that matrix back into Stata using
the same command). See the example below:

*------------- begin example --------------
sysuse auto, clear
statsmat mpg, s(N mean) by(foreign) mat(m1)
mata
m1 = st_matrix("m1")
m1 = rowshape (m1,1)
st_matrix("m1", m1)
end
matrix list m1
*------------- end example ------------------
( For more on how to use examples I sent to statalist see:
http://www.maartenbuis.nl/stata/exampleFAQ.html )

Hope this helps,
Maarten

PS. For others who want to use this code: -statsmat- 
is a user written program by Nick Cox and Kit Baum 
which is downloadable from SSC by typing in Stata:
-ssc install statsmat-.

--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany

http://www.maartenbuis.nl
--------------------------


      

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