Using permanent Stata data files
Clearing memory, 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 use myfile drop d save myfile save myfile,replace
1. The clear command removes data from Stata's memory. Why do we need to use this command before copying a new data file into Stata's memory? Answer.
2. 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:
4. Why do you get the error message "file myfile.dta already exists" when you type the save command? Answer.
1. Stata can only keep one set of data in memory at a time. 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.
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.
4. 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: