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

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


From   Sergio Correia <[email protected]>
To   [email protected]
Subject   Re: st: Counting combinations of two vars within groups defined by third var
Date   Thu, 10 Nov 2005 12:53:16 -0500

Maybe this helps

* Creating example dataset
clear
set obs 20
set seed 123
gen school=ceil(_n/5)
gen gender=uniform()>0.5
gen grad=uniform()>0.6
label define gender 0 Fem 1 Male
label values gender gender

* Answer
tab school grad if gender==1

-----------------

So, just use the -tab- command, and you will get how many males
graduated (and how many don't).

(Note that it doesn't works if there were no males in one school)

Sergio


On 11/10/05, Julie K. Rajaratnam <[email protected]> wrote:
> 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/
>

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