Dear Statalist,
I have a large survey panel dataset that includes various waves of the survey. Sadly, not all questions are asked in all waves of the survey. Hence, to keep track of which variable/question appears in which wave of the survey, I want to edit the variable label with the number of the waves the question appears in.
So let's say, we have the question for the gender of a participant in waves 1, 2, and 5; and the question of how much the participant likes apples in waves 1, 3, and 6 of the survey.
My dataset hence contains the variables w1_sex, w2_sex, and w5_sex as well as w1_appel, w2_apple, and w6_apple.
All variables in the dataset are named in the following way: w`number_of_wave'_`abbreviation_of_quetsion'
What I intend to do is to rewrite the labels of all w*_sex variables from "Gender of participant" to " 1 2 5 Gender of participant" and of all w*_appel labels from "Likes Appels (scale 1 not at all to 5 very much)" to "1 3 6 Likes Appels (scale 1 not at all to 5 very much)".
I've been toying around a lot, but have not seen any promising results yet.
Here is just a sample of how I tried to approach the problem.
Code:
Thank you very much for your help in advance. I've been a long-time reader of the forum but this is the first time I honestly could not find any help with my problem.
Best,
Fabian
I have a large survey panel dataset that includes various waves of the survey. Sadly, not all questions are asked in all waves of the survey. Hence, to keep track of which variable/question appears in which wave of the survey, I want to edit the variable label with the number of the waves the question appears in.
So let's say, we have the question for the gender of a participant in waves 1, 2, and 5; and the question of how much the participant likes apples in waves 1, 3, and 6 of the survey.
My dataset hence contains the variables w1_sex, w2_sex, and w5_sex as well as w1_appel, w2_apple, and w6_apple.
All variables in the dataset are named in the following way: w`number_of_wave'_`abbreviation_of_quetsion'
What I intend to do is to rewrite the labels of all w*_sex variables from "Gender of participant" to " 1 2 5 Gender of participant" and of all w*_appel labels from "Likes Appels (scale 1 not at all to 5 very much)" to "1 3 6 Likes Appels (scale 1 not at all to 5 very much)".
I've been toying around a lot, but have not seen any promising results yet.
Here is just a sample of how I tried to approach the problem.
Code:
Code:
foreach num of numlist 1(1)12 {
gen prefix = ""
foreach var of varlist w`num'_*{
capture confirm variable y`num'_*
if !_rc {
replace prefix = prefix + "`num'"
}
else {
local varlabel : var label `var'
local newlabel "`prefix' `varlabel'"
label var `var' "`newlabel'"
}
}
drop prefix
}
Best,
Fabian

Comment