SC1/2: Gemeinsame Geburtsjahrvariable für alle Geschwister

Liebes Team,

ich nutze die SC1 und 2 für meine Analysen und möchte nun eine Variable erstellen, in der die Geburtsjahre aller Geschwister enthalten sind und nicht wie bisher für jedes Geschwisterkind einzeln. Wie kann ich dies machen,  zumal die Variablen in den beiden Kohorten noch unterschiedlich heißen? Kann man einzelne Variablen mergen?

Viele Grüße

Annika

 

Hallo Annika!

Endlich melde ich mich um deine Frage zu beantworten, sorry.

Generell kann man nicht alle Geburtsjahre sämtlicher Geschwister in eine Variable schreiben. Man kann entweder den Mittelwert, das Maximum, Minimum, etc. generieren.

 

Ich habe ein Do-file geschrieben, das die Geschwisterjahr aufbereitet und für SC1 und SC2 umbennent und dann in einen Datensatz schreibt.

 

ich hoffe, das hilft dir weiter.


// open dataset and keep relevant variables
use "<PATH_TO_YOUR_DATA>/SC1_pParent_D_4-0-0.dta", clear 
keep ID_t wave p73222y_w1 p73222y_w2 p73222y_w3 p73222y_w4 p73222y_w5 p73222y_w6 p73222y_w7 p73222y_w8 p73222y_w9 p73222y_w10 p73222y_w11 p73222y_w12 p73222y_w13 p73222y_w14 p73222y_w15 p73222y_w16 p73222y_w17 p73222y_w18 p73222y_w19 p73222y_w20 pb10000

drop pb10000 // drop that indicator
nepsmiss // convert to missing
egen anydate=rowmax(p73222y_w1 p73222y_w2 p73222y_w3 p73222y_w4 p73222y_w5 p73222y_w6 p73222y_w7 p73222y_w8 p73222y_w9 p73222y_w10 p73222y_w11 p73222y_w12 p73222y_w13 p73222y_w14 p73222y_w15 p73222y_w16 p73222y_w17 p73222y_w18 p73222y_w19 p73222y_w20)
keep if inrange(anydate,1950,2017)  // keep plausible cases
drop anydate

local counter 0
foreach var of varlist p73*_w* {	
	local counter `++counter'
	sum `var'
	if `r(N)'==0 {   // keeping only sister-date-variable with at leat one valid year
		drop `var'
	}
	else {
		local oldstub=usubstr("`var'",1,7)  // create local for chars 1-7 of varname
		local lastchar=usubstr("`var'",-1,.)  // create local for last char of varname
		rename `oldstub'_w`lastchar' sibling_w`counter'   // rename vars to sibling_w<NR>
	}
} 
egen siblings_anzahl=rownonmiss(sibling_w*) // create new indicator for numbers of siblings
reshape long  sibling_w, i(ID_t)  // reshaping data to long format to simplify further proceedings
drop _j 
drop if missing(sibling_w) // drop empty lines
distinct ID_t sibling_w, joint // there are more siblings within one year, might be twins 
bysort ID_t (sibling_w): gen sibling_nr=_n  // create new sibling-nr-indicator, sorted by year of birth (NOT UNIQUE)
reshape wide sibling_w, i(ID_t) j(sibling_nr) // reshape to wide again

// merging to complete SC1-Partent-Dataset
merge 1:1 ID_t wave using "<PATH_TO_YOUR_DATA>/SC1_pParent_D_4-0-0.dta", assert(using match)
replace siblings_anzahl=pb10000 if _merge==2 & inlist(pb10000,0,-54)  // fill in values
drop _merge 
gen cohort=1  // generate cohort-indicator prior to merging with sc2-data
rename wave wave_sc1 // to reduce confusion, rename wave indicator
keep ID_t wave_sc1 siblings_anzahl sibling_w* cohort  // (+ other relevant variables)

save "<PATH_TO_YOUR_DATA>/siblings_sc1.dta", replace


*********************************************************************
// exact same procedure using sc2-data

use "<PATH_TO_YOUR_DATA>/SC2_pParent_D_6-0-1.dta" , clear
keep ID_t wave pb10000 pb1002a pb1002b pb1002c pb1002d pb1002e pb1002f pb1002g pb1002h pb1002i pb1002j
drop pb10000
nepsmiss
egen anydate=rowmax(pb1002a pb1002b pb1002c pb1002d pb1002e pb1002f pb1002g pb1002h pb1002i pb1002j)
keep if inrange(anydate,1950,2017)
drop anydate

local counter 0
foreach var of varlist pb1002a pb1002b pb1002c pb1002d pb1002e pb1002f pb1002g pb1002h pb1002i pb1002j {
	local counter `++counter'
	sum `var'
	if `r(N)' == 0 {
		drop `var'
	}
	else {
		local oldstub=usubstr("`var'",1,6)
		local lastchar=usubstr("`var'",-1,.)
		rename `oldstub'`lastchar' sibling_w`counter'
	}
}
egen siblings_anzahl=rownonmiss(sibling_w*)
isid ID_t 
reshape long sibling_w, i(ID_t)
drop _j
drop if missing(sibling_w)
distinct ID_t sibling_w, joint
bysort ID_t (sibling_w): gen sibling_nr=_n
reshape wide sibling_w, i(ID_t) j(sibling_nr)

merge 1:1 ID_t wave using  "<PATH_TO_YOUR_DATA>/SC2_pParent_D_6-0-1.dta", assert(using match)
replace siblings_anzahl=pb10000 if _merge==2 & inlist(pb10000,0,-54)
drop _merge 
gen cohort=2
rename wave wave_sc2
keep ID_t wave_sc2 siblings_anzahl sibling_w*  cohort // (+ other relevant variables)

**************************************************

append using  "<PATH_TO_YOUR_DATA>/siblings_sc1.dta" // adding cases from cohort 1 to already opened sc2-data
order ID_t wave_sc* cohort siblings_anzahl  // order variables
sort cohort ID_t wave_sc1 wave_sc2  

// might be usefull?
egen sibyear_mean=rowmean(sibling_w*)  // means within person
egen sibyear_min=rowmin(sibling_w*)  // birth year of oldest sibling
egen sibyear_max=rowmax(sibling_w*) // birth year of youngest sibling

 

Viele Grüße und nochmals sorry für die lange Wartezeit.

Dietmar.