Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: RE: RE: Assigning sex by order of birth


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: RE: RE: Assigning sex by order of birth
Date   Sun, 14 Mar 2010 20:11:31 +0100

<>

Very good point by Nick. I would say it is obvious who of the two of us has experience with family life :-)

So my code should really have been:


*************

clear*

inp byte(Family age_child sex:mylabel), auto
   1            12                 male
   1             5                  female
   1             2                  female
   2             9                  female
   2             7                  female
   2             4                  male  
   2             1                  female
   3			2		male
   3			5		male
end

tempvar reverseorder
bys Family (age_child): gen byte `reverseorder'=_N-_n


bys Family (`reverseorder'): gen byte Boy1st=(_n==1)*(sex==1)
by Family (`reverseorder'): gen byte Girl1st=(_n==1)*(sex==2)
by Family (`reverseorder'): gen byte Boy2nd=(_n==2)*(sex==1)
by Family (`reverseorder'): gen byte Girl2nd=(_n==2)*(sex==2)
l, sepby(Family ) noo
*************


HTH
Martin


-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox
Sent: Sonntag, 14. März 2010 19:54
To: statalist@hsphsun2.harvard.edu
Subject: st: RE: RE: Assigning sex by order of birth

I don't think so. As Cinzia underlines, the first child is the oldest, so -sort family age_child- gives the wrong order. 

It makes things a lot easier if you have a variable which is age negated. Alternatively, look at -gsort-. 

As with Martin's toy dataset, and assuming 1 means male, 2 means female: 

. gen neg_age = - age

. bysort family (neg_age) : gen boyfirst = sex[1] == 1

. bysort family (neg_age) : gen girlfirst = sex[1] == 2

. bysort family (neg_age) : gen boyfirst = sex[2] == 1

etc. 

This will work fine even for one-child families as then -sex[2]- is deemed missing and the indicator will be born 0. 

However, twins and any other children born in the same year as far as the survey were concerned need more code, or even better data. 

Alternatively, assuming no intersex complications, -girlfirst- is just 1 - -boyfirst-, and one is redundant. 

Nick 
n.j.cox@durham.ac.uk 

Martin Weiss

clear

inp byte(Family age_child sex:mylabel), auto
   1            12                 male
   1             5                  female
   1             2                  female
   2             9                  female
   2             7                  female
   2             4                  male  
   2             1                  female
   3			2		male
   3			5		male
end

bys Family (age_child): gen byte Boy1st=(_n==1)*(sex==1)
by Family (age_child): gen byte Girl1st=(_n==1)*(sex==2)
by Family (age_child): gen byte Boy2nd=(_n==2)*(sex==1)
by Family (age_child): gen byte Girl2nd=(_n==2)*(sex==2)
l, sepby(Family ) noo

Cinzia Rienzo

I have some difficulties in creating variables for children in the 
family accounting for their sex and order of birth; in other words I 
want to create the following variables:
“Boy1st” if   First child born is male;
“Girl1st” if First child born is female
“boy2nd” if Second child born is male
“girl2nd” if Second child born is female   and so on.

I tried with the “egen rank”  to create order using the reverse of  the 
age of children in families:
bysort year family: g agechil=age if member ==”child”
bysort year family: g agechil reversed= agechil*-1
bysort  year  serial : egen rank_var = rank(agechil reversed)

 But when I Tab the rank it gives me: 1; 1.5 ; 2;  2.5;  3; 3.5….. 
My question is:  How can I assign the sex by order of birth in families 
using the rank given that the age of first child and numbers of 
children vary by families? 
As in the example below the first child in family 1 is 12 year old and 
the first child in family 2 is 9.


Family    age of child         sex 
   1            12                 male
   1             5                  female
   1             2                  female
   2             9                  female
   2             7                  female
   2             4                  male  
   2             1                  female

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index