Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: Averages for missing values


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: Averages for missing values
Date   Thu, 8 Sep 2005 22:26:20 +0100

This is a situation where -clonevar- 
is your natural starting point. -clonevar- 
echoes format, any variable label, any value labels 
and any characteristics. That is, start 

clonevar varnameAVE = varname

not with -generate-. 

Nick 
n.j.cox@durham.ac.uk 

Roger Newson

> >Before I give myself carpal tunnel syndrome I might ask:
> >Is there a command to replace missing values with averages?
> >
> >What I am currently doing is:
> >
> >generate varnameAVE=varname
> >summarize varnameAVE
> >replace varnameAVE=[here I use the mouse to copy from the results
> >window to the command window] if varnameAVE==.
> 
> You should use either the r() results (see -whelp return-) or 
> -egen- (see 
> -whelp egen-).
> 
> The first way is like:
> 
> generate varnameAVE=varname
> summarize varnameAVE
> replace varnameAVE=r(mean) if missing(varnameAVE)
> 
> The second way is like:
> 
> generate varnameAVE=varname
> egen AVE=mean(varnameAVE)
> replace varnameAVE=AVE if missing(varnameAVE)
> 
> Both the returned r() results and -egen- are very useful in 
> many more ways 
> than this, and it is a good idea to find out more about them.

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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   |   What's new   |   Site index