Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Barbara Romano <bar.romano@gmail.com> |
To | "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |
Subject | Fwd: st: Subgroup mean imputation |
Date | Sun, 17 Nov 2013 01:05:47 +0100 |
> > thanks Nick and Fernando, > it works! > barbara > > > > Il giorno 16/nov/2013, alle ore 10:52, Nick Cox <njcoxstata@gmail.com> ha scritto: > >> Given >> >> egen classmean = mean(score), by(CODICE_CLASSE) >> >> then (1) >> >> clonevar score2 = score >> replace score2 = classmean if missing(score) >> >> or (2) >> >> gen score2 = cond(missing(score), classmean, score) >> >> It's good practice to keep your original variable unchanged. In (2) >> use -double- or -long- if -score- is -double- or -long-. >> >> Nick >> njcoxstata@gmail.com >> >> Barbara Romano >> >>> Thanks Fernando, >>> unfortunately it’s not working. I’m stuck with my missing . >>> I never used looping, but do you think a loop could be a solution? >>> Something that says stata for each missing in the variable classmean impute the value of classmean of another observation with the same classroom_id… >> >> Fernando Rios Avila >> >>>> What I usually do is to add the following command to what you already have: >>>> egen classmean_imputed = max(classmean), by(CODICE_CLASSE) >> >> Barbara Romano >> >>>>> I’d like to contrast the results I get the mi imputation and the old fashioned mean imputation. >>>>> I’ve a huge dataset of student test scores with a variable for classroom id. >>>>> >>>>> I used the egen command to create the subgroup mean for each classroom >>>>> egen classmean = mean(score), by(CODICE_CLASSE) >>>>> >>>>> this create for each student with the same classroom code, BUT for the the students with a missing value for the score. >>>>> I’d like to impute that classroom subgroup mean for the “missing students”. >> >> * >> * For searches and help try: >> * http://www.stata.com/help.cgi?search >> * http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/