Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down at the end of May, and its replacement, **statalist.org** is already up and running.

[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: Re: st: Simple mean imputation |

Date |
Wed, 22 Aug 2012 15:17:47 +0100 |

Ona's problem was as below my signature. Suppose there was no -egen-, which allows Austin's neat solution: what would a solution look like? We would loop over variables, keeping track of totals and non-missings: gen count = 0 gen total = 0 qui foreach v of var PAM1-PAM20 { replace total = total + `v' if `v' < . replace count = count + 1 if `v' < . } replace total = cond(count < 18, ., total * 20/count) if count < 20 The key points as compared with Ona's code are that we need to loop over all the variables before we can act on how many non-missing values there are; and that the formulation above allows the number of non-missing values to vary. Nick A measure we are using consists of 20 items, the scoring of which is simply a sum of all the items. It is not to be scored if more than 2 items are missing but if 1 or 2 items are missing, it calls for simple mean imputation (I know this is an old method but the measure was created in 1988). It's not the overall dataset mean that's imputed, but the mean of the 18 or 19 items for each observation. My attempt is this: foreach var of varlist PAM1-PAM20 { if var >=. missingcount = missingcount + 1 } if missingcount <3, generate impflag=1, else impflag = 0 but I'm now stuck. I know this is very basic but I can't figure it out. I'd appreciate any help, On Wed, Aug 22, 2012 at 1:21 PM, Ona McCarthy <omccarthy@tccr.org.uk> wrote: > Many thanks Nick and Austin. I need to remember how logical Stata is and not to overcomplicate things. > > Ona > > > > > > > > ______________________________________________________________________ > This email has been scanned by the Symantec Email Security.cloud service. > For more information please visit http://www.symanteccloud.com > ______________________________________________________________________ > > * > * 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/ * * 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: Re: st: Simple mean imputation***From:*"Ona McCarthy" <omccarthy@tccr.org.uk>

- Prev by Date:
**Re: st: Stata do-file editor** - Next by Date:
**Re: st: FW: Running Polychoric Principal Component Analysis in STATA** - Previous by thread:
**RE: Re: st: Simple mean imputation** - Next by thread:
**st: Using margins and marginsplot with the ologit command** - Index(es):