Hello,
I have a string variable, let's called it "string". Sometimes it has 10 digits, and some times 9. I would like to obtain create a new variable which takes the first 8 digit if it has 10 digits, and to takes the first 7 digit if it has 9 digit.
I know how to do it considering just one part:
However, I have not found the way of doing both parts at the same time. Any ideas?
I have a string variable, let's called it "string". Sometimes it has 10 digits, and some times 9. I would like to obtain create a new variable which takes the first 8 digit if it has 10 digits, and to takes the first 7 digit if it has 9 digit.
I know how to do it considering just one part:
Code:
gen wanted = substr(string, 1, 8)
Comment