|
Size: 1659
Comment:
|
← Revision 10 as of 2025-10-24 16:31:24 ⇥
Size: 1367
Comment: Rewrite
|
| Deletions are marked like this. | Additions are marked like this. |
| Line 3: | Line 3: |
| Stata is capable of handling most file formats, including proprietary ones. | There are distinct commands for reading or writing to non-Stata file formats. |
| Line 13: | Line 13: |
| To import from an Excel spreadsheet: | To import from an [[Excel]] spreadsheet, try: |
| Line 19: | Line 19: |
| To import all columns as string variables, as opposed to guessing the type of columns, use option `allstring`. | To import all columns as string variables, as opposed to guessing the type of columns, use the '''`allstring`''' option. |
| Line 21: | Line 21: |
| To export into an Excel spreadsheet: | To export into an Excel spreadsheet, try: |
| Line 27: | Line 27: |
| For exporting reports into Excel, see [[StataReports#putexcel|documentation on putexcel]]. | See also [[Stata/PutExcel|-putexcel-]]. |
| Line 33: | Line 33: |
| == CSV == | == Text == |
| Line 35: | Line 35: |
| To import from a CSV file: | To import from a CSV file, try: |
| Line 38: | Line 38: |
| import delimited using "path/to/file", delimiters(",") varnames(1) | import delimited using "path/to/file", varnames(1) |
| Line 41: | Line 41: |
| Often, the `stringcols(_all)` option is necessary. If there are no column labels, use `varnames(nonames)`. To export into a CSV file: |
Or for a delimited text file, such as by tabs, try: |
| Line 48: | Line 44: |
| export delimited using "path/to/file", delimiters(",") | import delimited using "path/to/file", delimiters("\t") varnames(1) |
| Line 51: | Line 47: |
| To suppress column labels, use `novarnames`. | 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. |
| Line 57: | Line 63: |
| == Tab-Delimited == | == Older versions of Stata == |
| Line 59: | Line 65: |
| 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`. |
Stata is not infinitely backwards-compatible. To go beyond the supported range, use '''`-saveold-`'''. |
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)
