Hey everyone,

I have a string variable 'p2' that consists of ID codes formatted as follows "BBSC0123" "BBSC01010", I am trying to remove the 0 directly following the letters, but not remove any 0 that might be in the last 4 digits of the code?

I am relatively new to stata and have tried:

. gen p4 = substr(p2, 6, 4)

and

. gen p4 = substr(p2, 1, 4)

(only want to keep the 1-4 and 6-9 digits?) But can't workout how to do one that keeps either side of the 0