Announcement

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

  • preserve / restore through a do file

    Hello,

    it seems as if the commands preserve and restore don't function properly when they're executed via do file. If to be more precise, they do work well when they are run together on the same execution. Yet, if I already have a full script over which I want to go through by executing it line by line, then the problem occurs: The "preserve" is being executed normally, but then when I hit "restore", Stata replies an error that "there is nothing to restore".

    Is it a known issue? Any way to overcome it?

    Thank you in advance,
    Ben

  • #2
    Hello Ben, I think some do file codes are doomed to be run in block rather than line by line. If you don't need to preserve the data, you can just delete -preserve restore- to avoid error message.
    2B or not 2B, that's a question!

    Comment


    • #3
      As a footnote to the advice from Liu Qiang, the output of help preserve tells us that preserve and restore are functioning properly as they are designed to do.

      preserve and restore deal with the programming problem where the user's data must be changed to achieve the desired result but, when the program concludes, the programmer wishes to undo the damage done to the data. When preserve is issued, the user's data are preserved. The data in memory remain unchanged. When the program or do-file concludes, the user's data are automatically restored.
      You can think of preserve and restore as functioning like local macros, limiting the effects of the code to the program or do-file in which they appear.

      Comment


      • #4
        Sometimes -snapshot- is a helpful alternative. I don't often see it mentioned or used here, but it's like a less-automatic version of -preserve-, in which the user deliberately saves the file at a certain point and deliberately restores it at a later point.

        Comment

        Working...
        X