Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: summing across bins


From   Richard Williams <[email protected]>
To   [email protected], [email protected]
Subject   Re: st: summing across bins
Date   Mon, 13 Feb 2006 09:15:45 -0500

At 08:30 AM 2/13/2006, Lenna Nepomnyaschy wrote:
Hi,

I just downloaded the ado file binsm, which allows you to graph mean values (or other values) of yvar on bins of xvar. But, I need to use weights. Does anyone have another way to do this that allow weights? the binsm command does not.

Alternatively, does anyone know how to create a variable with weighted means across various groups. the command

egen newvar=mean(oldvar), by(group)
does not allow weights.
There may be a more straightforward way - but if you have Stata 9 you can use the -mean- command.

. webuse nhanes2f

. mean age [pw=finalwgt], over(race)

Mean estimation Number of obs = 10337

White: race = White
Black: race = Black
Other: race = Other

--------------------------------------------------------------
Over | Mean Std. Err. [95% Conf. Interval]
-------------+------------------------------------------------
age |
White | 42.50856 .172878 42.16968 42.84743
Black | 40.21349 .5020604 39.22935 41.19762
Other | 40.46675 1.066255 38.37669 42.55682
--------------------------------------------------------------

. mat b = e(b)

. gen newvar = b[1,1] if race==1
(1286 missing values generated)

. replace newvar = b[1,2] if race==2
(1086 real changes made)

. replace newvar = b[1,3] if race==3
(200 real changes made)

. mean newvar, over(race)

Mean estimation Number of obs = 10337

White: race = White
Black: race = Black
Other: race = Other

--------------------------------------------------------------
Over | Mean Std. Err. [95% Conf. Interval]
-------------+------------------------------------------------
newvar |
White | 42.50856 0 . .
Black | 40.21349 0 . .
Other | 40.46675 0 . .
--------------------------------------------------------------



-------------------------------------------
Richard Williams, Notre Dame Dept of Sociology
OFFICE: (574)631-6668, (574)631-6463
FAX: (574)288-4373
HOME: (574)289-5227
EMAIL: [email protected]
WWW (personal): http://www.nd.edu/~rwilliam
WWW (department): http://www.nd.edu/~soc
*
* 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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index