Hello.
Thanks to Kit Baum, an update to _gwtmean has been uploaded to SSC.
This is a user-created egen function that calculates a weighted mean.
I recently became aware that there had been a discussion to the effect that _gwtmean could not handle input expressions involving string comparisons. This discussion occurred two years ago, but I just learned about this recently. So I have fixed it, changing from the use of -parse- to -syntax-. (The original version was done in 2001, under Stata 3.)
Note that, possibly as a response to the shortcomings of this program, as it stood previously, an alternative program, _gwmean (no t) was created by Gueorgui I. Kolev.
Mr. Kolev's program has greater capability, in that it allows for different types of means: arithmetic, geometric, harmonic; and has a label option; however it...
ignores the -type- feature (always generates double);
requires the weight option to be a variable.
By contrast, _gwtmean does pay attention to the weight feature, and allows expressions in the weight option.
I did not include a label option, as I foresee some problems with it. But if users demand it, I can add it.
To obtain it,...
ssc inst _gwtmean
----
Having revised this program has reawakened my curiosity as to why egen does not allow a weight feature [w=exp] -- and forces us to implement weight as an option instead. This may be obvious but one reason is that you are not allowed to have a weight feature and an -exp in the same command; a weight feature on egen would run into that limitation. Note that both of these features result in the setting of the `exp' local, so there would be a conflict. They could have given them separate names -- e.g., `exp' and `weightexp', but they chose not to. I suppose that the motivation is that there should not be a need for both weight and exp features together in one command. exp is for generating variables; weight is for analysis; those are separate activities.
Pardon my rambling, but I thought that this may be interesting to some people.
Thanks,
--David
Thanks to Kit Baum, an update to _gwtmean has been uploaded to SSC.
This is a user-created egen function that calculates a weighted mean.
I recently became aware that there had been a discussion to the effect that _gwtmean could not handle input expressions involving string comparisons. This discussion occurred two years ago, but I just learned about this recently. So I have fixed it, changing from the use of -parse- to -syntax-. (The original version was done in 2001, under Stata 3.)
Note that, possibly as a response to the shortcomings of this program, as it stood previously, an alternative program, _gwmean (no t) was created by Gueorgui I. Kolev.
Mr. Kolev's program has greater capability, in that it allows for different types of means: arithmetic, geometric, harmonic; and has a label option; however it...
ignores the -type- feature (always generates double);
requires the weight option to be a variable.
By contrast, _gwtmean does pay attention to the weight feature, and allows expressions in the weight option.
I did not include a label option, as I foresee some problems with it. But if users demand it, I can add it.
To obtain it,...
ssc inst _gwtmean
----
Having revised this program has reawakened my curiosity as to why egen does not allow a weight feature [w=exp] -- and forces us to implement weight as an option instead. This may be obvious but one reason is that you are not allowed to have a weight feature and an -exp in the same command; a weight feature on egen would run into that limitation. Note that both of these features result in the setting of the `exp' local, so there would be a conflict. They could have given them separate names -- e.g., `exp' and `weightexp', but they chose not to. I suppose that the motivation is that there should not be a need for both weight and exp features together in one command. exp is for generating variables; weight is for analysis; those are separate activities.
Pardon my rambling, but I thought that this may be interesting to some people.
Thanks,
--David