I would like to replace and retain the original variable name after using the encode command for a set of variables x1-xn. This is where I've started:
for var x*: encode x*, generate(x*_) label(label)
My question is: what is a clean way to drop the x* (original string) variables?
When I figure that out, I can execute this command to rename x*_ (the new encoded variable):
rename x*_ x*
foris not documented in any recent version of Stata. I don't have access at the moment to the documentation for Stata 6 that would be needed to answer how to do it usingfor, but if you are using Stata 7 or later you should switch toforeach. If you are using an earlier version, you should say what it is. If you were presenting pseudocode, you should have explained that. Whatever the truth is, this question is inadequately explained. My recollection is that yourforstatement is a long way from legal. - Nick Coxforcommand in this version and it worked, so I did not realize that it was not appropriate. Could you please clarify what you meant by the pseudocode and legal comments? - Traciforwasn't appropriate; I said it was not documented, so you rely entirely on some code being remembered from a previous successful use. Clearly you haven't tried looking for the help forfor, as you would have found that it doesn't exist. As I said, my recollection is that your code isn't legal, meaning would not work because of a syntax error. - Nick Cox