Differences between revisions 1 and 4 (spanning 3 versions)
Revision 1 as of 2023-01-14 20:10:09
Size: 1409
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 2: Line 2:

'''`-rename-`''' renames an existing variable.
Line 11: Line 13:
To rename a variable, try:
Line 15: Line 15:
}}}

To rename multiple variables simultaneously, try:

{{{
rename (VAR1 VAR2) (VAR2 VAR1)
rename (OLDVAR1 OLDVAR2) (NEWVAR2 NEWVAR1)
Line 42: Line 37:
Prior to then, these functions were filled by other commands:

=== Backwards Compatibility ===

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



== See also ==

[[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)