Announcement

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

  • preserve and restore on mac

    Hi. I was trying to use preserve and restore command.

    Here are the codes:
    • preserve
    • drop BYINCOME BYSEX
    • restore

    It works fine if I run all 3 lines at once.

    However, if I run them separately, this is what happened.
    Clearly the variables BYINCOME BYSEX were dropped after I ran the first 2 lines, then
    after I ran the 3rd line "restore", I get this message:

    "nothing to restore
    r(622); t=0.02 14:27:09"

    I am not sure why. I am using a mac running El Capitan if that helps. Thank you in advance.

  • #2
    I think you are working from a do-file and running these commands from a do-editor.

    When you run one or more commands by themselves in the do-file editor, Stata treats that as a separate session. At the end of such a session, any local macros that were created in the session go out of scope, and any -preserve-d data is automatically -restore-d.

    So when you run all three commands as a single session, they behave as you would expect. But when you run -preserve- as a session by itself, it -preserve-s the data and then immediately -restore-s it! That's why there's nothing to restore when you then run the third line.

    Comment

    Working...
    X