Joseph Nathan Cohen

Department of Sociology, CUNY Queens College, New York, NY

Saving Data in Stata

How to save data in Stata

To see more about the “Teaching through YouTube” series.  For more, see this post.

Original Video Description

How to save data in Stata

Transcription (Auto-Generated)

In this video, I will show you how to save data in Stata format. By the end of this tutorial, you’ll be proficient in saving data in the Stata format. The syntax for saving data in Stata format is quite straightforward. In the command window, type the command “save”, followed by a space. Then, within quotation marks, provide the desired file name followed by the “.DTA” suffix. Close the quotation marks and if needed, add a comma followed by the word “replace”. For instance, if you wish to save your data as “survey_data”, the command would look like this: save “survey_data.DTA”, replace The “replace” option is essential to note. If you don’t use the “replace” command and try to save a data file with a name that already exists in your directory, Stata will throw an error. It will not overwrite any pre-existing data set. Therefore, always ensure your working directory is correct and be cautious when overwriting datasets. Now, as a practical example: Assuming I’ve already loaded a dataset into Stata’s memory, which I can verify by seeing the listed variable names in the variables window. To save this dataset, I’ll first ensure that the directory points to the desired folder. If I want this dataset to be named “new_data”, I’ll type: save “new_data.DTA”, replace Stata will confirm that the dataset “new_data” has been saved, and I can verify it in the directory. To recap: To save a dataset currently in Stata’s memory, use the “save” command. The syntax involves typing “save”, followed by the dataset’s name enclosed in quotation marks with a “.DTA” suffix. Optionally, include “, replace” if you want to overwrite a dataset with the same name. If you exclude the “replace” command and a file with the same name exists, Stata will give an error. Not adding “replace” can act as a safeguard against unintentional overwriting.