Differences between revisions 2 and 3
Revision 2 as of 2023-06-08 00:29:12
Size: 1500
Comment:
Revision 3 as of 2023-06-08 01:14:05
Size: 1603
Comment:
Deletions are marked like this. Additions are marked like this.
Line 66: Line 66:
----



== See also ==

[[https://www.stata.com/manuals/drename.pdf|Stata manual for rename]]

Stata Rename

The rename command 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


Stata 12 Extensions

As noted above, various extensions were added to the rename command 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 2023-06-08 01:14:05 by DominicRicottone)