Cornell University Cornell University CISER

Cornell Restricted Access Data Center

How Do I Run STATA with More Memory?

Q.  How can I work with large Stata datasets on the CRADC nodes? 

A.  When you open a dataset in Stata it loads the entire file into its memory.  If the file is larger than the default settings for memory and/or for the maximum number of variables you will get a message indicating that to be the case.

On CRADC the default settings for Stata allocate 10 MB of memory and a maximum number of 5000 variables.

If you need more than the default for either you can address this by using the SET MEM and SET MAXVAR commands.

Using the SET MEM command:

If you need more memory to read a large dataset, you can use the "SET MEMORY #K|M"  command to change the amount of memory available to you for the current Stata session:  

Example:  set mem 20M

Very Important!!!

There is a good explanation of how Stata uses memory at on the Stata web site at http://www.stata.com/support/faqs/win/memory1.html. That document also tells you how to estimate the amount of memory you need.

It is very important to request NO MORE than you truly need --  since requesting too much can actually slow things down!!  Stata will hold onto all memory requested (whether or not you use it!) until you close your Stata session.  Users who leave Stata open with large memory allocations are reducing the total amount of memory available to other users.  

After you have completed your large Stata job please close Stata or set the memory back to the default amount of 10MB so that your Stata session does not monopolize the memory on the machine!

You can enter the  query memory command to see your current settings (or the default settings):    

Using the SET MAXVAR comand:

Similarly, if you need to increase the maximum number of variables allowed, you can use the SET MAXVAR command:

Example:  set maxvar 10000   (the maximum possible is 32,767).  

Using the SET MATSIZE comand:

To increase the maximum number of variables allowed in a model you can use the SET MATSIZE command:

Example: set matsize 500 (the upper limit is 11,000)