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

st: Counting combinations of two vars within groups defined by third var


From   "Julie K. Rajaratnam" <[email protected]>
To   <[email protected]>
Subject   st: Counting combinations of two vars within groups defined by third var
Date   Thu, 10 Nov 2005 12:31:54 -0500

Hello, I am sure there is a simple way to do the following but I haven't
been able to find it searching through the help files or the listserv
archive: 

I have three variables - school (grouping variable), gender (binary), and
grad (binary). What I want to calculate is for each school, how many males
graduated? 

I have done the following:

sort sch gender grad
by sch: egen mg = count(lastsch) if gender==1 & grad==1
by sch: egen malegrads = max(mg)
drop mg

However, this only works if there are one or more male grads in the school.
I can't figure out how to get zero values to populate in schools where the
if condition is not satisfied.

Thanks for your help!
Julie

Julie K. Rajaratnam
Ph.D. Candidate
Department of Population and Family Health Sciences
Johns Hopkins Bloomberg School of Public Health
[email protected] 

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