Announcement

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

  • Never allow Stata to replace dataset

    I have ingrained in my muscle memory to press "ctrl+s" every time before I run a .do file in case Stata crashes. Once in a while I write code directly into the Stata command field, especially when I tabulate or summarise variables I just created to quality check them. I have thus accidently managed to press "ctrl+s" while in this window accidentaly, and followingly press enter with the intent to execute the command I wrote into the command window. This of course, replaces the data set I am working on, which I extremely seldomly want to do, and especially not outside of a .do file.

    Is there a way to never allow Stata to overwrite a specific file? In the .do file I use the "replace" option to force Stata to overwrite, but I could not find any options to "lock" the data set. I couldn't find an option anywhere to dissalow the "ctrl+s" on saving data sets. I wanted to ask if there is some information I am missing?

  • #2
    I'm a bit mystified that you are having this problem. For my part, I almost never use ctrl-S to save, so perhaps there are subtleties to its use that I'm unfamiliar with. But when I try ctrl-S with data in memory that has changed, a window pops up asking me whether I want to replace the existing file. So you can, at that point "just say no." But here's a back-up for that: in your operating system, set a read-only property on the data file before you use it. (In Windows, right click on the file's icon, select properties, and click the box next to read only. I don't know how it works in Mac or Linus but I'm sure it's pretty straightforward.) Then even if you try to -save, replace- or respond Yes to wanting to save this file, you won't be able to because the operating system will refuse to modify it.

    Comment


    • #3
      Clyde's recommendation about setting the read-only flag is the only fool-proof way to do it (assuming you don't forget).

      The only way I can think of that mimics this idea in Stata would be to load the dataset into a frame, copy that frame to a "working" frame, drop the original and use the "working" frame for analysis. Or, copy the dataset on disk and load that copy. Both of these are pretty cumbersome for all but the smallest datasets.

      Comment


      • #4
        When selecting File > Save or its keyboard shortcut to save a file, a dialog is presented prompting the user if they're sure they want to replace the existing file. Stata for Mac and Stata for Unix have an additional feature where there's a checkbox in that dialog to not show the dialog in the future and to simply replace the file. Stata for Windows will be getting this feature in a future update. Karl must be a Stata for Linux user because he uses ctrl-s for the keyboard shortcut and it's command-s on the Mac.

        If you want to be prompted to replace the file again, open the preferences dialog and uncheck the checkbox for Replace existing file when saving.
        Last edited by Chinh Nguyen (StataCorp); 31 Mar 2020, 12:18.
        -Chinh Nguyen

        Comment

        Working...
        X