Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, and its replacement, **statalist.org** is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
Nick Cox <n.j.cox@durham.ac.uk> |

To |
"'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu> |

Subject |
RE: st: smart averaging |

Date |
Thu, 23 Feb 2012 19:01:19 +0000 |

That can be done in various ways. Here is one: bys id : egen OK = total(inrange(year,2006,2009) & income < .) by id: egen average_inc = mean(income / (OK == 4)) Nick n.j.cox@durham.ac.uk Fernando Rios Avila If you are trying to average it only for those without missing variables, the easier process could be: 1. identify number of missing observations by id 2. average for all 3. replace by missing value if the number of missing values is higher than 0 On Wed, Feb 22, 2012 at 7:54 PM, Murat Mercan <mamercan@gmail.com> wrote: > I have the following problem I have been unable to decipher. I have the > following data set: > id year income > 1 2006 100 > 1 2007 50 > 1 2008 . > 1 2009 . > 2 2006 50 > 2 2007 50 > 2 2008 50 > 2 2009 50 > I want to average the income variable for those four years. I tried to use > the following command: > > bys id: egen average_inc = mean(income) if inrange( year,2006,2009) > > However, that averages person 1's income, too. I need to average just > person 2's income. * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**References**:**st: smart averaging***From:*Murat Mercan <mamercan@gmail.com>

**Re: st: smart averaging***From:*Fernando Rios Avila <f.rios.a@gmail.com>

- Prev by Date:
**st: RE: test command for categorical variables in survey data** - Next by Date:
**re: st: tsset error codes** - Previous by thread:
**Re: st: smart averaging** - Next by thread:
**Re: st: smart averaging** - Index(es):