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


From   Nick Cox <[email protected]>
To   [email protected]
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 <[email protected]> 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/


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