I have observations which list criminal codes as string variables, but not in the format I need. Using Stata 12, I want to replace some substrings in a string variable. For example, I need to change all instances of CC to 18, VC to 75, and PC to 35. Like so:
Orginal Variable
CC547A1 | VC549F| PC5297
New Variable
18547A1 | 75549F | 355297
The characters I need to change are always in the beginning. Some original variables do not need to be changed.
I tried figuring this out using the substring command, but I just couldn't adapt the code correctly.