Hi everybody,
I've spent hours trying to fix a problem that may be simple: when I append some datasets, variables that have been encoded turn into a 3-digit observation. To be precise:
My dataset contains - among others - two variables that would be numerical, but are strings because of stuff like "#NI#". Once I need it as numerical, I used "encode", which worked well [Stata didn't allow "destring"]. However, the new vars present leading zeros, and they seem to be an issue when I append the datasets: only when there are leading zeros the observations become a 3-digit number.
Here is the script:
encode v28, gen (v28_n)
encode v14, gen (v14_n)
rename v28 v28str
rename v14 v14str
rename v28_n v28
rename v14_n v14
drop v14str
drop v28str
recast double v28
recast double v14
How can I remove the leading zeros or avoid the 3-digit problem when I append the datasets?
Thank you!
I've spent hours trying to fix a problem that may be simple: when I append some datasets, variables that have been encoded turn into a 3-digit observation. To be precise:
My dataset contains - among others - two variables that would be numerical, but are strings because of stuff like "#NI#". Once I need it as numerical, I used "encode", which worked well [Stata didn't allow "destring"]. However, the new vars present leading zeros, and they seem to be an issue when I append the datasets: only when there are leading zeros the observations become a 3-digit number.
Here is the script:
encode v28, gen (v28_n)
encode v14, gen (v14_n)
rename v28 v28str
rename v14 v14str
rename v28_n v28
rename v14_n v14
drop v14str
drop v28str
recast double v28
recast double v14
How can I remove the leading zeros or avoid the 3-digit problem when I append the datasets?
Thank you!
Comment