Announcement

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

  • How to recover do file from a crush?

    Hi, Everyone! Thanks in advance in willing to chime in and help!

    I have been working on a project in the past two weeks that is due on Monday. Today, in the very last step to close the project. I saved my do file saved as dta accidentally. The whole package of code was rewritten into nonesense. Unfortunately, I didn't have a 'log' file. (Yes, I learned it in the hard way).

    I used this syntax:

    save "file.do", replace


    Then my do file was completely rewritten into a bunch of nonsense.

    I operated it with Stata 18 on Mac OS.

    On the macbook end, I didn't set up 'Time Machine'.

    It would be greatly appreciated if you can provide any constructive help.

    Thank you very much.
    Last edited by Zeming Lu; 29 Nov 2025, 17:10.

  • #2
    The package of code was not "rewritten into nonsense." What Stata actually did is save the data set active in memory at the time under the name "file.do." If you change the name of that file to "file.dta" and -use- it, you will see that you get back the data you had in memory at the time you did this. Perhaps that will prove helpful. It won't contain the code, but at least the resulting data set is still there and you might be able to move forward from that.

    The only way I can see to get your do-file back is if version 18 had the autosave feature in the do-file editor, and you didn't turn it off. I know it's in version 19, and not in version 17, but I don't know about 18. If you had it, then there might be a "file.stwp" in your working directory that contains the contents of the do-file as of whenever the last autosave was done. You can open it in the do-file editor. Otherwise, I think you are just out of luck.

    Don't feel too bad about having done this. I think nearly everybody who uses any kind of programming system has at some point, usually fairly early in their career, mistakenly done something that irreversibly deleted or irredeemably corrupted a program file or a data set. That's how we learn to work more cautiously and avail ourselves of the various safety features our applications make available. The long term benefits of learning that lesson will almost surely outweigh the value of the lost do-file, as I doubt you will ever make this kind of mistake again, and I predict you will become meticulous about maintaining backups and log files.

    Comment

    Working...
    X