Internet Guide to Stata |
Print article |
All Stata output is displayed, not surprisingly, in the output window (which is called Results window by Stata Corp). Here's a few helpful remarks:
To keep record of Stata's output, you have to specify a log file. In other words, by default the output is shown in the output window only. Note that you have to open the log file before output can be written to it. In other words, you cannot save output to a log file a posteriori. (Note, however, that there is some sort of workaround; see the following section.)
There are two formats for the log file, the SMCL format (a specific Stata format, as far as I know) and the text or plain ASCII format. Stata recommends to use the SMCL format, as it keeps some formatting that is helpful when looking at the file with the Stata viewer; it is therefore the default format. If you are sure you do not need this, the text format is better for accessing the log file with other software such as a word processor. However, you can also "translate" an SMCL file into a text file.
log using session20090213
causes Stata to write your commands and Stata's results into file session20090213.smcl, that is, a file in SMCL format.
log using session20090213.log
causes Stata to write your commands and Stata's results into file session20090213.log, which will be in text or plain ASCII format.
The file will be found in your working directory. If you have started Stata from the desktop, the default is a directory named \data. But you may have changed to a different directory; in this case you will find the log file there. You probably may also indicate a path for the log file.
Once you have opened a log file, you may temporarily suspend the output being written to it by
log off
Not surprisingly, to have further output written to the log file you have to switch
log on
A different thing is to close a log file with
log close
To have further output written to a log file, you have to specify again a log file with "log using....". It is important to know whether this file already exists and how you wish to handle this.
log using session20090213, replace
will overwrite the old file and start anew.
log using session20090213, append
will append the new output to the already existing file.
The results may either printed or opened with a word processor. For the latter purpose, the output has to be translated if you have used the SMCL format:
translate session20090213.smcl session20090213.log
Finally,
view session20090213
will open the Stata viewer and display the log file named session20090213.
First, you can always copy the output directly from the screen to some other file, e.g., in a text processor.
Second, there is a nice feat which permits to save your results, as long as they are accessible in the results windows. It goes like this:
translate @Results "name-of-some-file.txt"
Now, Stata will write everything that can be found in the scroll buffer (equivalent to everything you can see on your screen, including those parts you have to scroll in order to see them) in a txt-File with the name "name-of-some-file". I.e., this file will not be in Stata format, but as the txt-File is universally accessible, there is nothing to worry about this.
You may open several log files (up to five in SMCL and in text format, respectively). If I have found out how to do this (which I will do when I think I need several log files), I will tell you.
You may set the default log file type via "set logtype". With
set logtype t
("t" may be replaced by "text"), the default will be the text format. With
set logtype s
("s" may be replaced by "smcl"), the default will be the scml format again.
set logtype t, perm
will induce Stata to remember this setting the next time it is started.
A number of user-written packages are available for translating Stata output into other formats, such as LaTeX, HTML or Word. I'm afraid there is no "one size fits all" solution. So, you might try one or several of the packages listed below. You have first to obtain these packages via findit name-of-package [e.g., findit outtex]; afterwards, you can get information via help name-of-package. Most of these are, as you may guess, for LaTeX.
latab | produces a LaTeX-usable output for tables, but in the case of a simple frequency table, you cannot obtain cumulated percentages. With a crosstabulation, you can generate either counts or colum percentages or row percentages, but not two or three of these in one table. |
latabstat | produces a LaTeX file for the output of procedure tabstat. |
tabout | is quite complex; there is a tutorial, but be prepared to spend some time reading it. Vital information, such as required additions to the LaTeX preamble, comes near the end! Still, as yet I was not able to make the examples from the tutorial work on my LaTeX system. Will also produce output for HTML and Word. |
maketex | is very simple, but it does not help much, as it just takes your piece of output as it is and puts a LaTeX preamble at the beginning and the \end document command at the end of the file. |
outtex, outreg2, est2tex, estout | basically for output from estimation procedures. |
corrtex | for correlations. |
graph2tex | creates an .eps file from the most recent graph plus some LaTeX code to embed the graph into your Latex file. |
sutex | for summary statistics. |
outtable | despite appearances, it is not for tables, but for matrices. |
Brief explanations of some of these packages may be found in Florent Bresson's Outils Stata pour LaTeX.
All of Stata's estimation commands (and some others) store many elements that are part of the output or that are used during computation in the computer's memory; they remain available until the next procedure produces new elements to be stored. These elements may be single numbers (called "scalars" in matrix language), matrices, or strings. You can access them via
ereturn list
You will note that those elements that are found under the rubric "matrices" are not displayed; what is displayed is the format of the matrices, e.g., 7 x 7 for the variance-covariance matrix of estimates in a regression model with six predictors (the seventh item is the constant of the model). Matrices are displayed with the help of the matrix list command. For instance, from ereturn list (or from the help function) you may have learned that the variance-covariance matrix is stored in matrix e(V). So, just type
matrix list e(V)
to obtain the entire matrix.
© W. Ludwig-Mayerhofer, Stata Guide | Last update: 15 Jul 2015