Bookmark and Share

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]

re: st: data management question


From   "Airey, David C" <[email protected]>
To   "[email protected]" <[email protected]>
Subject   re: st: data management question
Date   Fri, 22 Apr 2011 19:10:49 -0500

.

Something like this, although your complicated data my kill my suggestion.

clear
set obs 120
egen school = seq(), from(1) to(12) block(10)
egen year = seq(), from(1999) to(2008) block(1)
egen condition = seq(), from(1) to(2) block(60)
egen category = seq(), from(1) to(3) block(10)
gen myvar = rnormal()

replace myvar = . if year == 2004
bysort school condition category (year): egen mean_myvar = mean(myvar) ///
	if inlist(year,2001,2002,2003,2004)
	
replace myvar = mean_myvar if year == 2004

// or

bysort school condition category (year): replace myvar = mean_myvar ///
	if year == 2004



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


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index