Stata File I/O
There are distinct commands for reading or writing to non-Stata file formats.
Contents
Excel
To import from an Excel spreadsheet, try:
import excel using "path/to/file", sheet("Sheet1") firstrowTo import all columns as string variables, as opposed to guessing the type of columns, use the allstring option.
To export into an Excel spreadsheet, try:
export excel using "path/to/file", sheet("Sheet1") firstrow(variables) replaceSee also -putexcel-.
Text
To import from a CSV file, try:
import delimited using "path/to/file", varnames(1)
Or for a delimited text file, such as by tabs, try:
import delimited using "path/to/file", delimiters("\t") varnames(1)Often, the stringcols(_all) option is necessary.
If there are no column labels, use the varnames(nonames) option.
To export into a (CSV) file, try:
export delimited using "path/to/file", replace
To suppress column labels, use the novarnames option.
Older versions of Stata
Stata is not infinitely backwards-compatible. To go beyond the supported range, use -saveold-.
saveold "path/to/file", version(11)
