Announcement

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

  • Pystata - unloading a previously loaded do-file

    We are developing a program in Python that has embedded Stata commands. The structure of the program is as follows:

    <python commands>

    stata.run("do dataprep.do")

    <more python commands>

    stata.run("stata command")

    <python commands>

    The program is run using the standard IPython "%run program.py" command and works fine the first time it executes. However, if you re-run the program it fails at the stata.run command with the "do dataprep.do" instruction to Stata. The reason is that the do-file is already loaded. I tried using stata.run("clear all") before loading the do-file but that doesn't help. I can stop the program failing by rewriting the command as stata.run("capture do dataprep.do") but that doesn't help much because while capture traps the error message the do-file is not executed.

    Hence, what I need is a way of unloading all loaded do-files from pystata. So far the only way I have found of doing that is literally to reboot my machine (this is under Windows). Restarting IPython doesn't achieve this goal.

    What am I missing? Does anyone have any suggestions on how to do this?
Working...
X