[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
n j cox <n.j.cox@durham.ac.uk> |

To |
statalist@hsphsun2.harvard.edu |

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 n.j.cox@durham.ac.uk * * 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/

**Follow-Ups**:**Re: st: RE: Why can't I egen means with pweights?***From:*Laura Schechter <schechte@are.Berkeley.EDU>

**References**:**st: RE: Why can't I egen means with pweights?***From:*"Nick Winter" <nwinter@policystudies.com>

- Prev by Date:
**Re: st: having fun with graph in Stata8** - Next by Date:
**Re: st: RE: Why can't I egen means with pweights?** - Previous by thread:
**st: RE: Why can't I egen means with pweights?** - Next by thread:
**Re: st: RE: Why can't I egen means with pweights?** - Index(es):

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