********************************************************************************************************************************************************************* ********data set used for identifying G1 parents and data set used for counting number of years G1 mother and G1 father are present between 1984 and 1994************ ********************************************************************************************************************************************************************* /*data set for G1 parents*/ clear use E:\Data\rawdata\705830\bef2006 keep pnr mor_id far_id /*keeps identifier for the individual, mother and father save E:\Data\workdata\705830\zic\sha\replication\data\forældre2006, replace forva x=2007/2017{ use E:\Data\rawdata\705830\bef`x' keep pnr mor_id far_id rename mor_id mor_id`x' rename far_id far_id`x' save E:\Data\workdata\705830\zic\sha\replication\data\forældre`x', replace } clear use E:\Data\workdata\705830\zic\sha\replication\data\forældre2006 forva x=2007/2017{ merge 1:1 pnr using E:\Data\workdata\705830\zic\sha\replication\data\forældre`x', nogen } replace mor_id=mor_id2007 if mor_id==. replace mor_id=mor_id2008 if mor_id==. replace mor_id=mor_id2009 if mor_id==. replace mor_id=mor_id2010 if mor_id==. replace mor_id=mor_id2011 if mor_id==. replace mor_id=mor_id2012 if mor_id==. replace mor_id=mor_id2013 if mor_id==. replace mor_id=mor_id2014 if mor_id==. replace mor_id=mor_id2015 if mor_id==. replace mor_id=mor_id2016 if mor_id==. replace far_id=far_id2007 if far_id==. replace far_id=far_id2008 if far_id==. replace far_id=far_id2009 if far_id==. replace far_id=far_id2010 if far_id==. replace far_id=far_id2011 if far_id==. replace far_id=far_id2012 if far_id==. replace far_id=far_id2013 if far_id==. replace far_id=far_id2014 if far_id==. replace far_id=far_id2015 if far_id==. replace far_id=far_id2016 if far_id==. bysort pnr: gen optal=_n keep if optal==1 keep pnr mor_id far_id save E:\Data\workdata\705830\zic\sha\replication\data\forældre_samlet, replace *counts number of years G1 parents are in the data between 1984 and 1994 clear forva x=1980/2017{ use E:\Data\rawdata\705830\bef`x' keep pnr gen ibef`x'=1 /*ibef`x' takes the value 1 if the individual is in the data in year`x' save E:\Data\workdata\705830\zic\sha\replication\data\bef`x', replace } clear use E:\Data\workdata\705830\zic\sha\replication\data\bef1980 forva x=1981/2017{ merge 1:1 pnr using E:\Data\workdata\705830\zic\sha\replication\data\bef`x', nogen } forva x=1980/2017{ replace ibef`x'=0 if ibef`x'==. /*ibef`x' takes the value 0 if the individual is not in the data in year`x' } *generate variable counting the number of years (data years) the individual appears in the data from 1984 to 1994 */ gen ibef84_94=ibef1984+ibef1985+ibef1986+ibef1987+ibef1988+ibef1989+ibef1990+ibef1991+ /// ibef1992+ibef1993+ibef1994 rename pnr mor_id rename ibef84_94 ibef84_94_mor keep mor_id ibef84_94_mor /*keeps identifier and count variable for data years*/ /* data set for G1 mothers */ save E:\Data\workdata\705830\zic\sha\replication\data\bef_samlet_test_mor, replace rename mor_id far_id rename ibef84_94_mor ibef84_94_far keep far_id ibef84_94_far /*keeps identifier and count variable for data years*/ /* data set for G1 fathers */ save E:\Data\workdata\705830\zic\sha\replication\data\bef_samlet_test_far, replace