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
error obtaining scores for robust varianceDear all, I am teaching to students who are using STATA 17 and I have STATA 16 on my machine. Weir…
Nobel Prize in Economics 2021The Nobel Prize is awarded to David Card, Joshua Angrist, and Guido Imbens. These men popularized th…
Help with scatterplotIn Stata 17, how can I make a scatter plot of X and Y variables, showing two distinct groups as in t…
factor-variable and time-series operators not allowed r101Hello experts I'm trying to perform a Stratification-Multilevel analysis using the hte package. How…
Difficulty interpreting results (xtlogit in combination with marginal effects)Hi, I ran the following command on my panel data: Code: xtlogit A B C D E F G logH And got the fo…
Subscribe to:
Post Comments (Atom)
0 Response to Replacing missing values with the mean by group via a loop
Post a Comment