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

Re: st: egen "mean weight"


From   austin nichols <austinnichols@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: egen "mean weight"
Date   Fri, 2 Sep 2005 10:16:37 -0400

It seems to me an oversight that -ssc install egenmore- does not
already give you this capability, especially since the xtile function
in that package allows weights when dividing your sample into
quantiles.  But it is easy enough, and good practice, to construct
weighted means from first principles--you really never have to use
egen, it's just a shortcut.
. bys iid: gen double spop=sum(pop)
. bys iid: replace spop=spop[_N]
. gen double wtdwage=wage*pop/spop
. bys iid: gen double meanwage=sum(wtdwage)
. bys iid: replace meanwage=meanwage[_N]
. drop spop wtdwage
. compress meanwage

On 9/1/05, Jorge Tuesta <jtuesta@grade.org.pe> wrote:
> Dear statalisters,
> Is it posible to create a average weight variable using "egen"?
>  I normally write:
>     egen mwage=mean(wage), by(iid)
> but i would like "mean weight" (using [fweight=pop], for example) not
> simple mean. Is it posible?
> Thanks in advance!
> Jorge

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