[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: RE: Why can't I egen means with pweights?
Nick Winter wrote:
I don't think there is a preprogrammed thing for this (although Nick Cox
may prove me wrong), but you can do this yourself fairly easily:
. sort month
. by month: gen ET = sum(varname*wgt) / sum(wgt)
. by month: replace ET=ET[_N]
Remembering that the weighted mean is simply the sum of the (variable
times the weight) divided by the sum of the weights. The second line
creates the "running" mean within month, the third line replaces the
weighted mean for all observations with the final one for each month,
which is the overall weightd mean for the month.
This code is better than mine. I was starting from an FAQ with which
I am familiar, not a good strategy compared with looking at the
David Kantor has a weighted mean -egen- function on SSC.
However, will any of this code treating pweights properly?
* For searches and help try: