help xls2dta
-------------------------------------------------------------------------------

Title

xls2dta -- Save Excel files as Stata datasets

Syntax

xls2dta [extvarlist] [using filename] [, options]

where filename specifies the Excel file/s to be converted to Stata datasets. If filename is not specified, it defaults to the current working directory. See Remarks.

Description

xls2dta converts Excel files to Stata datasets using import excel. Names for Stata datasets are derived from the names of the Excel files (see Remarks). The program is a convenient tool to import and convert more than one Excel file and/or worksheet at a time.

Options

save(dirc) specifies the directory to store Stata datasets. Default dirc is the current working directory (/Volumes/fmwww0/RePEc/bocode/x). Double quotes may be omitted.

allsheets[(numlist | ["]pattern["] ...)] saves all worksheets in the Excel files as Stata datasets. If foo.xls contains three sheets, Sheet1, Sheet2 and Sheet3, Stata datasets foo_Sheet1.dta, foo_Sheet2.dta and foo_Sheet3.dta will be saved. If specified, only worksheets numlist, or worksheets matching patterns (see strmatch) are converted.

replace allows Stata datasets to be replaced if they already exist.

import excel options are options allowed with import excel. Option sheet("sheetname") may not be combined with allsheets. Option describe may not be combined with any other option. Option clear is ignored.

respectcase specifies that xls2dta respect case in filename (Windows only). Uppercase characters in filename imply respectcase. See extended macro function dir.

nostop prevents xls2dta from stopping if one of the internal calls to import excel returns an error. This option should rarely be specified.

mkdir[(public)] creates new directory dirc, as specified in save (see mkdir).

Remarks

In filename one specific file, or more than one file in a directory may be specified.

Specifying

. xls2dta using c:/myxlsfiles/foo.xls

converts (the first sheet of) foo.xls to foo.dta and saves it in the current working directory.

If c:/myxlsfiles contains more than one .xls file, we can convert all of them to Stata datasets typing

. xls2dta using c:/myxlsfiles/*.xls

To convert all .xls and .xlsx files in c:/myxlsfiles, we would type

. xls2dta using c:/myxlsfiles

If foo.xls contains more than one worksheet, and we want to convert all worksheets to Stata datasets, we type

. xls2dta using c:/myxlsfiles/foo.xls ,allsheets

To only convert worksheets starting with Sheet, we specify

. xls2dta using c:/myxlsfiles/foo.xls ,allsheets(Sheet*)

Example

. xls2dta using c:/myxlsfiles ,save(c:/mydtafiles)

Saved results

xls2dta saves the following in r():

Macros r(n_dta) number of saved .dta files r(dta_#) filename of .dta file #

Author

Daniel Klein, University of Kassel, klein.daniel.81@gmail.com

Also see

Online: import excel, extended functions, foreach, mkdir

if installed: xls2stata