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

st: RE: re. Generating a multiple birth indicator in a large data set


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: re. Generating a multiple birth indicator in a large data set
Date   Fri, 16 Jul 2004 10:40:17 +0100

Stata is really excellent at these problems. 

-egen- haters would want to do this directly. 

. bysort mothid bo : gen multi = _N 

Alternatively, 

. egen multi = sum(1), by(mothid bo) 

or 

. egen multi = count(1), by(mothid bo) 

or 

. egen multi = count(offid), by(mothid bo)

The last is a little more subtle. -count(arg)- 
counts how many times arg is not missing. 
If in this case -offid- were ever missing 
you would want protection against that. 

Nick 
[email protected] 

roger webb
 
> I have a large vital statistics register of all births in Denmark and 
> have the following variables:
> 
> Offspring ID ('offid')
> Birth order ('bo')
> Maternal ID ('mothid')
> 
> If the birth order number is duplicated within a sibling set, 
> multiple 
> births are indicated. Eg. for 3 mothers (101,102,103):
> 
> mothid		bo		offid
> 101			1		1
> 101			2		2
> 102			1		3
> 102			1		4
> 103			1		5
> 103			1		6
> 103			1		7
> 
> Mother 101 has two singleton offspring (1,2), mother 102 has twins 
> (offspring 3,4) and mother 103 has triplets (offspring 5-7).
> 
> I'd like to add a multiplicity indicator ('multi') to the 
> data set, i.e.:
> 
> mothid		bo		offid		multi
> 101			1		1			1
> 101			2		2			1
> 102			1		3			2
> 102			1		4			2
> 103			1		5			3
> 103			1		6			3
> 103			1		7			3
> 
> I've looked at the 'egen' command but can't see anything suitable. 
> Does anyone have any ideas as to how I can write a Stata 
> command to generate this variable?

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