Good day all,
I am working with a dataset that looks something like this.
ID var1 var2 ... var17
1 a b c
2 d a .
3 . f a
4 e . f
5 c e d
What I need to do is calculate the geometric mean of the 17 variables, by ID. I've tried using the following code:
egen gmean = gmean(var1-var17), by(ID)
However, this returns a missing value as soon as one of the 17 variables contains a missing value.
How can I avoid this and obtain the geometric mean of all non-missing values across vars 1 to 17?
I am working with a dataset that looks something like this.
ID var1 var2 ... var17
1 a b c
2 d a .
3 . f a
4 e . f
5 c e d
What I need to do is calculate the geometric mean of the 17 variables, by ID. I've tried using the following code:
egen gmean = gmean(var1-var17), by(ID)
However, this returns a missing value as soon as one of the 17 variables contains a missing value.
How can I avoid this and obtain the geometric mean of all non-missing values across vars 1 to 17?
Comment