Hi there,
I was wondering if anybody could help. I have 200+ columns that could change when new data is incorporated. I would like to rename the columns with the variable labels (unique for each column) however when I attempt to use the following I come across a syntax error due to the fact that some labels contain illegal characters:
foreach v of varlist del* {
**find out distinct value (level) of del variables
levelsof `v'
** store the values (from the results) into a string local tmp
local tmp `r(levels)'
** rename the keep variables by the string local tmp
rename `v' `tmp'
}
Is there a way to rename the variables within the loop but also automatically ignore illegal characters or shorten labels when required?
Kind Regards,
Hannah
I was wondering if anybody could help. I have 200+ columns that could change when new data is incorporated. I would like to rename the columns with the variable labels (unique for each column) however when I attempt to use the following I come across a syntax error due to the fact that some labels contain illegal characters:
foreach v of varlist del* {
**find out distinct value (level) of del variables
levelsof `v'
** store the values (from the results) into a string local tmp
local tmp `r(levels)'
** rename the keep variables by the string local tmp
rename `v' `tmp'
}
Is there a way to rename the variables within the loop but also automatically ignore illegal characters or shorten labels when required?
Kind Regards,
Hannah
Comment