| |
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: RE: tabstat, by(): switching variables from row to columns
I think there are several ways to do what
you want so long as it is, or is equivalent
to, transposing a matrix.
Consider
. sysuse auto, clear
(1978 Automobile Data)
. tabstat trunk turn mpg, by(rep78)
Summary statistics: mean
by categories of: rep78 (Repair Record 1978)
rep78 | trunk turn mpg
---------+------------------------------
1 | 8.5 41 21
2 | 14.625 43.375 19.125
3 | 15.26667 41.06667 19.43333
4 | 13.5 38.5 21.66667
5 | 11.45455 35.63636 27.36364
---------+------------------------------
Total | 13.92754 39.7971 21.28986
----------------------------------------
I think you want this transposed. One way
to do it is
. tabstat trunk turn mpg, by(rep78) save
Summary statistics: mean
by categories of: rep78 (Repair Record 1978)
rep78 | trunk turn mpg
---------+------------------------------
1 | 8.5 41 21
2 | 14.625 43.375 19.125
3 | 15.26667 41.06667 19.43333
4 | 13.5 38.5 21.66667
5 | 11.45455 35.63636 27.36364
---------+------------------------------
Total | 13.92754 39.7971 21.28986
----------------------------------------
. tabstatmat temp
temp[6,3]
trunk turn mpg
1 8.5 41 21
2 14.625 43.375 19.125
3 15.266667 41.066667 19.433333
4 13.5 38.5 21.666667
5 11.454545 35.636364 27.363636
Total 13.927536 39.797101 21.289855
. matrix temp = temp'
. mat li temp, noheader
1 2 3 4 5 Total
trunk 8.5 14.625 15.266667 13.5 11.454545 13.927536
turn 41 43.375 41.066667 38.5 35.636364 39.797101
mpg 21 19.125 19.433333 21.666667 27.363636 21.289855
Here the key element is -tabstatmat-, which you can install from
SSC. In practice, you might want to tune the -matrix list-, e.g.
by specifying a -format()-.
Nick
[email protected]
Manuel Diezi
> using tabstat var1 var2 var3, by(var4): is there a
> possibility to switch
> rows and columns, ie to have var4 displayed in columns rather
> than in rows?
*
* 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/