*cd "C:\Documents and Settings\fgarip\My Documents\C Manuscripts\Migrant Social Capital Paper June 05" cd "Z:\C Manuscripts\Migrant Social Capital Paper June 05" clear set mem 500m set matsize 100 ** Last Updated: 20 September 2006 use "Data\idhhvill_allages.dta", replace *********************************************** ** Save restricted data for MLwin - All Ages ** *********************************************** destring hhid84, gen(hhid84_2) destring vill84, gen(vill84_2) ** hhid84_2 is stored in scientific format and Mlwin does not read that format ** (It is possibly treated as text). So, I generate a new, shorter hh id. *************************** ** Change Household IDs ** *************************** ** Create a data set where household id's are consecutive numbers save "Data\Temp\Base13_35.dta", replace ** Start w/ year 1985 keep if year==1985 egen hid = group(hhid84_2) keep hhid84_2 hid sort hhid84_2 save "Data\Temp\htemp85.dta", replace use "Data\Temp\Base13_35.dta" sort hhid84_2 merge hhid84_2 using "Data\Temp\htemp85.dta" drop _merge sort hhid84_2 save "Data\Temp\hpdat85.dta", replace ** Generate new id's for new hhs in 1986 use "Data\Temp\hpdat85.dta", clear egen maxhid = max(hid) keep if year==1986 & hid==. egen tempid = group(hhid84_2) replace hid = maxhid + tempid keep hhid84_2 hid sort hhid84_2 save "Data\Temp\htemp86.dta", replace use "Data\Temp\hpdat85.dta" sort hhid84_2 merge hhid84_2 using "Data\Temp\htemp86.dta", update drop _merge sort hhid84_2 save "Data\Temp\hpdat86.dta", replace ** Generate new id's for new hhs in 1987 use "Data\Temp\hpdat86.dta", clear egen maxhid = max(hid) keep if year==1987 & hid==. egen tempid = group(hhid84_2) replace hid = maxhid + tempid keep hhid84_2 hid sort hhid84_2 save "Data\Temp\htemp87.dta", replace use "Data\Temp\hpdat86.dta" sort hhid84_2 merge hhid84_2 using "Data\Temp\htemp87.dta", update drop _merge sort hhid84_2 save "Data\Temp\hpdat87.dta", replace ** Generate new id's for new hhs in 1988 use "Data\Temp\hpdat87.dta", clear egen maxhid = max(hid) keep if year==1988 & hid==. egen tempid = group(hhid84_2) replace hid = maxhid + tempid keep hhid84_2 hid sort hhid84_2 save "Data\Temp\htemp88.dta", replace use "Data\Temp\hpdat87.dta" sort hhid84_2 merge hhid84_2 using "Data\Temp\htemp88.dta", update drop _merge sort hhid84_2 save "Data\Temp\hpdat88.dta", replace ** Generate new id's for new hhs in 1989 use "Data\Temp\hpdat88.dta", clear egen maxhid = max(hid) keep if year==1989 & hid==. egen tempid = group(hhid84_2) replace hid = maxhid + tempid keep hhid84_2 hid sort hhid84_2 save "Data\Temp\htemp89.dta", replace use "Data\Temp\hpdat88.dta" sort hhid84_2 merge hhid84_2 using "Data\Temp\htemp89.dta", update drop _merge sort hhid84_2 save "Data\Temp\hpdat89.dta", replace ** Generate new id's for new hhs in 1990 ** IMP! There are no new hh's after 1990, so we omit the checks. ** Note that this was not the case with 18-25 year olds, there were ** new hh's in every year. This is because we were excluding hh's with ** no members in the age range, and including them as new hh's as they aged. use "Data\Temp\hpdat89.dta", clear save "Data\Temp\hpdat94.dta", replace ** Merge with the data set where household id's are consecutive numbers use "Data\Temp\Base13_35.dta", clear sort hhid84_2 merge hhid84_2 using "Data\Temp\hpdat94.dta" drop _merge tab vill84, gen(v) ren vill84_2 vid ren hid hhid ren id_lh id ren hhland0 land0 ren hhland010 land010 ren hhland1025 land1025 ren hdivc_htrip hdiv_ht ren cdivc_ctrip cdiv_ct ren hodivc_htrip hodiv_ht ren codivc_ctrip codiv_ct ren veqc_ctrip veq_ct ren rmec_htrip rme_ht ren rmec_ctrip rme_ct ren vremote84 vremote ren nodep84 nodep ** Generate an id-variable for person-year records sort id year gen i=_n keep outnr age sex sec* married nmig nodep land0 land010 land1025 year vremote velec wshortg uorate /// htrip ctrip hdivc cdivc hodivc codivc veqc rmec hdiv_ht cdiv_ct hodiv_ht codiv_ct veq_ct /// rme_ht rme_ct id hhid vid i sort vid hhid id i save "Data\mlwin_allages.dta", replace lab data "All ages for MLwiN application" ** Convert to Mlwin format stata2mlwin using "Data\mlwin_allages", replace