Hey,
I have a dataset with many lengthy variable names but which are useful for identification. What I would like to do is the following:
Loop through the variables.
1. Store the name of the variable to a local
2. rename the variable as var1
3. give the renamed variable the label of the old variable
What I have been struggling is that when using foreach var of varlist and then looping through, it goes through the values.
I would like to store the name of the variable. I have looked at past posts and the help manual but have not been able to find anything regarding this.
Pseudocode as answer would be appreciated. Thank you in advance.
I have a dataset with many lengthy variable names but which are useful for identification. What I would like to do is the following:
Loop through the variables.
1. Store the name of the variable to a local
2. rename the variable as var1
3. give the renamed variable the label of the old variable
What I have been struggling is that when using foreach var of varlist and then looping through, it goes through the values.
I would like to store the name of the variable. I have looked at past posts and the help manual but have not been able to find anything regarding this.
Pseudocode as answer would be appreciated. Thank you in advance.
Code:
scalar temp= 1 foreach var of varlist _all { //save variable name to local ( say i e.g.) rename `var' var`temp' label var`temp' `i' scalar temp= `temp' + 1
Comment