Module 6 Saving our data set

When we work in Stata, all commands and executions are saved in memory. Nevertheless, it is necessary that we save our work as a file, and this is what we will be doing in this module. For our data set, this means that even though all the work we have done so far is stored in Stata’s memory, it is necessary that we save a file copy of our work. By the end of the module, we:

  • should become familiar with basic requirements and processes for saving work activities in Stata
  • be able to save a file in Stata for both forward and backward compatibility situations

To save the work we done so far in Stata, - we first click on File at the top left corner on the toolbar, - then select Save as….

Doing this will open a dialog box where we can choose where we would like to save our file. Once the data have been saved to a file, Stata will give the file the .dta extension even if we do not specify one. This extension identifies the file as a Stata dataset. We can give it any first name we want, but it is important that we not change the extension (.dta). Now, Let us try to save our data set:

  • Go to the menu on the top left corner and select File
  • In the dialog box that pops up select Save as…
  • A dialog will open that is similar to the one below:

Figure 2.8

  • We specify a directory in which we wish to save our file
  • We then click the Filename field box near the bottom of the window, and give any file name we wish - let us choose term_proj as name for our dataset. Note: We can delete the .dta extension already in the field box as long as we leave the next field box Save as type just as it is.
  • Finally, we click Save to save the file and return to the main Stata screen.

It is worth noting that only one dataset can be opened in Stata at a time. When we open a new dataset, Stata first clears the current one from memory. Stata is designed to automatically detect when changes are made to datasets and will issue a prompt to save changes before exiting the application or replacing the current dataset. It is highly recommended, nevertheless, that we constantly save our work before closing Stata or opening a new data set. This is because Stata does not alert you to save data if the only changes made are to labels or notes.

After saving the data, it is good practice to check to see whether everything we have listed in the dataset is indeed there. To do this:

  • We move the cursor to the toolbox and select Data
  • From the dialog box that pops up, we select Describe
  • Then from the list, we select Describe data contents (codebook)
  • A dialog will pop up that looks similar to the one below:

Figure 2.9

  • In the dialog box, we can specify one of the variables in our data set, or if we want to see every variable in the output, we leave the input field Variables:(leave empty for all) blank.
  • Let us check the codebook for the variable tuition_hike to see whether everything is as we want. To do this, we type tuition_hike into the variable field in the dialog box and click OK, or Submit then OK. We should see an output similar to the one below:

Figure 3.0. .codebook for variable tuition_hike

The Stata version used in this tutorial is version 12. Given that Stata makes it possible for new versions to be able to read data files that were saved using older versions, the data set we just saved can be used in Stata versions 12 or later. Stata is backward compatible in this sense. Stata is not always forward compatible however. For example, if someone using an earlier version of Stata wanted to use our dataset, they would have to specifically save it to an older version of Stata for them to be able to use the dataset. This, unfortunately is only applicable to versions no earlier than 9. To make our data set forward compatible:

  • We move our cursor to the toolbar and click File
  • In the dialog box that pops up, we select Save as …
  • Another dialog box appears that is similar to the one below

Figure 3.1

  • In the Filename field box near the bottom, we select a name to give the file. Again, we choose the name term_proj
  • In the Save as type field box below, we then click on the down arrow on the right and select the Stata 9/10 Data(.dta)* from the list. Figure 3.1 below shows the options we must select to make our file forward compatible for earlier versions of Stata:

Figure 3.2.

  • Last but not least, we click Save, to save our dataset and set it to be forward compartible for later Stata versions

Creating a data set entails more than just numeric values, as we have seen in this tutorial. Sometimes, it requires incorporating several kinds of information including numeric data, variable names, and variable labels. In addition to the labeling, we can add notes in the dataset and in some cases, to variables, which can be a useful technique for documenting changes.

We have now created our Stata dataset and saved it to a local drive. Normally, after work is completed in Stata, we close the program by going to the menu at the top left corner, and clicking File, then Exit. Let us do that.