Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: tabstat: values in columns instead of rows?


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: tabstat: values in columns instead of rows?
Date   Wed, 12 Apr 2006 13:59:05 +0100

One way to do it is via -tabstatmat- from SSC. 
You will want to add sensible formats. 

. sysuse auto, clear
(1978 Automobile Data)

. tabstat turn trunk length, by(foreign) s(mean) save 

Summary statistics: mean
  by categories of: foreign (Car type)

 foreign |      turn     trunk    length
---------+------------------------------
Domestic |  41.44231     14.75  196.1346
 Foreign |  35.40909  11.40909  168.5455
---------+------------------------------
   Total |  39.64865  13.75676  187.9324
----------------------------------------

. tabstatmat mymatrix

mymatrix[3,3]
               turn      trunk     length
Domestic  41.442308      14.75  196.13462
 Foreign  35.409091  11.409091  168.54545
   Total  39.648649  13.756757  187.93243

. matrix mymatrix = mymatrix'

. mat li mymatrix

mymatrix[3,3]
         Domestic    Foreign      Total
  turn  41.442308  35.409091  39.648649
 trunk      14.75  11.409091  13.756757
length  196.13462  168.54545  187.93243

Nick 
[email protected] 

Sauermann, Jan
 
> I want to create a cross-table in the following form:
>  
>         | VAR1 == 0                  | VAR1 == 1              
>     | Total
> --------+----------------------------+------------------------
> ----|-------------
> X_1     | mean of X_1 (if VAR1 == 0) | mean of X_1 (if VAR1 
> == 1) | mean of X_1
> X_2     | mean of X_2                | mean of X_2            
>     | mean of X_2
>   .     |    .                       |    .                   
>     |   .
>   .     |    .                       |    .                   
>     |   .
>   .     |    .                       |    .                   
>     |   .
>   .     |    .                       |    .                   
>     |   .
>   .     |    .                       |    .                   
>     |   .
> X_N     | mean of X_N                | mean of X_N            
>     | mean of X_N
> --------------------------------------------------------------
> ----|-------------
> 
> where all variables (VAR1, X_1 ... X_N) are binary. A similar 
> result could be achieved by 
> 
> 	tabstat X_1 X_2 ... X_N, by(VAR1)
> 
> with the result:
> 
> Summary statistics: mean
>   by categories of: VAR1 
> 
>     VAR1 |     X_1     X_2       X_3        X_4
> ---------+----------------------------------------
>        0 |  .1119746  .8359621  .2555634  .5063582
>        1 |  .0486352  .6175836  .1630881  .5350927
> ---------+----------------------------------------
>    Total |  .0530139  .6494703   .169481  .5331062
> --------------------------------------------------
> 
> 
> However, we would like to have this table with columns "VAR1 
> == 0" and "VAR1 == 1", analogue to the example above. 

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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