** Macro for BHPS ethnicity coding between 'old' (1991-200, 'wrace') variable * and new (2001->, 'wracel') variable, * with additional imputation for household structure. *********************** capture program drop xethbhps program define xethbhps version 10.1 args race racel hid xeth xethh **** To use this file: * We assume you have BHPS variables 'race' and 'racel', and a BHPS current household * identifier 'hid' (calculate as _n if not available - i.e. giving a unique value per case) * * Macro will generate new variables called xeth, which is harmonisation of the race and racel * measures, and xethh, which is the same as xeth but also imputes missing values on basis of * household sharers if available (highest numeric category mentioned) **** * Individual level harmonisation tab1 `race' `racel' capture drop `xeth' gen `xeth'=`racel' recode `xeth' 1/5=1 6/9=2 10=3 11=4 12=5 13=6 14=7 15=8 16=9 17=10 18=11 *=-9 capture drop _tempvar gen _tempvar=`race' recode _tempvar 1=1 2=7 3=8 4=9 5=3 6=4 7=5 8=10 9=11 *=-9 replace `xeth'=_tempvar if `xeth'==-9 & _tempvar ~= -9 capture label drop eth_ons3 label define eth_ons3 /// 1 "White" /// 2 "Mixed" /// 3 "Indian" /// 4 "Pakistani" /// 5 "Bangladeshi" /// 6 "Other Asian" /// 7 "Black-Caribbean" /// 8 "Black African" /// 9 "Other Black" /// 10 "Chinese" /// 11 "Other ethnic group" label values `xeth' eth_ons3 label variable `xeth' "Own ethnic group, BHPS harmonisation from 1991/2001 schemes" tab1 `race' `racel' `xeth' , missing * Household level imputation capture drop _tempvar egen _tempvar=max(`xeth'), by(`hid') capture drop `xethh' clonevar `xethh' = `xeth' replace `xethh'=_tempvar if xeth==-9 & _tempvar ~=-9 drop _tempvar label values `xethh' eth_ons3 label variable `xeth' "Ethnic group, own or family, BHPS harmonisation from 1991/2001 schemes" mvdecode `xeth', mv(-9) mvdecode `xethh', mv(-9) tab1 `race' `racel' `xeth' `xethh', missing end ******************************* *** References: * BHPS data: * http://www.iser.essex.ac.uk/survey/bhps/documentation/volb/wave17/xwavedat.html#RACEL * ONS codes: * Office for National Statistics. (2003). Ethnic group statistics: A guide for the collection and classification of ethnicity data. London: HMSO. * * ** EOF