Written and maintained by CASRAI Editorial Board
Published
On this page
Importing Excel into Stata starts with import excel: select the workbook, worksheet and data rectangle, then use firstrow when that rectangle begins with column headings. Before analysis, check the imported observation count, variable names and storage types. The worked example below makes those checks explicit, so a command that runs successfully is followed by a test of what actually arrived.
What Stata is used for in research
For this task, Stata turns a spreadsheet table into a dataset that can be inspected and saved in its native .dta format. StataCorp’s Excel tutorial demonstrates that sequence: read a named worksheet, inspect it with describe, then save it. The import is a preparation step; it does not establish that the spreadsheet contains the right records for a research question.
Start with the table you mean to analyse. StataCorp’s conversion FAQ describes the expected layout as one table on one sheet, with at most one heading row. A workbook may also contain a cover sheet, explanatory notes or several tables. Identify the analytical rectangle rather than assuming that every occupied cell belongs to the dataset.
Keep the import instructions with the project. The Stata do-file workflow guide explains how a saved script fits into a reproducible project. Here, the practical goal is narrower: another researcher should be able to identify the same workbook, select the same cells and compare the resulting structure with the intended table.
How to install or access Stata
Use StataCorp’s installation guide for the download, installation and license setup. It provides separate routes for Windows, Mac and Unix/Linux. Before installing, have the License and Activation Key available and use it to identify the appropriate edition: Stata/MP, Stata/SE or Stata/BE. If supplied with an .stcodes file, retain it for import during installation.
The instructions below assume that Stata is installed and that you can open the workbook from your working location. Use an explicit file path when it is elsewhere. Do not replace the example filename with a worksheet name: the workbook is the file, while the worksheet is selected separately.
Stata’s current Excel manual documents direct reading of both .xls and .xlsx files on Windows, Mac and Linux. The documented menu route is File > Import > Excel spreadsheet (*.xls;*.xlsx). The command route is useful for retaining the exact import choices with the project.
How to import Excel into Stata step by step
This illustrative composite uses a fictional workbook called study.xlsx and a worksheet called Responses. It is a teaching example, not participant data or a report of a real study. Create the layout below if you want a small practice file, or substitute the corresponding coordinates from your own workbook.
In the example, row 1 contains a title, rows 2–3 are outside the table, row 4 contains headings, rows 5–8 contain observations, and row 9 contains a note. Store the identifiers as text in Excel before entering them; the leading zeros are part of each fictional identifier.
| Excel row | Column A | Column B | Column C |
|---|---|---|---|
| 4 | participant_id | wave | score |
| 5 | 0012 | 1 | 14 |
| 6 | 0034 | 1 | 18 |
| 7 | 0056 | 2 | 16 |
| 8 | 0078 | 2 | 20 |
- Protect any dataset already in memory. Save work you need before importing another dataset. The example import below uses
clear, which replaces the data currently in memory. Treat that as a deliberate replacement, not a routine option to add without checking. - Inspect the workbook’s sheet inventory. Run
import excel "study.xlsx", describe. This lists the available worksheets and their cell ranges. Check thatResponsesexists. An occupied range may include the title and note; it is evidence about the sheet, not an instruction to import all of it. - Select the intended rectangle. For this example, it is
A4:C8. The upper boundary includes the headings, and the lower boundary includes the final observation. StataCorp’s real-world import example shows why excluding preambles and footers matters. - Run the import. Use the single command below. Replace the workbook, sheet and coordinates together when adapting it. The names
Responsesandstudy.xlsxare placeholders for this fictional exercise. - Inspect the structure and values. Run
describe, then inspect the imported records in the Data Editor. Compare them with the small source table before applying transformations or fitting a model. - Save the checked dataset. Run
save "study-import.dta"using a new output filename. StataCorp’s introductory tutorial usessaveafter checking the imported data. Keep this output distinct from the input workbook so their roles remain clear.
import excel "study.xlsx", sheet("Responses") cellrange(A4:C8) firstrow case(lower) clear
describe
save "study-import.dta"
Here, firstrow refers to row 4, because that is the first row of the selected range. It does not mean row 1 of the workbook. The case(lower) option requests lowercase names. These are import choices, not subsequent edits to the observations.
Check the example’s expected result
The rectangle has five rows and three columns. Removing one heading row leaves four observations and three variables: 8 − 4 + 1 − 1 = 4 observations, and columns A through C give three variables. That arithmetic is an acceptance check for this deliberately complete example; it is not a general promise about sheets containing empty rows or unusual layouts.
Confirm that the first identifier is 0012 and that the last score is 20. The row-9 note should be absent. If the import instead starts with a title, includes the note or lacks the first participant, revisit the selected cells before continuing. For a real workbook, write down equivalent checks using its documented structure rather than reusing these fictional counts.
How to read the output
Use describe to examine the dataset’s structure. StataCorp’s manual distinguishes the general dataset information from the description of each variable. Look at the observation and variable totals first, then the names, storage types, display formats and variable labels.
The storage type tells you how a variable is held; the display format governs how it is shown. A variable label supplies descriptive text. These fields answer different questions. In particular, a plausible label is not a substitute for confirming the actual name used by a later command.
For the fictional example, inspect participant_id as text and wave and score as quantities. Do not require one particular numeric storage type merely because an example elsewhere displays it: concentrate on whether the imported representation fits the intended values.
For long names, describe, fullnames prevents abbreviation. For a quick dataset-level summary, describe, short suppresses the per-variable details. Use the full report when diagnosing import problems; a count-only check cannot reveal that a quantity arrived as text.
Successful parsing is only the first checkpoint. In this workflow, an acceptable import also matches the expected records, columns and identifier representation. That is an editorial checking method, not a statistical validation supplied by the import command.
Troubleshooting Stata
Headings appear as observations
Check the range and firstrow together. StataCorp’s real-world example shows that importing a heading row as data can make otherwise numeric columns arrive as strings. Start the selected rectangle at the true headings and use firstrow. Starting one row below the headings while retaining that option risks consuming the first observation as names.
Year columns have letter names
A heading such as 2024 cannot serve as a Stata variable name. StataCorp’s example shows numeric headings being represented by Excel column letters while the original headings remain as variable labels. A source heading such as y2024 avoids that particular naming problem. Inspect the actual names before writing downstream code; see the Stata syntax and command guide for the broader command workflow.
A numeric-looking column imports as text
The current manual says that a column containing nonnumeric text is imported as a string. Inspect entries such as explanatory text embedded among quantities. Keep a record of any correction and its meaning before rerunning the import. An identifier is a different case: numeric-looking characters can be intentionally textual, so conversion to a number is not automatically an improvement.
Leading zeros or dates look wrong
Compare with the source cells. StataCorp’s FAQ warns that Excel can reinterpret entries and that later formatting changes do not necessarily restore the original information. If a code has already lost its zeros in the workbook, changing the Stata import cannot establish what the missing characters were.
The allstring import option forces incoming data to strings; use it deliberately when a text-first inspection is appropriate, then plan any numeric conversion separately. Excel date-formatted numeric cells can instead be imported as Stata dates or datetimes under the manual’s type rules. Inspect the resulting values against known source dates before analysis.
The file is too large or the wrong sheet arrives
The current manual specifies a 40 MB limit for importing .xlsx files. Treat that as an import constraint, distinct from a worksheet’s dimensions. Also name the sheet explicitly: without sheet(), Stata imports the first worksheet. A valid import of a cover sheet is still the wrong input for the intended analysis.
If several sheets represent separate batches, import and check each before combining them. The guide to appending Stata datasets covers the later task of stacking observations; it should follow, rather than replace, the checks on each input.
Free alternatives to Stata
For the Excel-reading stage, R with readxl and Python with pandas provide alternative software routes. The readxl project publishes an MIT license, and the pandas project describes software that users can freely use and modify. These routes read spreadsheet data into their own environments; they do not execute Stata commands.
| Route | Documented import controls | Result to inspect |
|---|---|---|
| R with readxl | read_excel() supports a named sheet and Excel-style range; excel_sheets() lists sheet names. |
A tibble containing the imported table. |
| Python with pandas | read_excel() provides sheet_name, header, usecols and dtype; an appropriate Excel engine is required. |
A DataFrame, or a dictionary of DataFrames for multiple requested sheets. |
The downloadable data table compares the documented parameter names across these routes and Stata. It is a crosswalk, not a translation script. For example, pandas numbers header rows from zero, whereas Stata’s firstrow uses the first row of the selected range. Confirm each program’s conventions when adapting an import.
Expressing the example’s bounds in another program
For the fictional workbook, readxl’s Excel-style range can express the same rectangle directly:
readxl::read_excel("study.xlsx", sheet = "Responses", range = "A4:C8")
In pandas, the corresponding selection separates the header position, columns and number of data rows:
import pandas as pd
data = pd.read_excel("study.xlsx", sheet_name="Responses", header=3, usecols="A:C", nrows=4)
The pandas reference defines header as a zero-indexed row position, so header=3 selects Excel row 4. Its nrows parameter excludes the header from the requested number of rows. Thus the example requests four data rows after the headings, while usecols selects columns A through C.
These snippets illustrate the same intended input geometry in different APIs. They are useful when a collaborator reads the workbook in another language: compare the selected cells first, then inspect the resulting types and values. Agreement about filenames alone does not establish agreement about which part of a sheet was read.
Sources
- StataCorp: import excel — Import and export Excel files, checked 2026-11-17.
- StataCorp: Import and export data from Microsoft Excel, checked 2026-11-17.
- StataCorp: Stata installation guide, checked 2026-11-17.
- StataCorp: describe — Describe data in memory or in a file, checked 2026-11-17.
- StataCorp: How do I get information from Excel into Stata?, checked 2026-11-17.
- StataCorp: Using import excel with real world data, checked 2026-11-17.
- readxl: Read Excel Files, checked 2026-11-17.
- pandas: pandas.read_excel, checked 2026-11-17.
- pandas: About pandas, checked 2026-11-17.
Data: Excel worksheet and range controls across Stata, readxl and pandas
Original crosswalk compiled from the official Stata import excel manual, readxl examples and pandas read_excel reference. It distinguishes named-sheet controls, rectangular ranges and column selection; the controls are not interchangeable commands.
| Import route | Named worksheet control | Cell or column selection | Selection meaning |
|---|---|---|---|
| Stata import excel | sheet("Responses") | cellrange(A4:C8) | An Excel rectangle bounded by starting and ending cells. |
| R readxl::read_excel | sheet = "Responses" | range = "A4:C8" | An Excel-style cell range. |
| Python pandas.read_excel | sheet_name = "Responses" | usecols = "A:C" | An inclusive column selection; row controls are separate. |
Sources
- StataCorp: import excel — Import and export Excel files (accessed 2026-11-17)
- readxl: Read Excel Files (accessed 2026-11-17)
- pandas: pandas.read_excel (accessed 2026-11-17)
Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.







