UCLA Academic Technology Services HomeServicesClassesContactJobs
Help the Stat Consulting Group by giving a gift             
Loading

Stata FAQ
How do I read a data file that has commas or tabs as delimeters?

Consider the file below that contains four variables, make, mpg, weight, and price. The file looks like what is shown below (the variable names are indeed the first line of data.)
make,mpg,weight,price
AMC Concord,22,2930,4099
AMC Pacer,17,3350,4749
AMC Spirit,22,2640,3799
Buick Century,20,3250,4816
Buick Electra,15,4080,7827
You can read this kind of file using the insheet command as shown below.
insheet using comma.txt
We can issue the list command to see if the data was read properly.
list

              make       mpg    weight     price 
  1.   AMC Concord        22      2930      4099 
  2.     AMC Pacer        17      3350      4749 
  3.    AMC Spirit        22      2640      3799 
  4. Buick Century        20      3250      4816 
  5. Buick Electra        15      4080      7827 
As you can see, the insheet command was pretty smart. It got the variable names from the first row of the data.  It looks at the first row and can get the variable names from the first row.  It also examines the file and determines for itself whether the data are separated by commas or by tabs.  The exact same command could read the same file but delimited with tabs (you can try reading tab.txt for yourself).  If you would like more information about reading data in Stata, see the Stata Learning Module on inputting raw data into Stata.

As an aside, you can actually read the raw data file comma.txt directly over the internet into Stata, using the following command:

insheet using http://www.ats.ucla.edu/stat/stata/faq/comma.txt

How to cite this page

Report an error on this page or leave a comment

UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services


The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California.