Some context might be useful. One issue I often run into is that I want to edit a dofile while it is running. E.g. I code some stuff, run it, notice some things aren't as they should be and change it in the code. Unfortunately, I cannot save these changes until the current program is finished running or I press break. In most cases that's fine. However, sometimes this is very annoying, for example when manually parallelising the dofiles (e.g. the same dofile runs on different PCs, but using different data). Sometimes, I make changes that I think will improve it, but I am still interested in the results the old method will provide. If the old code causes Stata to hang, I will not be able to save these changes.
Of course, there are manual solutions to all these issues. For example, I could make a small alteration (one extra whitespace for example) to each dofile without saving. This would cause Stata to run a temporary file instead, allowing me to edit the original without issue. But I have to admit, I often forget and sometimes it's also inconvenient (because if you're as forgetful as I am, you might not remember whether the dofile was altered because you made a significant change or because you wanted to have it run as a temporary file).
One less manual solution I came up with is the following. Write a program that 1. reads in your entire dofile (the actual dofile would have to be saved I think, but perhaps this too can be avoided), 2. stores it as a tempfile, 3. executes the tempfile and 4.stops the current dofile.
Each step is manageable. 1-2 can be performed using a tempfile <tempname> and copy <location> <tempname>. 3. Can be done by calling Stata from the command line, from Stata (e.g. tell Stata to tell the commandline to run Stata). This would either open a new Stata window or write the output to a log file which could then be opened. 4. Is simply exit.
However, I have two substitutable unresolved issues. First, it would be much more convenient if you didn't need to specify the location of the dofile. Instead, I'm looking for a way to extract which dofile is currently executed. E.g. if you
I would love to extract "<dofileFolder>/dofileName.do" and use it to feed my copy command. In other words, is there a dofile equivalent to c(filename)?
Second, the current technique requires the dofile to be saved. It would be much safer if it could also execute unsaved dofiles. I have literally no idea how to do that, though.
Any ideas? I apologise if my description was a bit rambly, please do not hesitate the ask clarifying questions or better solutions than the one I propose.
PS: Another issue is to avoid recursiveness, (the code to call a tempfile should not be executed when the tempfile is called) but I think this can be solved in many different ways (though it might not be easy).
Of course, there are manual solutions to all these issues. For example, I could make a small alteration (one extra whitespace for example) to each dofile without saving. This would cause Stata to run a temporary file instead, allowing me to edit the original without issue. But I have to admit, I often forget and sometimes it's also inconvenient (because if you're as forgetful as I am, you might not remember whether the dofile was altered because you made a significant change or because you wanted to have it run as a temporary file).
One less manual solution I came up with is the following. Write a program that 1. reads in your entire dofile (the actual dofile would have to be saved I think, but perhaps this too can be avoided), 2. stores it as a tempfile, 3. executes the tempfile and 4.stops the current dofile.
Each step is manageable. 1-2 can be performed using a tempfile <tempname> and copy <location> <tempname>. 3. Can be done by calling Stata from the command line, from Stata (e.g. tell Stata to tell the commandline to run Stata). This would either open a new Stata window or write the output to a log file which could then be opened. 4. Is simply exit.
However, I have two substitutable unresolved issues. First, it would be much more convenient if you didn't need to specify the location of the dofile. Instead, I'm looking for a way to extract which dofile is currently executed. E.g. if you
Code:
do "<dofileFolder>/dofileName.do"
Second, the current technique requires the dofile to be saved. It would be much safer if it could also execute unsaved dofiles. I have literally no idea how to do that, though.
Any ideas? I apologise if my description was a bit rambly, please do not hesitate the ask clarifying questions or better solutions than the one I propose.
PS: Another issue is to avoid recursiveness, (the code to call a tempfile should not be executed when the tempfile is called) but I think this can be solved in many different ways (though it might not be easy).
Comment