0
votes

Have run into a problem with using a .bat file to run Stata automatically at 6AM every day.

The .bat file is simply:

Start /W "" "C:\Program Files (x86)\Stata13\StataMP-64.exe" do "C:\Users\Daniel\Documents\Reportes\Reportes v3.do" 

The do file this calls, "Reportes v3.do", contains a series of global directories, then runs four tasks housed in other do files:

cd "C:\Users\Daniel\Documents\Reportes\Do files v3"
do "Task 1.do", nostop
do "Task 2.do", nostop

etc.

Run manually, the .bat file works fine. The problem is when I add it as a task in Task Scheduler, the do file gets hung up on certain estimation commands. So far, I've had this problem with Stata's -alpha- and -xtreg- commands.

Specifically, Task Manager shows Stata is still running and has the data loaded in memory, but the log files don't show further output and databases don't update. Similarly, Stata won't let me make any changes to either the do file called directly by the .bat file, or the do files called from within the first do file. If I remove these specific estimation commands, everything runs fine.

Also the Stata window does not show up, I imagine because it is being run as a background task. Another difference is that when run manually from the Task Scheduler, the .bat file displays as Running while the do file is running, but when run automatically, it doesn't.

Adding -/HIGH- after -Start- doesn't fix the problem. Neither does disabling antivirus or creating four .bat files to run each task separately. Adding a log at the end of the .bat file doesn't reveal anything either.

This is my first experience working in batch mode, so any help is much appreciated.

1

1 Answers

0
votes

Finally found an answer to this question that might be of interest to other users.

For reasons I don't quite understand, the task needs to be set to run only if the user has started a session AND with the administrator privileges box unchecked. Otherwise, apparently Windows runs the task in a separate session, and something about this causes the problems I mentioned.

If anyone has a good explanation for why this happens, please share. But at least this solved the problem.