Example 3. Reading a Microsoft Excel file through command lines
An Excel file can be loaded into Stata using odbc directly. Here is an example. Let's say we have an Excel file test.xls located in folder d:\data. It has two sheets in it, s1 and s2. We want to read the first sheet into Stata. We can use command odbc load for this task as shown below. Notice that we have to specify in full the type of the data file and the location of the data file in dsn option and we use table("s1$") for reading in the first sheet. Both the quotation marks and the dollar sign are necessary here for the table option and both dsn and table options are needed to load the entire data. Also notice that we have to clear up the memory first.
clear odbc load, dsn("Excel Files;DBQ=d:\data\test.xls") table("s1$") descContains data obs: 5 vars: 2 size: 100 (99.9% of memory free) ------------------------------------------------------------------------------- storage display value variable name type format label variable label ------------------------------------------------------------------------------- a double %10.0g b double %10.0g ------------------------------------------------------------------------------- Sorted by: Note: dataset has changed since last saved