**To merge datasets, sweep 1-5 (first remove any unwanted variables), then: merge m:m mcsid using "C:\Users\msrsdhn5.DS\Documents\ESRC SDAI\MCS for ESRC project\MCS longitudinal, sweeps 1- 5\mcs1_parent_interview.dta" drop _merge merge m:m mcsid using "C:\Users\msrsdhn5.DS\Documents\ESRC SDAI\MCS for ESRC project\MCS longitudinal, sweeps 1- 5\mcs2_parent_interview.dta" drop _merge merge m:m mcsid using "C:\Users\msrsdhn5.DS\Documents\ESRC SDAI\MCS for ESRC project\MCS longitudinal, sweeps 1- 5\mcs3_parent_interview.dta" drop _merge merge m:m mcsid using "C:\Users\msrsdhn5.DS\Documents\ESRC SDAI\MCS for ESRC project\MCS longitudinal, sweeps 1- 5\mcs4_parent_interview.dta" drop _merge *to reshape MCS 5 data (CM-CAPI dataset) from long to wide: reshape wide EPPNUM00 - EPPART00, i(mcsid) j( EPELIG00 ) *New variable derived to restructure the data gen ELIG_CM = 0 replace ELIG_CM = 1 if EPELIG00 ==1 & ECCNUM00 == 1 replace ELIG_CM = 2 if EPELIG00 ==1 & ECCNUM00 == 2 replace ELIG_CM = 3 if EPELIG00 ==1 & ECCNUM00 == 3 replace ELIG_CM = 4 if EPELIG00 ==2 & ECCNUM00 == 1 replace ELIG_CM = 5 if EPELIG00 ==2 & ECCNUM00 == 2 replace ELIG_CM = 6 if EPELIG00 ==2 & ECCNUM00 == 3 label define ELIG_CM 1 "Main+CM1" 2 "Main+CM2" 3 "Main+CM3" 4 "Part+CM1" 5 "Part+CM2" 6 "Part+CM3" label values ELIG_CM ELIG_CM label var ELIG_CM "Main or Partner + CM number" **reshape with new variable - there will be 6 levels for your within-group identifier i.e. main_cm1; main_cm2 etc reshape wide [var1] - [var2], i(mcsid) j( ELIG_CM ) merge m:m mcsid using "C:\Users\msrsdhn5.DS\Documents\ESRC SDAI\MCS for ESRC project\MCS longitudinal, sweeps 1- 5\mcs5_parent_interview.dta" drop _merge **The code below removes negative weights and replaces them with system missing. **The ‘foreach’ is used because one may need to apply it to many variables. **Be careful with writing the `var’ , the first quotatation mark is left to the number 1 of your keyboard **the second quotation mark is at the @ key foreach var of varlist AOVWT2 BOVWT2 COVWT2 DOVWT2 EOVWT2{ replace `var' =. if `var'<0 } **weighting data: (the weight command used depends on what data is being used. *if running analyses using sweep 5 variables, the EOVWT2 weight is applied). svyset sptn00 [pweight=DOVWT2], strata (pttype2) svyset sptn00 [pweight=DOVWT2], strata (pttype2) svyset sptn00 [pweight=AOVWT2], strata (pttype2) svyset sptn00 [pweight=bovwt2], strata (pttype2) svyset sptn00 [pweight=COVWT2], strata (pttype2) svyset sptn00 [pweight=EOVWT2], strata (pttype2)