Dear all,
I`m trying to calculate duration terms, giving the number of years passed since the birth of the youngest child.
My data structure looks like this:
pid year kidbirth1 kidbirth2 kidbirth3
4 1999 2001 2005 -2
4 2000 2001 2005 -2
4 2001 2001 2005 -2
4 2002 2001 2005 -2
4 2003 2001 2005 -2
4 2004 2001 2005 -2
4 2005 2001 2005 -2
4 2006 2001 2005 -2
5 1999 1982 -2 -2
5 2000 1982 -2 -2
. .
. .
. .
I tried different things like for example generating a auxiliary variable like:
sort pid syear
egen min_kid_year=rowmax(kidbirth*)
and then calculate a duration term:
gen duration = 0
sort pid syear
by pid: replace duration= syear-min_kid_year if min_kid_year >0 & min_kid_year!=.
But what makes thinks difficult is that i need the auxiliary variable min_kid_year to be 2001 before the year 2005 (birth of the second child) and to be 2005 after the birth of the second child. Also the "-2" make things tricky.
I also tried to use -ereplace- but nothing really worked for me.
I would appreciate any help. Thanks in advance
I`m trying to calculate duration terms, giving the number of years passed since the birth of the youngest child.
My data structure looks like this:
pid year kidbirth1 kidbirth2 kidbirth3
4 1999 2001 2005 -2
4 2000 2001 2005 -2
4 2001 2001 2005 -2
4 2002 2001 2005 -2
4 2003 2001 2005 -2
4 2004 2001 2005 -2
4 2005 2001 2005 -2
4 2006 2001 2005 -2
5 1999 1982 -2 -2
5 2000 1982 -2 -2
. .
. .
. .
I tried different things like for example generating a auxiliary variable like:
sort pid syear
egen min_kid_year=rowmax(kidbirth*)
and then calculate a duration term:
gen duration = 0
sort pid syear
by pid: replace duration= syear-min_kid_year if min_kid_year >0 & min_kid_year!=.
But what makes thinks difficult is that i need the auxiliary variable min_kid_year to be 2001 before the year 2005 (birth of the second child) and to be 2005 after the birth of the second child. Also the "-2" make things tricky.
I also tried to use -ereplace- but nothing really worked for me.
I would appreciate any help. Thanks in advance
Comment