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

RE: st: loop to rename vars

From   "Nick Cox" <>
To   <>
Subject   RE: st: loop to rename vars
Date   Sun, 12 Oct 2008 16:50:55 +0100

I flagged that I was referring to -renvars- from the Stata Journal and
recommended using -search- for locations. Kit Baum also underlined that
the command is to be found in the Stata Journal files. 

Sergiy evidently did not follow that advice. Suppose you did: 

. search renvars 

Keyword search

        Keywords:  renvars
          Search:  (1) Official help files, FAQs, Examples, SJs, and

Search of official help files, FAQs, Examples, SJs, and STBs

SJ-5-4  dm88_1  . . . . . . . . . . . . . . . . .  Software update for
        (help renvars if installed) . . . . . . . . .  N. J. Cox and J.
        Q4/05   SJ 5(4):607
        trimend() option added and help file updated

STB-60  dm88  . . . . . . . .  Renaming variables, multiply and
        (help renvars if installed) . . . . . . . . .  N. J. Cox and J.
        3/01    pp.4--6; STB Reprints Vol 10, pp.41--44
        renames variables by changing prefixes, postfixes, substrings,
        or as specified by a user supplied rule

That is, the latest version of -renvars- may be downloaded from the
files for SJ 5(4). 

Why did Sergiy get his results? As he indicates clearly, for some reason
he is using this earlier version: 

renvars from
    renvars.  Powerful command to rename variables. / renvars renames
    variables in a varlist by any of a number of / functions, case
    pre- and postfixing of strings, and / substitutions within variable
    / Author:  Jeroen Weesie, Dept of Sociology, Utrecht University (NL)

There are various good reasons why you might use that version: 

1. You are still using Stata 6. The 2001 version requires Stata 7. The
2005 version requires 8. 

2. You downloaded the version from Jeroen's site some while ago and it
is fine for your purposes. 

3. You don't like later versions. 

But that's as may be. My examples didn't work with Sergiy's version
because the syntax has changed.  Again, I did recommend the Stata
Journal version, and neglected to explain the complete history of
-renvars- and its predecessors, which isn't very interesting. 

I note his "preferred strategy" with interest. Incidentally, wiring -ds-
into a program is inefficient. As I've already indicated in this thread,
you can go straight to a full list of variables using * or _all. -ds-
just adds interpretative overhead; it is useful for other problems, and
I use it myself, and am one of its authors, but it's not the best route
to follow here. 

I believe that the code Jeroen Weesie and I published in 2001 and 2005
avoids most of the obvious pitfalls with renaming. If Sergiy can find
any bugs or inconsistencies in the 2005 version, he should naturally let
us know. 

Sergiy Radyakin

Does not seem to work:

sysuse auto
renvars \ var1-var`c(k)'
\ invalid name

renvars var1-var`c(k)'

renvars * var1-var`c(k)'
variable var1 not found

which renvars
*! 2.2.1  15aug2000  Jeroen Weesie/ICS

version 9.2

Perhaps I am doing something wrong?? Is slash required? Did you mean
-renamev- ?

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