Stata 15 help for outfile

[D] outfile -- Export dataset in text format


outfile [varlist] using filename [if] [in] [, options]

options Description ------------------------------------------------------------------------- Main dictionary write the file in Stata's dictionary format nolabel output numeric values (not labels) of labeled variables; the default is to write labels in double quotes noquote do not enclose strings in double quotes comma write file in comma-separated (instead of space-separated) format wide force one observation per line (no matter how wide)

Advanced rjs right-justify string variables; the default is to left-justify fjs left-justify if format width < 0; right-justify if format width > 0 runtogether all on one line, no quotes, no space between, and ignore formats missing retain missing values; use only with comma

replace overwrite the existing file ------------------------------------------------------------------------- replace does not appear in the dialog box.


File > Export > Text data (fixed- or free-format)


outfile writes data to a disk file in plain-text format, which can be read by other programs. The new file is not in Stata format; see [D] save for instructions on saving data for later use in Stata.

The data saved by outfile can be read back by infile; see [D] import. If filename is specified without an extension, .raw is assumed unless the dictionary option is specified, in which case .dct is assumed. If your filename contains embedded spaces, remember to enclose it in double quotes.


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

dictionary writes the file in Stata's data dictionary format. See infile2 for a description of dictionaries. comma, missing, and wide are not allowed with dictionary.

nolabel causes Stata to write the numeric values of labeled variables. The default is to write the labels enclosed in double quotes.

noquote prevents Stata from placing double quotes around the contents of strings, meaning string variables and value labels.

comma causes Stata to write the file in comma-separated-value format. In this format, values are separated by commas rather than by blanks. Missing values are written as two consecutive commas unless missing is specified.

wide causes Stata to write the data with 1 observation per line. The default is to split observations into lines of 80 characters or fewer, but strings longer than 80 characters are never split across lines.

+----------+ ----+ Advanced +---------------------------------------------------------

rjs and fjs affect how strings are justified; you probably do not want to specify either of these options. By default, outfile outputs strings left-justified in their field.

If rjs is specified, strings are output right-justified. rjs stands for "right-justified strings".

If fjs is specified, strings are output left- or right-justified according to the variable's format: left-justified if the format width is negative and right-justified if the format width is positive. fjs stands for "format-justified strings".

runtogether is a programmer's option that is valid only when all variables of the specified varlist are of type string. runtogether specifies that the variables be output in the order specified, without quotes, with no spaces between, and ignoring the display format attached to each variable. Each observation ends with a new line character.

missing, valid only with comma, specifies that missing values be retained. When comma is specified without missing, missing values are changed to null strings ("").

The following option is available with outfile but is not shown in the dialog box:

replace permits outfile to overwrite an existing dataset.


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

List the data . list

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

Display contents of myout.raw . type myout.raw

Change the value of mpg in observations 1 to 20 . replace mpg = 20 in 1

Write data in plain-text format to myout.raw, overwriting the existing myout.raw file . outfile using myout, replace

Write data in plain-text format to myout.raw but write numeric values for foreign rather than the labels . outfile using myout, nolabel replace

Display contents of myout.raw . type myout.raw

Write data in plain-text format to myout.raw in comma-separated format . outfile using myout, comma replace

Display contents of myout.raw . type myout.raw

Write data to myout.dct in Stata's dictionary format . outfile using myout, dictionary

Display contents of myout.dct . type myout.dct

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