[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: egen "mean weight"
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 <firstname.lastname@example.org> 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!
* For searches and help try: