****************************************************************** ******** This program generates the G2 population **************** ****************************************************************** clear forva x=2006/2017{ use E:\Data\rawdata\705830\bef`x' keep pnr foed_dag`x' alder`x' ie_type`x' koen`x' /*keeps identifier, birth year, age, immigration status and gender */ keep if alder`x'>21 /*keep only individuals older than 21 */ rename alder`x' alder rename ie_type`x' ie_type rename koen`x' koen gen fodaar=year(foed_dag`x') save E:\Data\workdata\705830\zic\sha\replication\data\bef`x', replace } use E:\Data\workdata\705830\zic\sha\replication\data\bef2006 forva x=2007/2017{ append using E:\Data\workdata\705830\zic\sha\replication\data\bef`x' } save E:\Data\workdata\705830\zic\sha\replication\data\bef_samlet_test, replace clear use E:\Data\workdata\705830\zic\sha\replication\data\bef_samlet_test bysort pnr: gen optal=_n bysort pnr: egen max_optal=max(optal) keep if max_optal==optal /*keep latest observation per individual - to avoid duplicates and count the number of data years per individual */ replace fodaar=0 if fodaar==. replace ie_type=0 if ie_type==. replace koen=0 if koen==. bysort pnr: egen fod_max=max(fodaar) bysort pnr: egen ie_max=max(ie_type) bysort pnr: egen koen_max=max(koen) drop fodaar ie_type koen rename fod_max fodaar rename ie_max ie_type rename koen_max koen keep pnr fodaar ie_type koen max_optal /*keep identifier, birth year, immigrant status, gender and data years */ save E:\Data\workdata\705830\zic\sha\replication\data\grund_pop, replace