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
Related Posts with Renaming columns
Converting Composite Categorical Variables to Binary VariablesHi all, I'm new to Stata and am running into trouble with setting up a dataset for use. The issue …
Facing problem in generating IDDear Statalist, I am facing kind of strange problem in my STATA. For my research I am using Nationa…
Creating a table with percentilesHi, I am very new to Stata and I would like to create a table for 3 variables displaying certain per…
Omiited due to collinearityHello guys, I regressed my model through multiple linear regression. However, Stata omitted two ind…
Correlation between two variables for every time unitHello everyone, I am completely new to Stata and I am trying to run an analysis for my dissertation.…
Subscribe to:
Post Comments (Atom)
0 Response to Renaming columns
Post a Comment