Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

st: Using expand


From   Grethe Søndergaard <[email protected]>
To   [email protected]
Subject   st: Using expand
Date   Tue, 18 Jan 2011 13:41:50 +0100

Hi,

I have a dataset that includes full siblings from different families
(two full siblings from each family).

Variables:
id_child
id_mother
id_father
birthdate (of the child)

I only want to use full siblings with an age different less than 5
years. In order to do this, I am using expand:

by id_mother id_father, sort: gen gfreq = _N
expand gfreq, generate(dub)
sort id_mother id_father id_child
by id_mother id_father id_child: gen num_child = _n

by id_mother id_father: gen id_child2  = id_child[gfreq * num_child]
by id_mother id_father: gen birthdate2 = birthdate[gfreq*num_child]

gen age_difference = (birthdate2 - birthdate)/365.25
replace age_difference = age_difference*-1 if age_difference<0
keep if age_difference<5

After doing this, I want to revert to the original observations:
keep if dub==0

- but is that the right way to do it?
The reason why I am asking is, that the number of observations before
I use dub==0 isn't exactly twice the number of observations after I
use dub==0. (N=1.426.648 before and N=713.466) - And shouldn't it be -
or am do I misunderstand something?
*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index