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 :
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.txtNote: 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.dtaNote: 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.
Last modified on May 06, 2011.







