Stata File I/O

Stata is capable of handling most file formats, including proprietary ones.


Excel

To import from an Excel spreadsheet:

import excel using "path/to/file", sheet("Sheet1") firstrow

To import all columns as string variables, as opposed to guessing the type of columns, use option allstring.

To export into an Excel spreadsheet:

export excel using "path/to/file", sheet("Sheet1") firstrow(variables) replace

See also putexcel.


CSV

To import from a CSV file:

import delimited using "path/to/file", delimiters(",") varnames(1)

Often, the stringcols(_all) option is necessary.

If there are no column labels, use varnames(nonames).

To export into a CSV file:

export delimited using "path/to/file", delimiters(",")

To suppress column labels, use novarnames.


Tab-Delimited

To import from a tab-delimited file:

import delimited using "path/to/file", delimiters("\t") varnames(1)

Often, the stringcols(_all) option is necessary.

If there are no column labels, use varnames(nonames).

To export into a tab-delimited file:

export delimited using "path/to/file", delimiters("\t")

To suppress column labels, use novarnames.


Old Stata Versions

Stata does not support handling data from all versions of Stata. To go beyond the supported range, use saveold.

saveold "path/to/file", version(11)


CategoryRicottone

Stata/FileIO (last edited 2023-06-08 00:44:38 by DominicRicottone)