I have a set of variables, the names of which have the same prefix attached to unique two-digit years:
div_unemp03
div_unemp04
.
.
.
div_unemp14
I would like to rename these variables to be as follows:
div_ue03
div_ue04
.
.
.
div_ue14
I attempted to carry this out using a foreach loop:
foreach x of var unemp* {
local new = substr(`x', 10, 2)
rename `x' div_ue`new'
}
However, Stata produces an error code:
type mismatch
Any help in understanding this error and how to achieve the desired effect would be appreciated!