Hi all,
Recently I try to streamline my data analysis by using the windows batch file to call do files. However, I find something strange about setting the current working directory, and overwriting generated files. For example, I have a do file named auto.do, whose only purpose is to download the auto data and save it; it looks like this:
And it's located in D:\Projects\p1.
I also write a cmd file calling the do file, and the cmd file looks like this:
Notice that I set the current working directory to the p1 folder, while my default Stata working directory is not this one.
This completes the setup. And Here are the questions:
1) It doesn't seem that the working directory I set in the cmd file is respected by Stata. Stata saves the auto data still to the default stata working directory, not the p1 folder. Also if I don't give the full path of the do file, Stata complains that it doesn't find the do file.
2) Stata saves the auto data to its default working directory. However, if I run the batch file again, the previously generated auto data is automatically overwritten, with no warning or any other message poped up. Also notice that I don't include the replace option in the save command in the do file. How could this happen? And what will be a good strategy to deal with this uninformed overwriting.
3) A log file is generated with /e specified. The issue is that this log file is indeed saved in the p1 folder, which I set as the working directory in the 1st line of the cmd file. This might not be a big issue for me since I prefer to include the log command in the do file, and not to use /e in the first place. But just curious to know why this phenomenon happens.
To conclude, the setting of working directory in the cmd file is ignored by Stata when new files are read or written in the do file. But the log file does respect the working directory set int he cmd.
Thanks!
Recently I try to streamline my data analysis by using the windows batch file to call do files. However, I find something strange about setting the current working directory, and overwriting generated files. For example, I have a do file named auto.do, whose only purpose is to download the auto data and save it; it looks like this:
Code:
sysuse auto, clear save auto.dta
I also write a cmd file calling the do file, and the cmd file looks like this:
Code:
cd /d D:\Projects\p1 Stata /e /q do "D:\Projects\p1\auto.do"
This completes the setup. And Here are the questions:
1) It doesn't seem that the working directory I set in the cmd file is respected by Stata. Stata saves the auto data still to the default stata working directory, not the p1 folder. Also if I don't give the full path of the do file, Stata complains that it doesn't find the do file.
2) Stata saves the auto data to its default working directory. However, if I run the batch file again, the previously generated auto data is automatically overwritten, with no warning or any other message poped up. Also notice that I don't include the replace option in the save command in the do file. How could this happen? And what will be a good strategy to deal with this uninformed overwriting.
3) A log file is generated with /e specified. The issue is that this log file is indeed saved in the p1 folder, which I set as the working directory in the 1st line of the cmd file. This might not be a big issue for me since I prefer to include the log command in the do file, and not to use /e in the first place. But just curious to know why this phenomenon happens.
To conclude, the setting of working directory in the cmd file is ignored by Stata when new files are read or written in the do file. But the log file does respect the working directory set int he cmd.
Thanks!
Comment