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
Events in IntervalsHi, I am attempting to count admissions that have occurred for an ID variable (IDV) that occur (ADat…
GARCH modelDear all, i am facing issue in running GARCH (1,1)Model. iterations are repeated but show as (NOT CO…
Histogram with bin freq and % on yaxisDear Statalist, I want to generate Histogram Stata with percent option and want counts/freq of bins…
variable with 2 conditionGood morning everyone, I have a problem on STATA. I have 2 variables (Ebitda08 and Ebitda09) and a t…
How can I change by default stsetHello, I am working on neonatal mortality. So my time points are 0 day- 28 days 0 day is for those…
Subscribe to:
Post Comments (Atom)
0 Response to Replacing missing values with the mean by group via a loop
Post a Comment