Hi,
I'm interested in renaming variables using values from the first observations. The problem with the particular data set I'm currently working on is that in certain cases the strtoname() will evaluate to already existing variable. The problem may be illustrated with the code below:
What I would like to achieve is to accommodate for that possible and when needed attach some prefix or suffix to the variable. I was thinking of adding some counter but I will be grateful for suggestions how this can be neatly addressed? Bonus question, can I save original observation value as a note via something like:
I'm interested in renaming variables using values from the first observations. The problem with the particular data set I'm currently working on is that in certain cases the strtoname() will evaluate to already existing variable. The problem may be illustrated with the code below:
Code:
// Create data set clear input str20 A str20 B "This is my desired name" "This is my desired name" "9098" "8676878" end // Rename foreach nvar of varlist A - B { rename `nvar' `=strtoname(`nvar'[1])' }
Code:
notes `nvar' : Original text `nvar'[1]
Comment