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
When only one independent variable is non stationary does it make sense to run a cointegration test?Dear Stata users, after checking the stationarity of my panel data regression model: Y = f (X1, X2,…
Comparing coefficients between two ivregress modelsTo Statalist I used -gmm- to test the equality between two variables (b1, c1) in different models r…
runmlwin cross-lev interactions and random slope specificationHello, I am fitting a multilevel logit model using runmlwin following the procedure explicated in LE…
Testing if two coefficients are statistical differentDear Stataforum, I am currently investigating the Norwegian electricity market. I am running two r…
Panel Unit Root Tests and Cointegration - Lag ProblemHello! I am a fresh Stata user and not very excellent on econometrics. My data is consisted of N=8 a…
Subscribe to:
Post Comments (Atom)
0 Response to Replacing missing values with the mean by group via a loop
Post a Comment