Stata Rename


Usage

To rename a variable, try:

rename OLDVAR NEWVAR

To rename multiple variables simultaneously, try:

rename (VAR1 VAR2) (VAR2 VAR1)

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

Prior to then, these functions were filled by other commands:

// 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


CategoryRicottone