Announcement

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

  • Any way to recover a .do file after a crash?

    Stata crashed in the midst of a loop and I'm wondering if there is any way to recover the do file I had written. This would be a good feature--at least for me as I seem to have a talent for crashing Stata and don't always remember to save before hitting run.

  • #2
    You can prevent loosing the last version of a do-file in your do-file editor by changing the preferences (advanced) of the do-file editor to always save the .do-file before do/run. If Stata crashed and you did not save your do-file you may be lucky to find the part of the do-file you wanted to execute in the temp-folder of your operating system, see https://www.stata.com/statalist/arch.../msg00491.html .
    Last edited by Dirk Enzmann; 18 May 2021, 07:45.

    Comment


    • #3
      I'd add that if Stata frequently crashes for you, something is wrong with your installation or in how you are using it. Stata has crashed on me only a few times in the last 20 years. The next time you have a crash, you might want to post here with the details and see if someone can help with a diagnosis.

      Comment


      • #4
        Stata frequently crashes for me, but merely because my laptop frequently shuts itself down, crashing all programmes open at the time, and only reopens by rebooting.
        I am very interested in Dirk's pointers, thank you so much!
        I just discovered logs and they saved me from having lost my dofile with all of yesterday's work at the last crash - I just opened the log file and had all the work there to review (if in a laborious manner!) So my opening routine now involves:

        Code:
        cd "C:\Users\XXXXXXX\OneDrive - XXX\XXXXXX"
        capture log close  
        log using 2021.05.18_Stata_Today, replace text 
        use "C:\Users\XXXXXXX\OneDrive - XXX\XXXXXX\2021.05.17 Complete dataset.dta", clear
        save "C:\Users\XXXXXXX\OneDrive - XXX\XXXXXX\2021.05.18 Complete dataset.dta"
        *********************************
        **Then my CLOSEDOWN involves SAVE dta above again, SAVE all do-files**
        *********************************
        log close



        Comment


        • #5
          Note that you also can write the commands you entered into the command-window into a .log-file by including the following into your profile.do (located in the folder ado/personal/ ).

          Using Linux:
          Code:
          // Write session start time in time.txt
          set obs 1
          gen time="******* Session started `c(current_date)' `c(current_time)'"
          outfile time using "~/stata/time.txt", noquote replace           // adapt the path to your needs
          clear
          
          // Copy session start time to the cmdlog (cmdlog.txt) and open it
          // ! means that Linux command follows
          ! cat ~/stata/cmdlog.txt ~/stata/time.txt >> ~/stata/cmdlog.txt  // adapt the path to your needs
          cmdlog using ~/stata/cmdlog.txt, append                          // adapt the path to your needs
          
          // Open the log (stata.log)
          set logtype text
          log using ~/stata/stata.log, replace                             // adapt the path to your needs
          Using Windows:
          Code:
          // Write session start time in time.txt
          set obs 1
          gen time="******* Session started: `c(current_date)'  `c(current_time)'"
          outfile time using d:\stata\time.txt, noquote replace                     // adapt the path to your needs
          clear
          
          // Copy session start time to the cmdlog (cmdlog.txt) and open it.
          // ! means that a DOS command follows.
          ! copy /b d:\stata\cmdlog.txt + d:\stata\time.txt d:\stata\cmdlog.txt /y  // adapt the path to your needs
          cmdlog using d:\stata\cmdlog.txt, append                                  // adapt the path to your needs
          
          // Open the log (stata.log)
          set logtype text
          log using d:\stata\stata.log , replace                                    // adapt the path to your needs

          Comment

          Working...
          X