Statalist


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

st: re: simple tab needed but multiple records


From   Kit Baum <[email protected]>
To   [email protected]
Subject   st: re: simple tab needed but multiple records
Date   Fri, 5 Oct 2007 17:45:51 -0400

Joseph said

 I have a dataset of x-ray records with multiple records per
patient.  The records consist of id, age, and sex and I need to know how
many persons had an x-ray when they were between the age of 17 and 25
AND when when they were over 30.  My attempts have been crude and I know
there has to be a simple yet elegent way to do this.

I think this should work, without the necessity of reshaping:

bysort id: gen early = inrange(age, 17, 25)
by id: gen late = age > 30
by id: gen both = cond(_n==_N, (sum(early) & sum(late)) , .)
count if both == 1

To test,

set obs 1000
g id=mod(_n,100)+1
g age=40*uniform()

Kit Baum, Boston College Economics and DIW Berlin
http://ideas.repec.org/e/pba1.html
An Introduction to Modern Econometrics Using Stata:
http://www.stata-press.com/books/imeus.html


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