Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • getting rid of the E+ format when exporting Stata files to csv

    Dear Statalisters,

    I'm trying to export my datasets to csv but the ID variable (18 digits) kept changing to e.g. 1E+6. In the original stata file, this variable is a string variable. To be sure, I've formatted it using the command:
    format person_id %20s
    then export using the command:
    export delimited using "file.csv", datafmt replace
    But in the csv file the ID variable still appear as 1E+6. Can you please advise how I can get around this problem?

    Many thanks,

    Hai
    Last edited by Hai Nguyen; 25 Jul 2022, 05:01.

  • #2
    My guess is that if you were to open the CSV file in a text editor you would see that the ID variable in fact appears as 18 digits, and that the program you are importing the CSV file into is treating the ID variable as an 18-digit number, converting it to a numeric value, and displaying it with E format. You need to ensure that the values in the ID variable are surrounded by quotation marks so the program reading the CSV treats it as a string rather than a number.
    Code:
    export delimited using "file.csv", quote datafmt replace
    From the output of help export delimited we see

    quote specifies that string variables always be enclosed in double quotes. The default is to only double quote strings that contain spaces or the delimiter.

    Comment

    Working...
    X