Hello,
I am using Stata 11 and have a set of variables that use underscores, see list below:
_401
_402
_402_1
_402_2
_403
_403a
_403b
I would like to rename the variables so that underscores are removed and replaced with an 's' in front of the variables, as shown below:
s401
s402
s402_1
s402_2
s403
s403a
s403b
Is there any way to rename this set of variables at once instead of renaming them one by one? This is what I have tried so far:
foreach v of varlist _401 _402 _402_1 _402_2 _403 _403a _403b {
2. rename `v' s`v'
3. }
and
foreach v of varlist _401 _402 _402_1 _402_2 _403 _403a _403b {
2. local V: subinstr local v "_" "", all
3. rename `v' s`v'
4. }
In both cases Stata just added the 's' in front of the '_' (i.e. s_401) and I want to remove the '_' and add the 's'.
Thank you!
Carr
I am using Stata 11 and have a set of variables that use underscores, see list below:
_401
_402
_402_1
_402_2
_403
_403a
_403b
I would like to rename the variables so that underscores are removed and replaced with an 's' in front of the variables, as shown below:
s401
s402
s402_1
s402_2
s403
s403a
s403b
Is there any way to rename this set of variables at once instead of renaming them one by one? This is what I have tried so far:
foreach v of varlist _401 _402 _402_1 _402_2 _403 _403a _403b {
2. rename `v' s`v'
3. }
and
foreach v of varlist _401 _402 _402_1 _402_2 _403 _403a _403b {
2. local V: subinstr local v "_" "", all
3. rename `v' s`v'
4. }
In both cases Stata just added the 's' in front of the '_' (i.e. s_401) and I want to remove the '_' and add the 's'.
Thank you!
Carr
Comment