1
votes

Nice

I use Windows batch files to execute various Stata do-files in a certain order. For example, when I do

StataMP-64 /e do myDoFile1.do
StataMP-64 /e do myDoFile2.do 

Stata executes myDoFile1.do and nicely routes its output to myDoFile1.log, and then executes myDoFile2.do and routes its output to myDoFile2.log. By the way, both log files are in the same directory as the do-files.

Not nice

Now I want to pass an argument for each of these do-file. In particular, this argument is a directory path. For example,

StataMP-64 /e do myDoFile1.do "C:\MyDir"
StataMP-64 /e do myDoFile2.do "C:\MyDir" 

Now Stata executes myDoFile1.do as expected, but saves its output to a file named MyDir.log. And it does the same to myDoFile2.do, overwriting the log for myDoFile1.do.

Questions:

  1. Is this the expected behavior?
  2. How to solve this, and have outputs routed to myDoFile1.log and myDoFile2.do respectively, preferably without the need to explicitly starting to log in each do file?

Edit 1:

Just to add to this problem, I tested the case in which I need to pass 2 directory paths to my do-file, like so

StataMP-64 /e do myDoFile1.do "C:\MyDir1" "C:\MyDir2"

The output is now routed to a file named MyDir2.log. Strange.

Edit 2:

I reproduced the example in Roberto's answer below. Here's the screenshot to show that the problem is indeed occurring. I use both a Windows batch file and the Windows prompt (which Roberto used in answer below), and I reproduced the problem either way. I am using Stata 13 MP on Windows 7.enter image description here

Edit 3:

I've also replicated this on Stata 12 SE, Windows 7.

2
The same question is asked here, with the exception that the OS of interest is Linux. - Roberto Ferrer
very different questions, I'm afraid. in that question, OP was having a problem with his code breaking -- probably due to incorrect syntax. my question is about the file name to which output is printed. - djas
I see. Thanks for clarifying. - Roberto Ferrer
If you get no answer here, try statalist.com. (Please follow the guidelines stated in the FAQ.) If no solution there, then there's tech support. - Roberto Ferrer

2 Answers

1
votes

It's difficult for me to post text at the moment, so I'm attaching an image. It shows that it works fine for me. One argument (a complete directory path) is given and it shows up as a local macro. Moreover, the log file is created in the expected place, with the expected name.

enter image description here

The image shows all windows and files involved in the process.

That's Stata 12.0 on MS Windows XP.

(You can right-click on the image and download/view it at a greater resolution.)

0
votes

Escaping double quotes seems to solve the issue:

StataMP-64 /e do myDoFile1.do \"C:\MyDir\"

So it seems that Windows (7) is stripping the quotes before passing the arguments to Stata.