# STATA

STATA saves all temporary files in the C:/ in Windows workstations. Since storage quota are limited on the C:/, you should follow these steps to change the temporary directory

## 1. Identify a folder outside C:\\

Find a folder where you are allowed to create and modify files. This is going to be the new SAS temporary folder. In this tutorial, let's assume that the directory is "E:\StataTemp\ccvdemo2"

## 2. Change the temporary directory

Users can change the temporary directory in different ways. The second way is required for multiple users to run Stata as it allows each user to have their own temporary directory for Stata.&#x20;

### 2.1 Change Windows Environment Variable&#x20;

Users only need to make the following changes **ONCE**.&#x20;

Step 1: Launch "Control Panel"

<figure><img src="https://240799936-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LcWdZhwLCll1J0u091B%2Fuploads%2FlbFgVuRPXog68KaK7AFf%2Fstronghold-control-panel.png?alt=media&#x26;token=e6a47f77-4d6d-494a-bfb1-d15ef8a7694d" alt=""><figcaption></figcaption></figure>

Step 2: Click "System and Security" in Control Panel

<figure><img src="https://240799936-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LcWdZhwLCll1J0u091B%2Fuploads%2Fxw6Ll8ScZpz2rJRi3V66%2Fstronghold-systems.png?alt=media&#x26;token=bfbe6ae6-ce02-4f51-94ff-3af84e86fd4b" alt=""><figcaption></figcaption></figure>

Step 3: Click "System"

<figure><img src="https://240799936-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LcWdZhwLCll1J0u091B%2Fuploads%2Fz1V65aa29stvuuDGpD17%2Fstronghold-systems-2.png?alt=media&#x26;token=c2ec3ff7-2258-428f-94a4-418a4ff82bbf" alt=""><figcaption></figcaption></figure>

Step 4: Click "Advanced system settings"

<figure><img src="https://240799936-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LcWdZhwLCll1J0u091B%2Fuploads%2FVdlwIKrYPhr9olfBQw2l%2Fstronghold-advanced-system.png?alt=media&#x26;token=561075e4-aabd-49a5-be89-5285e9b9a9e0" alt=""><figcaption></figcaption></figure>

Step 5: Click "Environment Variables"

<figure><img src="https://240799936-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LcWdZhwLCll1J0u091B%2Fuploads%2FCRuFiNGvYDtlhU9LdoQT%2Fstronghold-advanced-system-properties.png?alt=media&#x26;token=d2af0f29-98cf-4518-b476-8a56cd94c63e" alt=""><figcaption></figcaption></figure>

Step 6: Click "New"

<figure><img src="https://240799936-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LcWdZhwLCll1J0u091B%2Fuploads%2FIeNurqomet0MQRpXcdHg%2Fstronghold-environment-variables.png?alt=media&#x26;token=40e0e7f8-610d-4969-8c4b-3c920fc43731" alt=""><figcaption></figcaption></figure>

Step 7: Enter the variable name `STATATMP` and value that is your temp folder, i.e., `E:\StataTemp\ccvdemo2.`Then click "OK"

<figure><img src="https://240799936-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LcWdZhwLCll1J0u091B%2Fuploads%2FarULWcXo3EpOZtbt48Eg%2Fstronghold-environment-variables-new.png?alt=media&#x26;token=91dc2a71-4384-47aa-9c33-6a49111c1359" alt=""><figcaption></figcaption></figure>

After the changes above, whenever `Stata`is launched, it saves temporary files in the configured temporary folder.

### 2.2 Create myStata.bat

1. Launch Notepad. (You can click the search icon in the bottom left of the screen on the Taskbar. Type Notepad and click the first icon)
2. Enter the following text. It contains **4 lines**, including a blank line at the bottom:

```
:top
set dir=E:\statatmp\%random%
if exist %dir% goto top
mkdir %dir%
set statatmp=%dir%
"C:\Program Files\Stata16\StataSE-64.exe"
rmdir /s /q %dir%
goto :eof
```

<figure><img src="https://240799936-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LcWdZhwLCll1J0u091B%2Fuploads%2FhVK9CFlLsZY6shtszqOC%2Fsh-myStata.png?alt=media&#x26;token=0aa5e060-7708-4cba-9f65-b5073d6687a9" alt=""><figcaption></figcaption></figure>

3. On Notepad, click on File -> Save As ...
4. Click on "Desktop" on the left "Quick Access Panel"&#x20;
5. Enter "myStata.bat" in the File name field.
6. In the "Save as Type" dropdown list, choose "All Files"
7. Click Save

After the changes above, whenever users double click  "**myStata**" file on the Desktop, `Stata` is launched and saves temporary files in the configured temporary folder.&#x20;
