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

st: data management(corrected the fromat of e-mail message)


From   "Kemal Aslan" <[email protected]>
To   <[email protected]>
Subject   st: data management(corrected the fromat of e-mail message)
Date   Sat, 19 Nov 2005 10:08:39 +0200

Dear All:
I have the household data that contains the following variables:
hhid: household id.
hrelhd: relation to household head: if hhrelhd=3 that indicates the
individual is considered children.
age: age
female: the gender of individual
maxage: maximum age
bromaxage: maximum age for male children.
 
My aim is to calculate the number of older brothers. Using the solution
suggested in FAQ, I create bromaxage as follows:
 
generate bromaxage=.
bysort hhid: gen bropid=_n
summarize pid
quietly forvalues i=1/`r(max)' {
      generate include=1 if bropid!=`i' & hrelhd==3 & female==0
      egen work=max(age*include), by(hhid)
      replace bromaxage=work if bropid==`i'
      drop include work
}
 
Then I use
generate olderbro=bromaxage>age if hrelhd==3;
replace olderbro=0 if olderbro==.; 
*For each child, what is the number of older brothers?;
gsort hhid hrelhd -age;
by hhid: generate nolderbro=sum(olderbro==1); 
replace nolderbro=0 if olderbro==0;
sort hhid hrelhd age; 
However, I can't get the correct number of older brothers as shown in the
last column-nolderbro-.
How can I fix this problem? Any help would be greatly appreciated.
Thanks a lot in advance.
Best regards,
Kemal Aslan

  				
				
 
+---------------------------------------------------------------------------
-------------------+
hhid   hrelhd   age   female         maxage   olderchild   nolderchildd
bromaxage   olderbro   nolderbro | 
 
|---------------------------------------------------------------------------
-------------------|
10 7        1    43        0         19          0              0         19
0           0  
10 7        2    38        1         19          0              0         19
0           0  
10 7        3    19        0         16          0              0         11
0           0  
10 7        3    16        1         19          1              1         19
1           2 
10 7        3    13        1         19          1              2         19
1           3  
10 7        3    11        0         19          1              3         19
1           1 

  






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