Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, and its replacement, **statalist.org** is already up and running.

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

From |
"Nick Cox" <n.j.cox@durham.ac.uk> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
RE: st: RE: Calculate number of alive male and female children from a family dataset |

Date |
Tue, 1 Jun 2010 19:31:14 +0100 |

Although code has been produced, a simple point that no code can resolve is that a birth and a death of a previous child in the same calendar year leave ambiguous whether the death occurred before or after the birth. So, the number of children already alive may be uncertain to that extent. Of course, that's also true of daily data, but for years it could easily bite in a large dataset. Nick n.j.cox@durham.ac.uk Anna Reimondos Thank you very much Martin -that did the trick. On Mon, May 31, 2010 at 3:12 AM, Martin Weiss <martin.weiss1@gmx.de> wrote: > Extension of this code to several mothers will require use of -bysort-, btw: > > > *********** > clear* > set obs 6 > *Mother's id > gen byte motherid=1 > > *Birth order > gen byte birth=_n > > *child's sex > gen byte chsex=1+inlist(_n,4,5) > > label define chsex 1 male 2 female > label values chsex chsex > > *born year > gen int bornyear=1982 > replace bornyear=1985 in 2 > replace bornyear=1986 in 3 > replace bornyear=1989 in 4 > replace bornyear=1990 in 5 > replace bornyear=1995 in 6 > > *death year > gen deathyear=1994 in 2 > > expand 2 if !mi(deathyear), gen(myindicator) > gen year=cond(myindicator, deathyear, bornyear) > la def myvals 0 "birth" 1 "death" > la val myindicator myvals > sort year > > gen deadmale=sum((chsex==1)*myindicator) > gen deadfemale=sum((chsex==2)*myindicator) > gen alivmale=sum((chsex==1)*!myindicator)-deadmale > gen alivfemale=sum((chsex==2)*!myindicator)-deadfemale > drop if myindicator > drop myindicator year > sort birth > > > list, noo sepby(chsex) > *********** Anna Reimondos > I have a dataset which had the complete birth histories of a survey of > women. The data is in 'long' format so that each woman has one > observations for each child she has had. The information I want to > work with is the child's date of birth, date of death (if applicable) > and sex. From this I would like to calculate at the time of each > birth, how many alive male children the woman had, how many alive > female children, how many dead male children and how many dead female > children. That is the part I am having trouble with. > > Here is a quick example of one hypothetical womans history: > This woman has had 6 births (4 males, and 2 females - where sex=1 is > male and sex=2 is female) > All the children were still alive at the time of the survey except for > the second birth. That child died in 1994. > Based on this information I want to fill in the variables alivmale > (number of male children alive at the time of the birth of child X), > alivfem, deadmale and deadfem. > For example at the time of the birth of the 6th child the woman had > had 2 male children, 2 female children and the 1 male child that had > died. > > motherid Birth sex bornyear deathyear alivmale alivfem > deadmale deadfem > 1 1 1 1982 0 > 0 0 0 > 1 2 1 1985 1994 1 > 0 0 0 > 1 3 1 1986 2 > 0 0 0 > 1 4 2 1989 3 > 0 0 0 > 1 5 2 1990 3 > 1 0 0 > 1 6 1 1995 2 > 2 1 0 > > > > I can't seem to get it right. > I thought it would be a fun problem to get into, but after struggling > now for quite a long time it is not so fun anymore. > I hope someone will be able to see a solution.... > Thanks > Anna > > P.S I have written the code to produce this dataset in STATA as well > if that helps. > > set obs 6 > *Mother's id > gen motherid=1 > > *Birth order > gen birth=. > forvalues n=1/6 { > replace birth=`n' in `n'/`n' > } > > *child's sex > gen chsex=1 in 1/3 > replace chsex=2 in 4/5 > replace chsex=1 in 6/6 > > label define chsex 1 male 2 female > label values chsex chsex > > > *born year > gen bornyear=. > replace bornyear=1982 in 1/1 > replace bornyear=1985 in 2/2 > replace bornyear=1986 in 3/3 > replace bornyear=1989 in 4/4 > replace bornyear=1990 in 5/5 > replace bornyear=1995 in 6/6 > > *death year > gen deathyear=. > replace deathyear=1994 in 2/2 * * 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/

- Prev by Date:
**st: RE: Graph dot labels** - Next by Date:
**st: RE: RE: Graph dot labels** - Previous by thread:
**st: RE: RE: RE: Placing results in a new stata sheet** - Next by thread:
**st: RE: Cannot calculate AR and Sargan tests (returning .)** - Index(es):