Statalist


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

st: RE: adding count variables


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: adding count variables
Date   Wed, 4 Jul 2007 20:36:09 +0100

Whether or not this is quite your problem, this may help. 

-collapse- and -contract- are not advisable here, as they 
lead to reduced datasets. I guess that you want these characteristics
stored with the individual-level observations. 

Suppose you have 

familyid    personid  alive (1: alive, 0: dead) 

1               1       0
1               2       0
1               3       0 
1               4       1 
1               5       1
1               6       1 
2               7       0
2               8       0  
2               9       1 
2              10       1
2              11       1
3              12       1
3              13       1
3              14       1 
3              15       1 

The number of dead people in each family is

egen n_dead = total(alive == 0), by(familyid) 

The number of alive people in each family is 

egen n_alive = total(alive == 1), by(familyid) 

In addition, use of Stata terminology is advisable
on Statalist. "case" means "observation" in Stata. 

Nick 
[email protected] 

Ann E Fitzmaurice
 
> Have a data set with approx 22500 cases from n families, i 
> want to create a
> variable wuich is the number of family members in each 
> family, variable
> identification is caseid. The data set includes a second 
> variable denoting
> the status of the person  , either alive or dead
> 
> What I want to do is to put a variable in the file which 
> denotes the number
> within a family for the dead people, for example if there are 
> six siblings,
> and 3 are dead , then the first variable will gave a 6 next 
> to each member
> and a 3 against each member denoting the number dead within a family
> 
> From her it is straight forward to calculate the number of 
> siblings within a
> family still alive and then make an adjustment to the number 
> of women alive
> to reflect that there has been a death in the family
> 
> Can anyone suggest how this might be done
> 
> I have looked at collapse , and calculated the total within 
> the family using
> _N

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