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

st: RE: mean of variable


From   "Stephen P Jenkins" <stephenj@essex.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: mean of variable
Date   Thu, 29 Jan 2004 08:57:39 -0000

> -----Original Message-----
> From: owner-statalist@hsphsun2.harvard.edu 
> [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of 
> aschaefer@diw.de
> Sent: 29 January 2004 08:46
> To: statalist@hsphsun2.harvard.edu
> Subject: st: mean of variable
> 
> 
> Hi All,
> 
> I try to generate a new variable out of the mean of another 
> variable (for each person)! Is there an easy way to solve 
> this problem?

Example:

Suppose you have data for individuals, and also know which household
they belong to, and the age of each person in the household. You want to
attribute to each person the mean age among the individuals of the
household to which he belongs.
	by hh_id: egen mean_age = mean(age)

More generally, look through -egen- in the manual; read about "by group"
operations in the User Guide, and also look through the Stata FAQs

Stephen
-------------------------------------------------------------
Professor Stephen P. Jenkins <stephenj@essex.ac.uk>
Institute for Social and Economic Research
University of Essex, Colchester CO4 3SQ, U.K.
Tel: +44 1206 873374.  Fax: +44 1206 873151.
http://www.iser.essex.ac.uk   

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