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

Re: st: data management


From   "Svend Juul" <[email protected]>
To   <[email protected]>
Subject   Re: st: data management
Date   Sat, 19 Nov 2005 21:42:54 +0100

Kemal Aslan wrote:
For maxage and bromaxage, my main motivation was to take into
account twin, triple kids. But, unfortunately, I can't use then
efficiently in the first place to derive the number of older boys.
... could you give me any advice how I can take into acoount twin,
triple kids?
---------------------------------------------------------

OK, this took a couple of trials, but I think I ended up right.
Check carefully!

Best wishes,
Svend


clear
input str4 hhid hrelhd age female
10_7 1 43 0
10_7 2 38 1
10_7 3 19 0
10_7 3 16 1
10_7 3 13 1
10_7 3 11 0
10_8 1 43 0
10_8 2 38 1
10_8 3 10 1
10_8 3 11 0
10_8 3 11 0
10_8 3 13 0
10_8 3 14 1
10_8 3 14 0
10_8 3 14 0
10_8 3 14 0
end

gen male = 1-female

// by...: does not consider age sorted after gsort -age.
gen _age = -age
sort hhid hrelhd _age

// -boysum- is boy number (oldest first); twins have different numbers
by hhid hrelhd: gen boysum = sum(male) if hrelhd==3

// -boysum2- is boy number (oldest first), but twins have the same high number
by hhid hrelhd _age: egen boysum2 = max(boysum) if hrelhd==3

// -boysamage- it the number of boys of same age
by hhid hrelhd _age: egen boysamage = sum(male) if hrelhd==3

// The number of older brothers is boysum2-boysamage
gen nolderbr = boysum2-boysamage

sort hhid hrelhd age
list hhid-female boysum-nolderbr
      +-----------------------------------------------------------------------+
      | hhid   hrelhd   age   female   boysum   boysum2   boysam~e   nolderbr |
      |-----------------------------------------------------------------------|
   1. | 10_7        1    43        0        .         .          .          . |
   2. | 10_7        2    38        1        .         .          .          . |
   3. | 10_7        3    11        0        2         2          1          1 |
   4. | 10_7        3    13        1        1         1          0          1 |
   5. | 10_7        3    16        1        1         1          0          1 |
      |-----------------------------------------------------------------------|
   6. | 10_7        3    19        0        1         1          1          0 |
   7. | 10_8        1    43        0        .         .          .          . |
   8. | 10_8        2    38        1        .         .          .          . |
   9. | 10_8        3    10        1        6         6          0          6 |
  10. | 10_8        3    11        0        5         6          2          4 |
      |-----------------------------------------------------------------------|
  11. | 10_8        3    11        0        6         6          2          4 |
  12. | 10_8        3    13        0        4         4          1          3 |
  13. | 10_8        3    14        0        1         3          3          0 |
  14. | 10_8        3    14        0        3         3          3          0 |
  15. | 10_8        3    14        0        2         3          3          0 |
      |-----------------------------------------------------------------------|
  16. | 10_8        3    14        1        0         3          3          0 |
      +-----------------------------------------------------------------------+


________________________________________________________

Svend Juul
Institut for Folkesundhed, Afdeling for Epidemiologi
(Institute of Public Health, Department of Epidemiology)
Vennelyst Boulevard 6
DK-8000 Aarhus C,  Denmark
Phone, work:  +45 8942 6090
Phone, home:  +45 8693 7796
Fax:          +45 8613 1580
E-mail:       [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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index