Stata 15 help for infile1

[D] infile (free format) -- Import unformatted text data

Syntax

infile varlist [_skip[(#)] [varlist [_skip[(#)] ...]]] using filename [if] [in] [, options]

If filename is specified without an extension, .raw is assumed. If filename contains embedded spaces, remember to enclose it in double quotes.

options Description ------------------------------------------------------------------------- Main clear replace data in memory

Options automatic create value labels from nonnumeric data byvariable(#) organize external file by variables; # is number of observations -------------------------------------------------------------------------

Menu

File > Import > Unformatted text data

Description

infile reads into memory from a disk a dataset that is not in Stata format.

Here we discuss using infile to read free-format data, meaning datasets in which Stata does not need to know the formatting information. Another variation on infile allows reading fixed-format data; see infile2. Yet another alternative is import delimited, which is easier to use if your data are tab- or comma-separated and contain 1 observation per line. Stata has other commands for reading data, too. If you are not certain that infile will do what you are looking for, see [D] import and [U] 21 Entering and importing data.

After the data are read into Stata, they can be saved in a Stata-format dataset; see [D] save.

Options

+------+ ----+ Main +-------------------------------------------------------------

clear specifies that it is okay for the new data to replace the data that are currently in memory. To ensure that you do not lose something important, infile will refuse to read new data if data are already in memory. clear allows infile to replace the data in memory. You can also drop the data yourself by typing drop _all before reading new data.

+---------+ ----+ Options +----------------------------------------------------------

automatic causes Stata to create value labels from the nonnumeric data it reads. It also automatically widens the display format to fit the longest label.

byvariable(#) specifies that the external data file is organized by variables rather than by observations. All the observations on the first variable appear, followed by all observations on the second variable, and so on. Time-series datasets sometimes come in this format.

Examples

--------------------------------------------------------------------------- Setup . sysuse auto . keep price mpg rep78 . keep in 1/10

Write data in text format to myout.raw . outfile using myout

Display contents of myout.raw . type myout.raw

Clear data and value labels from memory . clear

Read data in myout.raw into memory . infile price mpg rep78 using myout

List the data . list

Describe the data . describe

Clear data and value labels from memory . clear

Read data in myout.raw into memory, but store mpg and rep78 as int variables . infile price int (mpg rep78) using myout

Describe the data . describe

--------------------------------------------------------------------------- Setup . sysuse auto, clear . sort price . keep make price mpg rep78 foreign . keep in 1/10

Write data in text format to myout.raw . outfile using myout, replace

Display contents of myout.raw . type myout.raw

Clear data and value labels from memory . clear

Read data in myout.raw into memory . infile str18 make price mpg rep78 str8 foreign using myout

List the data . list

Clear data from memory . clear

Read data in myout.raw into memory, automatically creating a value label for foreign and storing it as a byte rather than a str8 . infile str18 make price mpg rep78 byte foreign:origin using myout, automatic

Describe foreign . describe foreign

List the data . list

List the value label . label list

Clear data and value labels from memory . clear

Define value label myorigin . label define myorigin 0 "Domestic" 1 "Foreign"

Read data in myout.raw into memory using myorigin value label for foreign . infile str18 make price mpg rep78 byte foreign:myorigin using myout

List the data . list

List the value label . label list ---------------------------------------------------------------------------


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index