How to redirect Stata temp file to a specific folder

Sometimes the default Stata temp space run out of storage. You may have to redirect the location of your temp file to fix this. Here’s what you should do.

While signed into the servers begin inside the Notepad application. Open start menu by clicking windows icon in bottom left, type “notepad” and select Notepad desktop application.
Open Notepad.

Paste the following into your Notepad application. A full example of this will be printed near the bottom of the page.:


set STATATMP=U:\statatemp
cd u:\project
"C:\Program Files\Stata17\StataMP-64.exe"

Save the notepad file with a .bat extension to create a batch file (e.g., Statatemp.bat). Do not save it with the default .txt extension. It has to have a .bat extension.

The quotes when pasted from this FAQ to notepad do not come out as standard quotes.  Delete and replace the quotation marks after you have pasted the above commands into notepad. If the text inside the quotes are color coded; delete the quotes and re-enter them in the same position.

Make sure to put an empty line after the 3rd line of code. A total of 4 lines in your Notepad. 3 commands and 1 empty line at the end.

Make sure you create a folder named “statatemp” inside your U drive.  U:\statatemp folder mentioned on the set command above. You can specify any path\folder here provided they exist. This is where Stata will redirect your temp files.

Replace the u:\project folder with your own project path\folder.

Do not change the last line. The point of the last line is to run the .exe file that would open stata. If you are using a different Stata version the path\folder and .exe name may be different. 

Once created, double-click on the .bat file.

From hereon double click on the .bat file created using the above specifications. Double clicking the file should open Stata automatically, if it does not there is an issue with the .bat file created. You can run the commands below to check where your tempfile is going:

tempfile junk
display “`junk'”

It should show the temp file being stored in the folder you specified on the set command.

Example
Example using my research account.

set STATATMP=U:\Desktop\statatemp
cd U:\Documents\stata_test
"C:\Program Files\Stata17\StataMP-64.exe"

Contact the CCSS-RS HelpDesk with any questions or issues.