Hello Stata experts,

I am using the following data:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float(IVOL DUM FirmID)

   -.012846745 0 1
    .003010829 0 1
    -.01994809 1 1
     -.0102941 1 1
   -.016133793 1 1
    .003362658 1 1
    .010100462 0 1
   -.005357542 1 1
     .01985686 1 1
    -.02125267 0 1
   -.013251625 0 2
   -.011405208 0 2
    .005397665 0 2
   -.016385317 0 2
    -.02082585 0 2
    .004482734 0 2
   -.008927207 0 2
-1.3124484e-06 1 2
   -.002564483 0 2
    -.02041283 0 2
   -.021711256 0 3
    .019218445 0 3
    -.01553059 0 3
   -.001207368 0 3
   -.020130247 1 3
   -.015929932 1 3
   -.012757675 1 3
    .002185969 1 3
    -.01975868 1 3
   -.010493663 1 3
   -.021384994 1 4
   -.016919166 1 4
   -.016161574 0 4
    .006752182 0 4
   -.009183821 0 4
   -.022988187 0 4
    .005700997 0 4
   -.016790474 0 4
   -.010007303 1 4
   -.013928052 0 4
  
end

to run this regression:
Code:
xtreg IVOL DUM, fe
where DUM is basically a dummy variable and FirmID is the panel firm ID.

So, the observations of variable DUM ==1 vary from one firm to another. We have firms with no observations for DUM==1 and other firms with greater observations of DUM==1. So what I would like to do is to run the above regression if the observations of variable DUM==1 is greater than the average or mean of observations for DUM==1 for all firms. Is there a way to get to the mean of observations for DUM==1 for all firms without doing something like:

Code:
by FirmID: sum DUM if DUM==1
because this will calculate the observations for DUM==1 for each firm and then I will have to calculate the mean observations for all firms manually.
Once we do this I need to run the above regression for firms with observations of DUM==1 greater than the mean observations for all firms.

Thank you