Hello,
I am currently working with a data set with the unit of observation as households. There are also variables for each member of the household e.g hv101_01 for person one in the household, hv101_02 for the second person in the household and up to hv101_39, all of which contain the same label. This is is the case for many variables.
I will like to change the names of all variables to the label name. I was able to figure this out as:
foreach v of var * {
local lbl : var label `v'
local lbl = strtoname("`lbl'")
rename `v' `lbl'
label variable `lbl' "`v'"
}
But when it reaches the variables that are for the second member of the household e.g hv101_02, Stata says that the variable name is already defined. I know that this is because hv101_01 already has that variable name.
I will like to add _02 or whatever number is behind the variable when the variable is changed to the label name.
Can someone please help with a code for this.
Thank you for the anticipated response.
I am currently working with a data set with the unit of observation as households. There are also variables for each member of the household e.g hv101_01 for person one in the household, hv101_02 for the second person in the household and up to hv101_39, all of which contain the same label. This is is the case for many variables.
I will like to change the names of all variables to the label name. I was able to figure this out as:
foreach v of var * {
local lbl : var label `v'
local lbl = strtoname("`lbl'")
rename `v' `lbl'
label variable `lbl' "`v'"
}
But when it reaches the variables that are for the second member of the household e.g hv101_02, Stata says that the variable name is already defined. I know that this is because hv101_01 already has that variable name.
I will like to add _02 or whatever number is behind the variable when the variable is changed to the label name.
Can someone please help with a code for this.
Thank you for the anticipated response.
Comment