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
How to dissect multiple variables in one column to separate columnsHello good Sir/Madam, I am currently working with a list of corporations and their CashFlowTypes, a…
Testing and addressing potential attrition bias in panel dataDear all, I am using household panel data across three waves (2011, 2013, and 2015). Although the v…
Limit replace observations for n yearsDear All, I have the following data: Code: * Example generated by -dataex-. To install: ssc inst…
Random forests and neural nets in Stata (with Python integration)Hey all, I wrote a couple Stata packages to do regression or classification with random forests and…
Obtain village name form longitude and latitude & coordinatesHi Statalist! This is my first time dealing with GPS dataset. What I would like to do is to get the…
Subscribe to:
Post Comments (Atom)
0 Response to Replacing missing values with the mean by group via a loop
Post a Comment