Your use of the delimiter ; here does not bite, so I will ignore it.
The error is in the use of subinstr(), which must have four arguments, the fourth being the number of substitutions to be made. See help subinstr().
This works (note please the use of a minimal complete verifiable example):
clear
set obs 1
generate intensity1 = 1
generate intensity2 = 2
foreach VAR of varlist intensity* {
local NEW = subinstr("`VAR'", "intensity", "int", 1)
rename `VAR' `NEW'
}
ds
But the loop is utterly unnecessary. First, let's flip the names back and then show how to change names directly:
rename int* intensity*
rename intensity* int*
See help rename groups for more.
tracefeature is (often) a helpful command for debugging. Seehelp trace. - Brendan