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

st: RE: matrix of variable averages


From   Theuer Stefan <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   st: RE: matrix of variable averages
Date   Tue, 9 Dec 2003 13:24:03 +0100

Dear Stata Users,

To this solution i have 2 questions:
1) What is the meaning of the transpose mark, in my opinion the syntax should also run without this mark.

2) if i like getting not alone the results of the total mean but also the differences between the mean of all items and grouped items i used the following ado file. My question is, is there a way to use the labels of the by-variable for the matrix list command at the bottom?

Thanks very much

Stefan


program define compmean
        version 8.0
        syntax varlist [if] [in], by(varname)      

marksample touse
quietly levels `by' if `touse', local(K)



* total

di as text _newline(2) "{hline 104}"_newline "total means"_newline
tabstat `varlist' if `touse', stats(mean) format(%9.3f) save casewise 
matrix total = r(StatTot)
di _newline "{hline 104}" _newline(2)

* groupwise

di _newline "{hline 104}" _newline "means of the groups" _newline
tabstat `varlist' if `touse', stats(mean) by(`by') format(%9.3f) save casewise nototal miss
di _newline "{hline 104}" _newline(2)

* matixes of the means of the groups and differencies of the means

foreach num of numlist 1/`K'{
	matrix cl`num' = r(Stat`num')	               
	matrix cl`num't = (cl`num' - total)*100	   
	
}

* display
di _newline(2) "{hline 104}" _newline "differences of the means" _newline

foreach num of numlist 1/`K' {
	di _continue "Cluster `num'	"
	matrix list cl`num't, noheader format(%9.1f)  noblank nonames
}

di "{hline 104}" 

end
exit

> -----Urspr�ngliche Nachricht-----
> Von: Nick Cox [mailto:[email protected]] 
> Gesendet: Dienstag, 25. November 2003 13:16
> An: [email protected]
> Betreff: st: RE: matrix of variable averages
> 
> 
> . tabstat experience education children, s(mean) save
> . matrix mean = r(StatTot)' 
> . matrix li mean 
> 
> Note the transpose mark. 
> 
> Nick 
> [email protected] 
> 
> Mohamad Khalid Dimaporo
>  
> > Im a beginner with stata and cant find a simple method to
> > create a (n x 1) 
> > matrix of my variable averages. For example, what command 
> > do I type to get a 
> > 3 x 1 matrix of the averages of experience education children.
> 
> *
> *   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/
> 

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