import excel — Import and export Excel files 3
export excel options Description
Main
sheet("sheetname"[ , modify | replace]) save to Excel worksheet
cell(start) start (upper-left) cell in Excel to begin saving to
firstrow(variables | varlabels) save variable names or variable labels to first row
nolabel export values instead of value labels
keepcellfmt when writing data, preserve the cell style and
format of existing worksheet
replace overwrite Excel file
Advanced
datestring("datetime format") save dates as strings with a datetime format
missing("repval") save missing values as repval
locale("locale") specify the locale used by the workbook; has no
effect on Microsoft Windows
collect is allowed with import excel; see [U] 11.1.10 Prefix commands.
locale() does not appear in the dialog box.
extvarlist specifies variable names of imported columns. An extvarlist is one or more of any of the
following:
varname
varname=columnname
Example: import excel make mpg weight price using auto.xlsx, clear imports columns
A, B, C, and D from the Excel file auto.xlsx.
Example: import excel make=A mpg=B price=D using auto.xlsx, clear imports columns
A, B, and D from the Excel file auto.xlsx. Column C and any columns after D are skipped.
Options for import excel
sheet("sheetname") imports the worksheet named sheetname in the workbook. The default is to
import the first worksheet.
cellrange(
start
:end
) specifies a range of cells within the worksheet to load. start and end
are specified using standard Excel cell notation, for example, A1, BC2000, and C23.
firstrow specifies that the first row of data in the Excel worksheet consists of variable names. This
option cannot be used with extvarlist. firstrow uses the first row of the cell range for variable
names if cellrange() is specified. import excel translates the names in the first row to valid
Stata variable names. The original names in the first row are stored unmodified as variable labels.
case(preserve | lower | upper) specifies the case of the variable names read when using the
firstrow option. The default is case(preserve), meaning to preserve the variable name case.
Only the ASCII letters in names are changed to lowercase or uppercase. Unicode characters beyond
ASCII range are not changed.
allstring
("format")
forces import excel to import all Excel data as string data. You can
specify the numeric display format used to convert the numeric data to string using the optional
argument format. See [D] format.
clear clears data in memory before loading data from the Excel workbook.