Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: st: Rename variables to reflect values?


From   "Victor, Jennifer Nicoll" <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   RE: st: Rename variables to reflect values?
Date   Fri, 5 Jun 2009 10:19:26 -0400

I found my typo/mistake.  Thanks for your help Roy and Nick.  This works great.

-Jennifer

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Nick Cox
Sent: Friday, June 05, 2009 10:13 AM
To: [email protected]
Subject: RE: st: Rename variables to reflect values?

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/

*
*   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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index