Hi, all. I am trying to generate a new variable by calculating averages by subgroup. To do this, I use the following command:
sort Group Period
bysort Group Period: egen mcost = mean(Cost)
My problem is that the variable Cost contains zeros, and I would like to exclude those zeros from the calculations. For example, I would like the mean of 0, 0, 2, 2 to be 2 and not 1. I tried to add if Cost != 0 at the end but I received values only where Cost is positive. Any suggestions? Thanks in advance.
sort Group Period
bysort Group Period: egen mcost = mean(Cost)
My problem is that the variable Cost contains zeros, and I would like to exclude those zeros from the calculations. For example, I would like the mean of 0, 0, 2, 2 to be 2 and not 1. I tried to add if Cost != 0 at the end but I received values only where Cost is positive. Any suggestions? Thanks in advance.
Comment