Home  /  Resources & support  /  FAQs  /  Getting information from Excel to Stata
Note: This FAQ applies to older versions of Stata; in particular, Stata 4.0 and earlier. It does not apply to the current version.

How do I get information from Excel into Stata?

Title   Getting information from Excel to Stata
Author StataCorp

If you have a data transfer package, then use that to create a Stata dataset. If you do not have a data transfer package, but you do have Excel, then follow the steps below.

Here are the steps to follow in order to save numeric data from Excel and then read it into Stata. This will not work if any of the columns contain string information.

  1. Launch Excel and read in your Excel file.
  2. Save this file as a text file using the Save As menu item under the File menu. If the original filename is filename.xls, then save the file under the name filename.raw in the C:\DATA directory.
  3. Quit Excel.
  4. Use the File Manager or DOS to copy filename.raw to the file filename.do.
  5. Use a text editor (Notepad) to open the file filename.raw. Delete the first line of variable names (or column names). Save the file.
  6. Use a text editor (Notepad) to open the file filename.do. Delete everything except the first line of variable names (or column names).
  7. If there are commas separating the variable names, remove them.
  8. Add the word infile to the very beginning of that first line.
  9. Add the words using filename where filename is the name of the file that you are converting (without an extension) to the very end of the line.
  10. Ensure that all material is on one physical line (some editors will wrap lines).
  11. Save the file.
  12. Launch Stata if it is not already running. If it was already running, then clear the data (save it if you need to).
  13. In Stata, type do filename where filename is the name of the file that you are working on.
  14. In Stata, type compress.
  15. Save the data as a Stata dataset using the save command.
Note:   If you do not have a data transfer package and you do not have Excel, then you cannot get your data into Stata. You will need either Excel so that you can save the data into a text file, or the transfer package to directly transfer the Excel file to Stata format.