Bookmark and Share

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

[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


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

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:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index