Differences between revisions 3 and 4
Revision 3 as of 2023-06-08 01:14:05
Size: 1603
Comment:
Revision 4 as of 2025-10-24 17:34:56
Size: 1583
Comment: Rewrite
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
The '''`rename`''' command renames an existing variable. '''`-rename-`''' renames an existing variable.
Line 37: Line 37:
----
Line 40: Line 39:
=== Backwards Compatibility ===
Line 41: Line 41:
== Stata 12 Extensions ==

As noted above, various extensions were added to the `rename` command in Stata 12. Consider the following for backwards compatibility:
As noted above, various extensions were added to `-rename-` in Stata 12. Consider the following for backwards compatibility:
Line 72: Line 70:
[[https://www.stata.com/manuals/drename.pdf|Stata manual for rename]] [[https://www.stata.com/manuals/drename.pdf|Stata manual for -rename-]]

Stata Rename

-rename- renames an existing variable.


Usage

rename OLDVAR NEWVAR
rename (OLDVAR1 OLDVAR2) (NEWVAR2 NEWVAR1)

Stata 12+ supports additional functions:

// rename all variables with a leading 'q' such that the 'q' is replaced with a 'Q'
rename q* Q*

// rename all variables with a trailing '_r' such that the '_r' is replaced with a '_R'
rename *_r *_R

// add a prefix to all variable names
rename * orig_*

// strip a suffix from all variable names
rename *_checked *

// rename all variables to a lowercase name
rename *, lower

Backwards Compatibility

As noted above, various extensions were added to -rename- in Stata 12. Consider the following for backwards compatibility:

// rename all variables with a leading 'q' such that the 'q' is replaced with a 'Q'
renpfix q Q

// rename all variables with a trailing '_r' such that the '_r' is replaced with a '_R'
search rensfix //STB59: needs to be manually installed
rensfix _r _R

// add a prefix to all variable names
search renvars //STB60: needs to be manually installed
renvars *, prefix(orig_)

// strip a suffix from all variable names
search rensfix //STB59: needs to be manually installed
rensfix _checked

// rename all variables to a lowercase name
search renvars //STB60: needs to be manually installed
renvars *, lower


See also

Stata manual for -rename-


CategoryRicottone

Stata/Rename (last edited 2025-10-24 17:34:56 by DominicRicottone)