I apologize in advance for this question. I'm currently using Stata 15.1.
Let's say you have the following dataset:
I would like to come up with code that will do the following renames:
Obviously, if I only had those three variables I could just do it by hand. But I have about 15 datasets like this, ranging from about 50 to 250 "var" variables. While the "var" variables always go in sequential order, the respondent_id variable has gaps that don't follow any known rule.
I suspect there is some way to map the "var" variables onto the values of "respondent_id", either using a loop with rename or with renvars, but I have no idea where to begin. Does anyone have resources or ideas of code that would do this?
Let's say you have the following dataset:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str7 respondent_id byte(var1 var2 var3) "_0001" 0 0 0 "_0005" 0 0 1 "_0007" 0 0 0 end
Code:
rename var1 var_0001 rename var2 var_0005 rename var3 var_0007
I suspect there is some way to map the "var" variables onto the values of "respondent_id", either using a loop with rename or with renvars, but I have no idea where to begin. Does anyone have resources or ideas of code that would do this?
Comment