I am attempting to use Stata to manipulate Excel workbooks, with import (and export) excel. Importing changes the values of numbers (even though they are read in as strings since there are other non-numeric characters in the same row). For example, 0.814 in Excel becomes .8139999999999999 in Stata. I need the numbers to stay exactly as they appear in Excel, since the data later directly become tables in a publication via texsave. (Perhaps not the greatest workflow, but that's what I'm stuck with.)
I assume this has to do with machine precision, but I thought the format would be preserved since it reads the numbers as strings anyway. The 'allstring' option doesn't help since they're already strings, and 'keepcellformat' is only for exporting. (Maybe I'll have to use that when exporting though.) If there is no way to enforce it in Stata I'd be curious if there are things I could do in Excel (formatting cells as text didn't seem to work.)
A small excel file is attached.
A code example would just be something like:
I assume this has to do with machine precision, but I thought the format would be preserved since it reads the numbers as strings anyway. The 'allstring' option doesn't help since they're already strings, and 'keepcellformat' is only for exporting. (Maybe I'll have to use that when exporting though.) If there is no way to enforce it in Stata I'd be curious if there are things I could do in Excel (formatting cells as text didn't seem to work.)
A small excel file is attached.
A code example would just be something like:
Code:
clear all import excel using ./Test.xlsx, clear //preferably with an option to keep exact formatting *Do other unrelated things export excel using ./Testoutput.xlsx, replace keepcellfmt
Comment