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   Laura Schechter <schechte@are.Berkeley.EDU>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: RE: Why can't I egen means with pweights?
Date   Wed, 23 Apr 2003 15:45:46 -0700 (PDT)

I tried it out and Nick Winter's code works very well, and it seems as if
it is faster in my bootstrap than the whole svymean thing was. I don't
know anything about SSC though or how that compares.
   Thanks for all your input. 
       Laura

On Wed, 23 Apr 2003, n j cox wrote:

> 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/
> 

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index