An Extension to egen for the Computation of Peers' Average Characteristics
egen [type] newvar = peers(argument) [if] [in], by(varname)
peers is an extension to egen that computes the average characteristic of peers in a unit defined by argument.
Behaviour with missing values and small units
peers ignores missing values, ie they do not count in the mean. Moreover if a unit has only one observation, then newvar is set to missing.
egen average_age_of_peers = peers(age), by(classroom)
Amine Ouazad, PhD Candidate of the Paris School of Economics, Webpage http://www.pse.ens.fr/junior/ouazad/ Email email@example.com