Hi, I got a problem. I have a variable named CG_IDFULL. The researcher used 001002 denotes the second person within the first household.

My ultimate goal is to create a new variable which only contains the first three number: 001. Thus I can merge the 1st person in the 1st household data set.

I tried to use the code
Code:
generate CG_IDHH = substr(CG_IDFULL, 1, 3)
But Stata shows the error message: type mismatch

I think the reason is that current CG_IDFULL is numeric, not string. So I want to convert to string. I use
Code:
tostring CG_IDFULL, generate(CGID)
Stata shows the message: CGID generated as str5. I don't know what str5 mean. But the problem is that Stata shows 1002 in the new variable. I know the reason is that Stata think 001002 == 1002.

What should I do?