[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
RE: st: egen "mean weight"
I don't know why -egenmore- is being singled
out here. The bigger issue is that -egen-
does not take weights as such, so that
use of -egen- with weights requires some
work-around, for example the use of an
option, as in -egen, xtile()- on -egenmore-.
That creates an obligation to say which kinds of
weights are supported.
As far as -egenmore- is concerned, the whole
package is pretty much an ad hoc accumulation of
programs found to be needed by their authors.
People should feel free to look at it and
recognise oversights everywhere. Theme,
direction and planning are non-existent.
The original question was discussed in an
FAQ a few years ago:
FAQ . . Calculating variables containing weighted group summary statistics
. . . . . . . . . . . . . . . . . . . . . N. J. Cox and S. P. Jenkins
1/03 I want to calculate a variable containing weighted
group summary statistics, but I do not want to
collapse the data and egen does not support weights.
How can I do this?
In that FAQ, we strongly commend the kind of
approach from first principles well explained
here by Austin.
> 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
> > 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?
* For searches and help try: