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:

       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:



3. What does the drop command do? Answer.

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.

Back to question.



2. 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. 



3. 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. 



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:

       save myfile,replace

Back to question.


Review again?


Another topic?

Wink Plone Theme by Quintagroup © 2013.

Personal tools
This is themeComment for Wink theme