Getting ASCII (*.txt or *.csv) and Excel (*.xls) Data into Stata Format
(by Amy Yuen)

Stata can import data from several different file formats for statistical analysis. This tutorial will show you how to get your data into Stata format starting from tab-delimited or comma-separated ASCII file formats (*.txt, *.csv) and from Excel files (*.xls) beginning with the simplest methods to showing you how to use features of Stata that give you more control over how the data are imported.

Data Formats

Tab-delimited files:
With tab-delimited files, each unique case has its own row of data, and the delimiter that seperates variables is a tab. The data generally look something like the following:



Click here for full-size image

Comma-separated files:
These look very similar to tab-delimited files, except that the delimiter between variables is a comma instead of a tab:



Click here for full-size image

The file format *.txt is a simple text file and is usually seen with tab-delimited datasets. The file format *.csv is associated with comma-separated formats, and files in this format can usually be opened in a spreadsheet program like Excel. Excel files, meanwhile, end with .xls. All of these files can be sources for Stata datasets. The following pages will explain and demonstrate how to convert these files into Stata format:

Cutting and pasting data directly into Stata

Using StatTransfer

Using Stata's -insheet- command

Using Stata's -infix- command

Converting ICPSR Data in ASCII Format into Stata Data Files

(NOTE - if your ASCII data file has explanatory/descriptive text in it (e.g. footnotes), it may be necessary to strip out that information in a text editor or Excel before you try to import your data into Stata.)

Again, this guide is not a comprehensive, top-to-bottom review of how to get non-Stata files into Stata. It is instead an introduction to the methods and commands for doing so and how they might be used with a particular data format. If you would like more assistance in using the command with your data, please feel free to contact the Data Center staff.


Other Guides for Getting Data in Stata:

"Inputting Your Data into Stata," UCLA Academic Technology Services

"Stata Help for Insheet," by the Stata Corporation

"Stata Help for Infix," by the Stata Corporation



Home | Analyze Data Online | Help Resources | Contacts & Hours | Emory General Libraries