Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

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

From |
Nick Cox <njcoxstata@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: data management question |

Date |
Sat, 23 Apr 2011 01:02:17 +0100 |

No; apart from the fact that you need -egen- to do this, this includes the values for 2004 in the average, which is not what is wanted. The -replace- will thus make no difference. Nick On Sat, Apr 23, 2011 at 12:43 AM, Airey, David C <david.airey@vanderbilt.edu> wrote: > . > > What about first replacing year 2004 for myvar with missing, then > > bysort var1-var10 (year): gen mean_myvar = mean(myvar) if inlist(year,2001,2002,2003,2004) > > that now includes the year 2004. > > Now you can > > replace myvar = mean_myvar if year == 2004 > > Of course I'm guessing at this without any data set to try it on... > > Now you could replace > >> I'm guessing a statement like, >> >> bysort var1-var10 (year): gen mean = mean(var11) if inlist(year,2001,2002,2003) >> >> should get the means for those years for each subset. >> >> Now how to get the 2004 year replaced with the means for each subset? > > >>> We have data from 12 schools, grouped into two conditions, for 100 categories, for 9 grades, for each of 10 years. This data is for 20 different variables. >>> >>> We want to replace the scores for year 2004, with the mean of the score for 2001-2003 for each variable, for each grade, for each category, for each condition, for each school. The current values for 2004 are not reliable and so we are making this replacement. >>> >>> How can we do this. >>> >>> Here is an example of the data >>> >>> sch_id group category grade year rex mex sex . . . >>> 1 2 all 3 2001 1 2 0 . . . >>> 1 2 all 3 2002 2 1 1 . . . >>> 1 2 all 3 2003 4 1 1 . . . >>> 2 2 all 3 2004 8 55 6 . . . >>> ... >>> >>> 17 1 blkfem 8 2010 1 2 1 . . . >>> >>> --Alan Acock * * 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**:**re: st: data management question***From:*"Airey, David C" <david.airey@vanderbilt.edu>

- Prev by Date:
**Re: st: data management question** - Next by Date:
**re: st: data management question** - Previous by thread:
**re: st: data management question** - Next by thread:
**re: st: data management question** - Index(es):