Hello,
I have a large dataset of 59,000,000 observations.
There are a 50 variables each beginning with the word qof. Some of the observations have missing values. I need to replace the missing values with the mean by group (healthgroup), For an individual missing variable I can do this easily enough I think:
egen missqof1 = mean(qof1), by(health_org)
replace qof1 = missqo1 if missing(qof1)
my problem is that I don't want to type this 50 times for each of the 50 variables, so I want to do this in a loop I think:
foreach var of varlist qof* {
replace qof* = mean(qof*) if missing(qof*)
}
I am not familiar with loops - and not sure how to make the code work.
Related Posts with Replacing missing values with the mean by group via a loop
Difficulties in invoking python in stata 16I am trying to call python into the stata 16 environment but having the below error. Any help would …
How to generate a variable with the total number per year only?Good day all, I have a dataset with 3 variables: (survival status "survived/died", year, number of …
Meta-analysis of prevalence data using metaprop commandHi There, I am seeking some help regarding the meta-analysis of the prevalence data using the metap…
Creating an indexHey I want to create an index out of 10 variables, each of them has values on a scale from 1 to 5. I…
is this a correct way to rescale a variable?Hi all, I have an independent variable in my regression that lies between .0000869 and .0610705. It…
Subscribe to:
Post Comments (Atom)
0 Response to Replacing missing values with the mean by group via a loop
Post a Comment