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
[email protected]
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/