Hi everyone,
I am trying to truncate an identifier variable in my data (string variable). The identifier is made of 16 digits.
For example: 0104038003105701
I want to keep only the first 14 digits, i.e, I would like to transform the above identifier into 01040380031057
I have used many time the real(substr) command but for some reason stata here returns me a variable full of missing observations.
I am running:
gen int hhid2 = real(substr(hhid,1,14)) where hhid is my original identifier.
It works with lower numbers, for example: gen int hhid2 = real(substr(hhid,1,3)) would work.
Another problem is that for identifiers starting with 0 as in the example above, the 0 gets ommited. So for the identifier 0104038003105701 , the command real(substr(hhid,1,3)) would only return 10 , and not 010 as I want
Many thanks for your help,
Regards
Basile
I am trying to truncate an identifier variable in my data (string variable). The identifier is made of 16 digits.
For example: 0104038003105701
I want to keep only the first 14 digits, i.e, I would like to transform the above identifier into 01040380031057
I have used many time the real(substr) command but for some reason stata here returns me a variable full of missing observations.
I am running:
gen int hhid2 = real(substr(hhid,1,14)) where hhid is my original identifier.
It works with lower numbers, for example: gen int hhid2 = real(substr(hhid,1,3)) would work.
Another problem is that for identifiers starting with 0 as in the example above, the 0 gets ommited. So for the identifier 0104038003105701 , the command real(substr(hhid,1,3)) would only return 10 , and not 010 as I want
Many thanks for your help,
Regards
Basile
Comment