Hi There,
I have been trying to solve this problem for a while and just can't figure it out. I am using household surveys for the last 15 years published each year with the same variables but they are the same variable. I would like to perform an analysis per year on a long list of variables but in order to do this I have to rename each variable in year dataset that is different. For example if I want to rename one variable I would write the code
global years "10 11 12 13 14 15 16 17 18 19 20 21"
foreach X of global years {
use "$Data\GHS\GHS_merged_20`X'.dta", clear
numlabel, add
* Connection to mains
cap rename Q330aMains eng_mains
cap rename Q327aMains eng_mains
cap rename Q328AMAINS eng_mains
cap rename Q528aMains eng_mains
cap rename ENG_MAINS eng_mains
tab eng_mains
gen byte mains=eng_mains==1
tab mains
save "$Data\GHS\GHS_cleaned_20`X'.dta", replace
}
These variables are all the same and there are several variables that I have to rename. The label names seem to be aligned but not the variable names. I wanted to know if there was a simple way to rename all variables with a specific label of if there was a way to link the same variable that has been named differently across the same household survey in order to link the datasets over time.
I have been trying to solve this problem for a while and just can't figure it out. I am using household surveys for the last 15 years published each year with the same variables but they are the same variable. I would like to perform an analysis per year on a long list of variables but in order to do this I have to rename each variable in year dataset that is different. For example if I want to rename one variable I would write the code
global years "10 11 12 13 14 15 16 17 18 19 20 21"
foreach X of global years {
use "$Data\GHS\GHS_merged_20`X'.dta", clear
numlabel, add
* Connection to mains
cap rename Q330aMains eng_mains
cap rename Q327aMains eng_mains
cap rename Q328AMAINS eng_mains
cap rename Q528aMains eng_mains
cap rename ENG_MAINS eng_mains
tab eng_mains
gen byte mains=eng_mains==1
tab mains
save "$Data\GHS\GHS_cleaned_20`X'.dta", replace
}
These variables are all the same and there are several variables that I have to rename. The label names seem to be aligned but not the variable names. I wanted to know if there was a simple way to rename all variables with a specific label of if there was a way to link the same variable that has been named differently across the same household survey in order to link the datasets over time.

Comment