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
Matching datesHi all, I need the iv_spread value of option expiration date (exdate) closest (during or after) to …
Sample size for cox proportional hazards model with multiple covariatesThis is my first time using power cox, and I would like confirmation of my code. HTML Code: power…
Calcule Overlap between two variablesI need to calculate the overlap of two variables (time series). I saw that in R, the command is "cal…
Identifying matched observations in a large databaseDear all, This is relevant to the question I asked some days ago and can be found here: I have enc…
Deciding between RE and FEI have a theoretical question concerning usage of the FE model for panel data regression. I'm curre…
Subscribe to:
Post Comments (Atom)
0 Response to Replacing missing values with the mean by group via a loop
Post a Comment