Using permanent Stata data files
Clearing memory, setting memory size, using a Stata file, saving changes to the file.
In Example1 you created a permanent Stata data file called myfile.dta. This example uses that file. Type each of these commands and observe the results:
clear
// setting memory is only necessary if using a
// previous version of Stata to version 12:
set memory 100m
use myfile
drop d
save myfile
save myfile,replace
Questions:
1. The clear command removes data from Stata's memory. Why do we need to use this command before changing the size of memory (set memory command) or before copying new data into Stata's memory? Answer.
2. The set memory command tells Stata to create space of a given size in your computer's RAM in which to hold data. How much space do you need?
Answer.
3. What is another way to request memory in Stata?
Answer.
4. The use command copies a Stata
data file into Stata's memory. How would you change the use command if
the Stata data file was not in the present working directory? Assume it
was in the following path:
e:\student\jdoe\myproject\data\myfile.dtaAnswer.
5. What does the drop command do?
Answer.
6. Why do you get the error message "file myfile.dta already exists" when you type the save command?
Answer.
Answers:
1. Stata can only keep one set of data in memory at a time. Once it has data in memory, the size and shape of the data space in memory remain fixed. In order to protect you from accidentally writing over and destroying your data in memory, Stata requires that you clear memory before either of these tasks.
Back to question.
2. The amount of space you request needs to be larger than the size of the file you want to use. A good rule is to request 5 MB more memory than you need. This allows some room for you to add more variables or observations. In this case, we're asking for 100 MB of memory. It will handle any file that uses less than 100 MB on disk.
Back to question.
3. The default amount when you open Stata at CPC from the Start menu is 50 MB. If you have your own copy of Stata installed on your computer, you can change the default memory up to the maximum available on your computer using set memory. This command and many other set commands have the permanently option. This tells Stata to remember the memory setting from one Stata session to the next.
set memory 100m, permanentlyAnother approach is to create a profile.do text file and store it in c:\ado. In that file you can put any commands that you would like Stata to execute when it starts, such as:
set memory 100mBack to question.
4. Change the use command to include the full path:
use "e:\student\jdoe\myproject\data\myfile.dta"By the way, if you make a mistake typing a Stata command, especially a long one like this, you don't have to retype the whole command. You can press the Page Up
key to display your last command, edit it, and press Enter to resubmit it. Or, you can click on the command in the Review window to display it for editing.
Back to question.
5. The drop command drops one or more variables. We cover it in detail in the next example. It's included here only to make this example a little less artificial.
Back to question.
6. Stata is warning you that you are about to write over an existing file on disk. It's giving you a chance to think about whether that's what you really should be doing. The replace option reassures Stata that you know what you're doing:
save myfile,replaceBack to question.
Review again?
Another topic?


