Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: RE: Why can't I egen means with pweights?


From   n j cox <[email protected]>
To   [email protected]
Subject   Re: st: RE: Why can't I egen means with pweights?
Date   Wed, 23 Apr 2003 23:42:52 +0100

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
problem directly.

David Kantor has a weighted mean -egen- function on SSC.

However, will any of this code treating pweights properly?

Nick
[email protected]



*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index