Skip Navigation

UNC Carolina Population Center

 

Getting Stata output into Excel, Power Point, MS-Word, Word Perfect


Since many different software packages (e.g. Power Point) read in Excel spreadsheets this tutorial is focused on getting your Stata results into Excel spreadsheets. Once you have your results in an Excel spreadsheet you are ready to either use Excel to format the table or create the graph, or bring the results into some other software. There are ways to create graphs and to format your results in Stata, but most people are already familiar with doing all that with one of these 4 software packages.

There are at least 5 ways to get your results out of Stata and into Excel using native Stata commands.

(Additional commands, available free from the SSC archives, are listed below.)

No matter which way you choose, it's always a good idea to check that the process did what you expected.

From the Stata results window:


#1 - Select text in Stata and paste into Excel.


From a log file:


#2 - Select text in Stata  log window and paste into Excel.

#3 - Open the log file (*.log) in Excel as fixed width file.

TIP: Make use of Stata's ability to start and stop logging to a log file so that your log file contains only one table of results. It's easier to have multiple log files with one table per file than multiple tables and other code in one big log file.

use "t:\statatut\examfac2.dta"
log using "test1.log", replace
svyprobt age factype authorit urbrur femster
log close

log using "test2.log", replace
svyreg q103_1 age urbrur authorit factype
log close


From a Stata data set:

First you need to learn how to save your results in a Stata data set. The parmest command is designed to do this. You may be able to use the collapse command if you want summary statistics such as the mean or percentiles. Once you have your results in a Stata data set you can try either of the following two methods.

A benefit to having your results in a Stata data set is that you can use your Stata data management skills to manipulate them to your liking (e.g. drop certain columns from your results) before you bring them into Excel. Either of these two methods becomes more helpful when creating a lot of tables.


#4 - Use DBMScopy to convert a Stata data set to an Excel spreadsheet.

#5 - Use the outsheet command to output a spreadsheet that can be read into Excel.


#1- Select text in Stata and paste into Excel.

- Highlight to select the output in Stata's results window.
- Shift-Ctrl-C (or right click, Copy Table)
- Paste selection into Excel.
Back

#2- Select text in Stata log window and paste into Excel.

- View the log file (*.log or *.smcl) in the Stata viewer.
- Highlight to select what results you are interested in.
- Shift-Ctrl-C (or right click, Copy Table
- Paste selection into Excel.
Back

#3- Open a log file (*.log) into Excel as a fixed width file:

- Close and save your log file.
- Open Excel.
- Click the open folder in the tool bar to open a new file.
- Excel's default is to look for *.xls files, change that to All Files (*.*).
- Find your log file.
- Double click your file. Excel starts by putting your file in a Text Import Wizard.
- Choose Fixed width as data type.
- Click the Next> button.
- Excel tries to figure out what would be good columns. You can change them by clicking where you want one, or double clicking one to delete it, or grabbing one with your mouse and moving the vertical line to where you want it.
- Scroll down to view the file to check that the columns are where you want them. If a line goes through the middle of a number, the number will be spread over two cells.
- When satisfied with the column set-up click Next>.
- In this window Excel highlights the first column and suggests importing it as a General data format. If you import your results and Excel somehow changes the format or the data, try changing from General to Text. Excel's Help may be able to assist you further.
- If you want to change the data format of another column click Next>, otherwise click Finish.
- Once the file is in Excel, do a Save As to save as an Excel (*.xls) file. If you do not want to use Excel to create your tables then you can either highlight, copy your results and paste them into some other software or, after saving the file as an Excel spreadsheet, read the file directly into some other software.
Back

#4- Use DBMScopy to convert the Stata data set to an Excel spreadsheet:

CPC has DBMScopy on unix as well as on the Windows network. Click here for instructions on how to use DBMScopy interactively.

The basics of this method is to generate a Stata data set that contains the results you want to make into a table. DBMScopy can make an Excel copy of the data set. This Excel file can be read into Excel, Power Point, MS-WORD, Word Perfect.

Back

#5 - Use the outsheet command to output a spreadsheet that can be read into Excel.

This method requires that you start with your results in a Stata data set.
- Open the results data set in Stata.
- Type the following in a command line or in a do-file:
/* Create tab delimited text file */
outsheet using "results1.txt", replace
By default the outsheet command creates a tab delimited file. Excel will need to use the Import Text Wizard to open the file (see the fixed width example ).
If you create a comma separated values (*.csv) file, Excel will read in a comma separated file without putting you through the Text Import Wizard.
/* create comma separated values text file */
outsheet using "results1.csv", comma replace
- Open Excel.
- Click the open folder in the tool bar to open a new file.
- Excel's default is to look for *.xls files, change that to Text Files (*.prn; *.txt; *.csv).
- Find your comma separated values (*.csv) data file.
- Double click your file. Excel opens the file just like a normal *.xls file.
Back

There are at least 3 ways to get your results out of Stata and into MS Word or Excel using user-contributed commands.

These have been installed at CPC. If you need them for your laptop or home computer, you may download them using the ssc command. For example, ssc describe xml_tab will give you the details, and ssc install xml_tab will install the package.

The discussion below is brief, intended only to point you to the command you might need. See the help for each command for details.

tabout

The tabout command produces publication-quality cross tabulations. Lots of features are available to customize the table. The output file may be in tab-delimited or html format. Tab-delimited format files may be copied into Word and converted into a table using the Table menu (Table, Convert, Text to table). Html format files can be opened in your browser and copied. Inside Word, use Paste Special and paste the table as Formatted Text (rtf).

estout

The estout command produces regression tables from stored estimates. All modeling commands in Stata put the results (such as beta coefficients) into temporary variables. These can be stored for use by the estout command. The output file may be tab, fixed, Tex, or html. Tab-delimited format files may be imported into Excel using the Import Wizard. Html format files can be opened in your browser and copied. Inside Word, use Paste Special and paste the table as Formatted Text (rtf).

xml_tab

Like estout, the xml_tab command works from stored estimates. The output is in Excel's xml format. This format allows for a very feature-rich table that takes advantage of many of Excel's capabilities. To open the file in Excel simply click on File, Open. If xml_tab can locate Excel on your computer, it will create a link in the Stata Results window from which you can open the file.

Review Again?
Another topic?
Questions or comments?  If you are affiliated with the Carolina Population Center, send them to Phil Bardsley.