STATA: Data Entry

A. Colin Cameron, Dept. of Economics, Univ. of Calif. - Davis

This September 1999 help sheet gives information on As with many programs, one of the greatest challenges can be the initial reading in of data, especially if data are fixed format or if each observation spans several lines or if some of the data is character rather than numeric.

A detailed example is given in stjaggia.do which requires files jaggia.asc and jaggia.dct
 

STATA DATA SETS

Stata data sets have the extension .dta
They can be read in using the Stata command use.
For example, use mydata.dta
 

READ IN NON-STATA DATA SETS

Ways to proceed include

The Stata command help infiling gives an overview on reading in ascii (text) data. We have:


STATA COMMAND INFILE

The basic and most flexible command is infile.

For free format or unformatted data the basic command is, for example,
   infile v1 v2 v3 using mydata.raw
which creates variables we have labelled v1-v3 from the data in mydata.raw

For fixed format data there are two variations on the command

To see the form of the dictionary you need to see help infile2
but even better is to look at the Reference Guide [R] Infile

If you have problems also see the User's Guide [U] Commands to Input Data.
For Stata 6 manual this is chapter 24.

A detailed example is given in stjaggia.do which requires files jaggia.asc and jaggia.dct
 

SAVING STATA DATA SET

Once data is read in to Stata you should save it in Stata format using the save command.
    save mydata
for example, to save in file mydata.dta, or
    save mydata, replace
if replacing an existing Stata data set.

Also you should immediately that data is correctly read in by giving the Stata command
    summarize
which will give the minimum, maximum, mean and standard deviation of the data.
 

For further information on how to use Stata go to
   http://www.econ.ucdavis.edu/faculty/cameron