Announcement

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

  • Accidentally saved as txt file

    Hello
    I imported a txt file and then accidentally overwrote it as a txt file. I did not change any of the file’s contents, but the save command has resulted in an apparently corrupt txt file full of ‘gibberish’ characters.

    Here's my code:

    import delim using “C:\myfolder\myfile.txt”, delim(“|”)
    save “C:\myfolder\myfile.txt”, replace

    Is there any chance of restoring the original content, which presumably is still in there somewhere amongst all the gibberish characters?

    Any advice greatly appreciated

    With thanks

  • #2
    Problem solved!
    I was trying to open the new txt file using ‘import delim’ instead of ‘use’.
    Last edited by tim bradshaw; 22 Aug 2019, 08:17.

    Comment


    • #3
      The -save- command saves the data as a Stata data set even if you specify .txt as the extension. You need to use -export delimited-. Here's an example:

      Code:
      /* txt file contains:  
      v1|v2|v3|v4|v5|v6
      1|2|3|a|b|c
      */
      
      clear *
      import delim using "C:\temp\junk.txt", delim("|")
      save "C:\Temp\myfile.txt", replace
      
      use "C:\Temp\myfile.txt"
      export delimited using "C:\Temp\MyFile2.txt", delimiter("|") replace
      list
      Here is the output from the final -list- command:

      Code:
      . list
      
           +-----------------------------+
           | v1   v2   v3   v4   v5   v6 |
           |-----------------------------|
        1. |  1    2    3    a    b    c |
           +-----------------------------+
      Last edited by Bruce Weaver; 22 Aug 2019, 08:31. Reason: Crossed with #2
      --
      Bruce Weaver
      Email: [email protected]
      Version: Stata/MP 18.5 (Windows)

      Comment

      Working...
      X