Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: tabstatmat unnecessarily...


From   Kit Baum <[email protected]>
To   [email protected]
Subject   st: tabstatmat unnecessarily...
Date   Fri, 24 Sep 2004 14:58:58 -0400

Friedrich said

sysuse auto, clear
local i = 1
foreach var of varlist price mpg weight {
  quietly tabstat `var', stat(mean sd) by(foreign) save
  tabstatmat mat
  if `i'==1 {
    matrix bigmat = mat
    }
    else {
      matrix bigmat = bigmat \ mat
    }
  local i = `i' + 1
  }


But that wheel has already been invented...

sysuse auto, clear
local vars price mpg weight
mat res1 = J(2,2,0)
local i 0
foreach v of local vars {
	qui statsmat `v', stat(mean sd) by(foreign) mat(res`++i')
	if `i'>1 {
		mat res1 = res1 \ res`i'
	}
}
mat list res1


Kit

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