Without seeing exactly what you typed, further comment is difficult.
But
1. I confirm that Roy's code is legal and correct.
2. I suggest that you check that all left and right quotes are present.
Stata learners often don't notice that the left quote character is being
used to open macro references. It may be one that you don't use very
often, especially if you delegate to your word or text processor the
task of working out which quotation marks to use. I can't see your
keyboard, but on mine it is near the Tab key and some distance from most
punctuation keys. This point is explained in [U] when local macros are
introduced.
3. This code will only work for alphabetic a-z and integer characters.
If the first value of a variable contains a decimal point, it won't work
because they are not allowed in variable names.
Nick
[email protected]
Victor, Jennifer Nicoll
Roy, thanks for the suggestion. However, I get a syntax error when I
tried the procedure you suggested. I thought I understood your logic,
but I am not able to produce a renaming without an error.
Roy Wada
sysuse auto, clear
drop make headroom gear_ratio
foreach var of varlist _all {
ren `var' `var'`=`var'[1]'
}
Victor, Jennifer Nicoll
> Does anyone have a suggestion for how I could rename my variables to
> reflect the values in an observation or a variable? Or any other
> suggested shortcuts, short of making this long local macro?
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/