/* Issue: It has been identified that variable whodrive is miscoded; where option 0 (Non-household member) is mistakenly coded as option 1 (Person 1) and so forth. Additionally, a few households recorded non-resident members as drivers. The provided syntax can be used to accurately recode these values and set non-household members to 0 within the two affected waves. The synax is devided into two parts: Part 1 is designed to address miscoded values for 5 variables, whodrive1-whodrive5, within the hhresp data files for waves 10 and 13. Part 2 involves updating the drivers to 0 after identifying that some drivers were no longer residents within the household Please ensure that you set the working directory correctly according to your system before executing the code.*/ /*Part 1: Recodes variable *whodrive* */ glo wdir "~~\wave13\ukda_release_version_m1_13\stata" //set your own working directory qui { foreach v in 10 13 { local w = substr("abcdefghijklmnopqrstuvwxyz",`v',1) + "_" foreach typ in eul sl { use "${wdir}/`typ'/`w'hhresp.dta", clear isvar *whodrive* local varlist `r(varlist)' foreach var of local varlist { forval i=1/10 { replace `var'= `i'-1 if `var'==`i' } n fre `var' } save "${wdir}/`typ'/`w'hhresp.dta", replace } } } /*Part 2: Updates non-houshold mebers after recoding variable *whodrive* */ /*The code below is a fix for all the non-household members that were selected as drivers. These are set to 0 (non-household member)*/ //wave 10 qui { foreach typ in eul sl { use "${wdir}/`typ'/j_hhresp.dta", clear replace j_whodrive1=0 if j_hidp==68693618 & j_whodrive1==1 replace j_whodrive1=0 if j_hidp==340646018 & j_whodrive1==5 replace j_whodrive1=0 if j_hidp==412698818 & j_whodrive1==4 replace j_whodrive1=0 if j_hidp==478373218 & j_whodrive1==2 replace j_whodrive2=0 if j_hidp==478373218 & j_whodrive2==2 replace j_whodrive1=0 if j_hidp==550079218 & j_whodrive1==2 replace j_whodrive1=0 if j_hidp==619126418 & j_whodrive1==2 replace j_whodrive1=0 if j_hidp==681305618 & j_whodrive1==1 replace j_whodrive1=0 if j_hidp==1157387218 & j_whodrive1==2 save "${wdir}/`typ'/j_hhresp.dta", replace } } //Wave 13 qui { foreach typ in eul sl { use "${wdir}/`typ'/m_hhresp.dta", clear replace m_whodrive1=0 if m_hidp==139903224 & m_whodrive1==4 replace m_whodrive1=0 if m_hidp==619588824 & m_whodrive1==2 replace m_whodrive2=0 if m_hidp==619588824 & m_whodrive2==2 replace m_whodrive1=0 if m_hidp==1021109104 & m_whodrive1==2 replace m_whodrive1=0 if m_hidp==1089162824 & m_whodrive1==1 replace m_whodrive2=0 if m_hidp==1089162824 & m_whodrive2==1 replace m_whodrive1=0 if m_hidp==1158169224 & m_whodrive1==1 replace m_whodrive1=0 if m_hidp==1364229624 & m_whodrive1==2 replace m_whodrive1=0 if m_hidp==1635488424 & m_whodrive1==3 replace m_whodrive2=0 if m_hidp==1635488424 & m_whodrive2==3 save "${wdir}/`typ'/m_hhresp.dta", replace } }