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

st: return list and by


From   <[email protected]>
To   [email protected]
Subject   st: return list and by
Date   Mon, 12 Apr 2004 15:21:37 -0600

Hello All --
Is there a way to save the mean in r() for each value of a 
variable?  More specifically, I want the mean for each 
different person contained within the variable 'name'.  My 
programming experience in Stata is quite limited so I'd 
appreciate any advice; the shrapnel from my attempt at coding 
is pasted below:

program mean_get 
	syntax [varlist] 
		foreach i of local varlist { 
			generate overall2 = 0
			by name, sort:  summarize `i', meanonly
			local 1 = r(mean)
			by name, sort:  replace overall2 = `1'
			}  
end 

When I run this, it returns the mean from the last value in 
'name' and uses it to replace all values of 'overall2'.  Any 
suggestions?

Many thanks...
Clint Thompson


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