ARCHIVED: In Stata, how do I read an ASCII text file?

This content has been archived, and is no longer maintained by Indiana University. Information here may no longer be accurate, and links may no longer be available or reliable.

The Stata infile command reads a space- or comma-delimited ASCII text file. The infix command imports a fixed ASCII file without a delimiter.

Suppose you want to read the space-delimited ASCII file temp.txt saved in the directory c:\data. The file contains five variables (v1, v2, v3, v4, and v5). Use the infile command as follows:

  infile v1 v2 v3 v4 v5 using c:\data\temp.txt, clear

The clear option removes the existing data set in memory and reads in a new data set.

If a text file does not use a delimiter and instead distinguishes data items by their column locations, it is called the fixed format. The following command reads a string variable id from columns 1-7, a numeric variable stat from columns 11-13, and math from columns 14-16:

  infix str id 1-7 stat 11-13 math 14-16 c:\data\temp2.txt, clear

If you have questions about using statistical and mathematical software at Indiana University, contact the UITS Research Applications and Deep Learning team.

This is document afqr in the Knowledge Base.
Last modified on 2023-05-09 14:39:52.