Introduction to Stata

4. Opening data

It may come as a surprise to you that we are covering something as basic as opening a data file in this session.  However, when we use software like Stata, we move away from clicking through menus to tell the program what we want it to do.  So we need to learn some basic commands to even just open our data file so that we can do something with the data.


Here are some of the key commands we can use to open data in Stata:

Table 2


Normally we would have a data set (or seven, or fifty two!) that we want to open and do something with.  If we have this data set saved (in Stata format!) and stored in our working folders, we could access it using the following use command:

. use “filepath\filename.dta”, clear



If you had a Stata data file called “toothbrushes.dta” saved in your C:\ drive, your use command would look like this:

. use “C:\toothbrushes.dta”, clear


It’s good practice to use the clear command after the use command, just in case you already had a dataset open and you’d forgotten … this could lead to you doing things to your other data set that you did not want to do, such as renaming variables, creating new ones, or even worse … deleting variables or data!

Now we’re going to actually open a data set … we know, this is exciting!  We’re going to open and use a dataset that comes with the Stata software package, with data on life expectancy from different countries around the world.  This data set is called “lifeexp.dta” and is stored in the same location as your Stata software.  We don’t need the file path and file extension (.dta) included in our command (like we did with the use command), because the sysuse command tells Stata that it’s using its own data file.

task  Task:   Open a Stata demonstration data file

Type the following command into your command window:

. sysuse lifeexp, clear


Have a quick look at your results window … what can you see?  Probably it doesn’t seem like much … you should (hopefully) get something like this:

Table 2