I want to generate a variable that equals the mean of the values of the first two nonmissing variables in a three-variable list (var1, var2, var3). At the same time, I also want to record which two of the three variables in my list have been used to generate the new variable (I do not need the variable name; the order of the variable is enough). How can I do that efficiently? Thank you very much!
Code:
webuse auto,clear replace headroom=. if mpg==17 replace weight=. if mpg==22|mpg==17 //I did the above manipulation so that some observations have only one nonmissing value in the varlist to be considered below //so that you cannot simply apply egen rowmean to fulfil my task keep rep78 headroom weight rename rep78 var1 rename headroom var2 rename weight var3 //how to generate a variable that equals the mean of the first two nonmissing variables in the varlist (var1, var2, var3) //and record which two of the three variables in my list have been used to generate the new variable?
0 Response to egen problem
Post a Comment