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

From |
"Victor, Jennifer Nicoll" <jnvictor@pitt.edu> |

To |
"'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu> |

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: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox Sent: Friday, June 05, 2009 10:13 AM To: statalist@hsphsun2.harvard.edu 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 n.j.cox@durham.ac.uk 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/

**References**:**st: Rename variables to reflect values?***From:*"Victor, Jennifer Nicoll" <jnvictor@pitt.edu>

**RE: st: Rename variables to reflect values?***From:*Roy Wada <roywada@hotmail.com>

**RE: st: Rename variables to reflect values?***From:*"Victor, Jennifer Nicoll" <jnvictor@pitt.edu>

**RE: st: Rename variables to reflect values?***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

- Prev by Date:
**Re: st: creating a numeric matrix from string variables** - Next by Date:
**st: symmetrically trimmed least squares** - Previous by thread:
**RE: st: Rename variables to reflect values?** - Next by thread:
**RE: st: Rename variables to reflect values?** - Index(es):

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