Indiana University
University Information Technology Services
  
What are archived documents?
Login>>
Login

Login is for authorized groups (e.g., UITS, OVPIT, and TCC) that need access to specialized Knowledge Base documents. Otherwise, simply use the Knowledge Base without logging in.

Close

How can I read ASCII data files into Stata?

Suppose your data is in the following format, located on a flash drive, for example E:, with the filename data.txt :

1 male 12 19 0 1 3.1 2 male 14 24 0 1 5.8 3 female 16 45 1 1 12.2 4 female 14 23 . 0 8.1 5 male 18 36 0 0 6.6 6 female 15 23 1 1 0 7 female 12 21 1 1 21.2 8 male 13 19 1 0 7.1

The data consist of eight cases and seven variables, with each variable delimited by a single space. (You can also delimit variables with tabs or commas.) The second variable is a string variable, the seventh variable is a floating point variable, and a missing value is indicated by a period for the fifth variable of the fourth case.

To read this file into Stata, at the Stata prompt, enter:

infile id str7 sex ed inc vote married tv using e:\data.txt

Note: The name of each variable is listed in the order that it appears in the raw data file. Each variable name must begin with a letter and avoid special characters such as  #  (the pound sign) and  $  (the dollar sign). The str7 notation informs Stata that the variable immediately following (sex) is a string variable whose length is seven characters.

To read ASCII data files into Stata using the drop-down menu, click File > Import > Unformatted ASCII data.

To save the data in a Stata format to the flash drive, enter:

save e:\data.dta

Note: To enter a string with embedded spaces or commas, surround it with quotation marks (e.g., "Indiana University"). If data is tab- or comma-delimited, use the insheet command instead of infile. If data is in a fixed format, use the infix command.

For more about statistical and mathematical software, email the UITS Stat/Math Center, visit the center's web page, or phone 812-855-4724 (IUB) or 317-278-4740 (IUPUI). The center is located in Bloomington at 410 N. Park Avenue, and is open for consultation by appointment Monday-Friday 9am-5pm.

This is document aeil in domain all.
Last modified on May 06, 2011.

Comments/Questions/Corrections

Use this form to offer suggestions, corrections, and additions to the Knowledge Base. We welcome your input!

If you are affiliated with Indiana University and would like assistance with a specific computing problem, please use the Ask a Consultant form, or contact your campus Support Center.

Contact Information

Note: We will reply to your comment at this address. If your message concerns a problem receiving email, please enter an alternate email address.