Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


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

Re: st: smart averaging


From   Francisco Morales <fcomorales@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: smart averaging
Date   Wed, 22 Feb 2012 22:21:57 -0300

Hi Murat,

If you don't care about the missing values, this may be what you need:

. bysort ID (year): egen average_inc =  mean(income)

With this line, the average is of those non-missing values.

Francisco

On Wed, Feb 22, 2012 at 21:54, Murat Mercan <mamercan@gmail.com> wrote:
> Hi,
>
> 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.
> Can anyone suggest how to do that?  Thank you in advance.
> Murat
> *
> *   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/

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


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index