******************************************************************************** * Created by: Clinton Hayes * * Updated by: Nicole Watson & Markus Hahn * * * * Purpose of the progam: * * ====================== * * This program demonstrates how to merge the partner information to the * * responding person file. Wave 1 data is used here as an example. * * Please note that we use 'tempfile partner' to create a macro (local) that * * allows us to access a temporary data file which will be automatically * * deleted when this do-file ends. * ******************************************************************************** clear set memory 1g // Specify directories (use "." to point to current directory) local origdatadir "C:\orig-data" // Location of original HILDA data files local newdatadir "C:\new-data" // Location to which to write new data files // Prepare a data set with partner information use "`origdatadir'\Rperson_a180c.dta" keep xwaveid ahgage ahgsex // keep the variables wanted rename xwaveid ahhpxid // rename matching indicator rename ahgage apartage // rename age variable rename ahgsex apartsex // rename sex variable tempfile partner save "`partner'", replace // save to temporary partner file // Merge responding persion file with partner file use "`origdatadir'\Rperson_a180c.dta" merge m:1 ahhpxid using "`partner'" // use many-to-one merge because ahhpxid // has missing values drop if (_merge==2) // cases can't be merged because respondent has no partner // or partner is non-respondent drop _merge sort xwaveid // sort dataset by xwaveid // Save new data set save "`newdatadir'\rperson-partner", replace