Statalist


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

Re: st: RE: constructing sibling sex composition


From   Neil Shephard <[email protected]>
To   [email protected]
Subject   Re: st: RE: constructing sibling sex composition
Date   Mon, 08 Dec 2008 10:14:19 +0000

Nirina F wrote:
> Dear Martin,
> I looked but couldn't find which one would work for what I
> specifically would like to construct.
> Do you mind pointing it to me please?
>   

Perhaps something like....

local t = 1
foreach x in male female{
  if("`x'" == "female") local t = 2
  egen t_`x' = count(sex) if(sex == `t' & (father != 0 | mother != 0)),
by(family)
  egen n_`x' = mean(t_`x'), by(family)
  bysort family: replace n_`x' = 0 if(n_`x' == .)
  drop t_`x'
}

This will leave you with two variables 'n_male' and 'n_female' which
indicate how many males and females there are in each family
respectively, not including the parents.

There are however a few assumptions in the above code...

1) It assumes that sex is encoded to represent the number of X
chromosomes and individual carries (Males == XY; Females == XX;
Kleinfelters and other forms of trisomy are ignored).

2) It also assumes that you have your data structured in what is known
as LINKAGE whose format is described  at
http://linkage.rockefeller.edu/soft/linkage/   .  Where you have the
following five basic variables that allow you to uniquely reconstruct
the pedigree structure... 'FamilyID'    Uniquely identifies a family
'IndividualID'  Uniquely identifies an individual within the family group
'FatherID' (variable father in above code)   Uniquely identifies the
father within a given family
'MotherID' (variable mother in above code)  Uniquely identifies the
mother within a given family
'Sex' Sex indicator male == 1; female == 2

'Founders' (in the case the parents) of a family do not have
identifiable parents and are therefore given a value of zero for these
two fields.  If you have another way of identifying the parents then you
must exclude them from the 'egen = count()' call, otherwise you will
have them included in the number of males/females in each family.

I can't think of any way of construct _a_ variable that indicates the
sex composition within a family as you originally asked.  If you totaled
up the value of the sex indicators then its too ambiguous, a family with
12 male children would give a total of 12 just as a family of six female
children would, making them indistinguishable.

Obviously if your data is not in this structure you will have to either
coerce it into it or think of an alternative, but the LINKAGE format was
designed specifically for analysing family data (when investigating
genetic linkage of markers to disease phenotypes under parametric models).

Neil


Example....

. list

     +----------------------------------------------------+
     | family   indivi~l   father   mother   sex   t_male |
     |----------------------------------------------------|
  1. |      1          1        0        0     1        . |
  2. |      1          2        0        0     2        . |
  3. |      1          3        1        2     1        . |
  4. |      1          4        1        2     1        . |
  5. |      1          5        1        2     1        . |
     |----------------------------------------------------|
  6. |      1          6        1        2     2        1 |
  7. |      2          1        0        0     1        . |
  8. |      2          2        0        0     2        . |
  9. |      2          3        1        2     2        2 |
 10. |      2          4        1        2     2        2 |
     +----------------------------------------------------+


. local t = 1

. foreach x in male female{
  2.
.   if("`x'" == "female") local t = 2
  3.
.   egen t_`x' = count(sex) if(sex == `t' & (father != 0 | mother !=
0)), by(family)
  4.
.   egen n_`x' = mean(t_`x'), by(family)
  5.
.   bysort family: replace n_`x' = 0 if(n_`x' == .)
  6.
.   drop t_`x'
  7.
. }
(7 missing values generated)
(4 missing values generated)
(4 real changes made)
(7 missing values generated)
(0 real changes made)

. list

     +---------------------------------------------------------------+
     | family   indivi~l   father   mother   sex   n_male   n_female |
     |---------------------------------------------------------------|
  1. |      1          1        0        0     1        3          1 |
  2. |      1          2        0        0     2        3          1 |
  3. |      1          3        1        2     1        3          1 |
  4. |      1          4        1        2     1        3          1 |
  5. |      1          5        1        2     1        3          1 |
     |---------------------------------------------------------------|
  6. |      1          6        1        2     2        3          1 |
  7. |      2          1        0        0     1        0          2 |
  8. |      2          2        0        0     2        0          2 |
  9. |      2          3        1        2     2        0          2 |
 10. |      2          4        1        2     2        0          2 |
     +---------------------------------------------------------------+

-- 
"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." - Albert Einstein


***********************************************************************
This  message  may  contain  confidential and  privileged  information.
If you  are not the  intended recipient  you should not  disclose, copy
or distribute information in this e-mail or take any action in reliance
on its contents.  To do so is strictly  prohibited and may be unlawful.
Please  inform  the  sender that  this  message has  gone astray before
deleting it.  Thank you.

2008 marks the 60th anniversary of the NHS.  It's an opportunity to pay
tribute to the NHS staff and volunteers who help shape the service, and
celebrate their achievements.

If you work for the NHS  and  would like  an NHSmail  email account, go
to: www.connectingforhealth.nhs.uk/nhsmail
***********************************************************************

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index