Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Mean


From   Austin Nichols <[email protected]>
To   [email protected]
Subject   Re: st: Mean
Date   Fri, 23 Jan 2009 14:18:35 -0500

In addition to the -egen- fcn -wtmean- at
  ssc d _gwtmean
and the solution from first principles outlined at
  http://www.stata.com/support/faqs/data/weighted.html
as pointed out by Nick Cox, you can use -areg- to get means like so:

egen g=group(x area)
areg y [aw=weight], a(g)
predict ybar, xbd

which by default will not calculate means for categories where
variables x and/or area are missing, but the -missing- option can be
added if desired:

egen g=group(x area), missing
areg y [aw=weight], a(g)
predict ybar, xbd

On Fri, Jan 23, 2009 at 11:27 AM,  <[email protected]> wrote:
> I have to create a variable that compute the mean of varname (y) for a
> particular area (area=1)and conditioned to an other variable (x, that
> assumes value equals to 1,2,3,4,6),so I would calculate the mean of y|x=1 in
> area=1, the mean of y|x=2 in area=1, and so on. I typed
>
> egen mean=mean(y) if area==1, by (x)
>
> but I have to introduce aweight to this computation, how can I do?
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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