UCLA Academic Technology Services HomeServicesClassesContactJobs
Help the Stat Consulting Group by giving a gift             
Loading

Stata FAQ
How can I save the contents of the results window?

Stata does not allow you to save the output in the Results window through the menu system. Stata does however offer ways to capture the output and save it to another file. The methods discussed in this page capture all of the output that appears in the Results window, if you want to copy selected parts of the output, the method described in How do I Copy Stata Output and Stata Graphs into Word? may be more appropriate.

Which of the methods described below is more appropriate will depend on the situation. The advantage of the first method, using a log file, is that a log file will capture all of the output from the time you open the file until you close the file, regardless of how much output is produced. The second method, which uses the translate command only captures the output currently in the scroll buffer (i.e. what you can scroll up and see in the Results window), which might not include all of the output you want. For information on how to increase the size of the scroll buffer, see How can I make the Results window hold more results? The advantage of translate is that unlike a log file that has to be opened before you run the commands, translate captures all of the output that has already been produced.

Saving contents using a log file

One way to save all of the results from your Stata session, is to use a log file. As mentioned above, a log file will include all the output produced while the log file is open.

To open a log file called c:\dissert.log, you can type the following at the start of your Stata session:

log using c:\dissert.log

Then, go ahead and run all of your commands. When you are done, you can type:

log close

The results of all of your commands will be saved in the log file (for this example, c:\dissert.log ).

Saving contents using the translate command

The translate command converts all of the output currently in your Results window into a text file. As mentioned above, this is useful if you have run a bunch of analyses and then realize you forgot to start a log file. In the example below, we run a regression analysis and a summarize command. We then use the translate command to output everything from the Results window to a text file, called mylog.txt. The keyword is @Results, which is to say everything from the Results window. At the end, we use type command to show the content of mylog.txt. As you can see, Stata literally dumps everything in the Results window to this file.

use http://www.ats.ucla.edu/stat/stata/notes/hsb2
(highschool and beyond (200 cases))

reg write math female

      Source |       SS       df       MS              Number of obs =     200
-------------+------------------------------           F(  2,   197) =   82.81
       Model |  8165.58839     2  4082.79419           Prob > F      =  0.0000
    Residual |  9713.28661   197  49.3060234           R-squared     =  0.4567
-------------+------------------------------           Adj R-squared =  0.4512
       Total |   17878.875   199   89.843593           Root MSE      =  7.0218

------------------------------------------------------------------------------
       write |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
        math |   .6328663   .0531548    11.91   0.000     .5280407    .7376918
      female |   5.218377   .9975118     5.23   0.000     3.251205    7.185549
       _cons |   16.61374   2.908957     5.71   0.000     10.87705    22.35043
------------------------------------------------------------------------------

sum

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
          id |       200       100.5    57.87918          1        200
      female |       200        .545    .4992205          0          1
        race |       200        3.43    1.039472          1          4
         ses |       200       2.055    .7242914          1          3
      schtyp |       200        1.16     .367526          1          2
-------------+--------------------------------------------------------
        prog |       200       2.025    .6904772          1          3
        read |       200       52.23    10.25294         28         76
       write |       200      52.775    9.478586         31         67
        math |       200      52.645    9.368448         33         75
     science |       200       51.85    9.900891         26         74
-------------+--------------------------------------------------------
       socst |       200      52.405    10.73579         26         71

translate @Results mylog.txt
(file mylog.txt written in .txt format)

type mylog.txt
                                                        ___  ____  ____  ____  ____tm
                                                       /__    /   ____/   /   ____/  
                                                      ___/   /   /___/   /   /___/   
                                                        Statistics/Data Analysis     
      
      
        ___  ____  ____  ____  ____ tm
       /__    /   ____/   /   ____/
      ___/   /   /___/   /   /___/    9.2   Copyright 1984-2006
        Statistics/Data Analysis            StataCorp
                                            4905 Lakeway Drive
                                            College Station, Texas 77845 USA
                                            800-STATA-PC        http://www.stata.com
                                            979-696-4600        stata@stata.com
                                            979-696-4601 (fax)
      
      Notes:
            1.  (/m# option or -set memory-) 1.00 MB allocated to data
      
     1 . cd stata
      d:\DATA\stata
      
     2 . use hsb2
      (highschool and beyond (200 cases))
      
     3 . reg write math female
      
            Source |       SS       df       MS              Number of obs =     200
      -------------+------------------------------           F(  2,   197) =   82.81
             Model |  8165.58839     2  4082.79419           Prob > F      =  0.0000
          Residual |  9713.28661   197  49.3060234           R-squared     =  0.4567
      -------------+------------------------------           Adj R-squared =  0.4512
             Total |   17878.875   199   89.843593           Root MSE      =  7.0218
      
      ------------------------------------------------------------------------------
             write |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
      -------------+----------------------------------------------------------------
              math |   .6328663   .0531548    11.91   0.000     .5280407    .7376918
            female |   5.218377   .9975118     5.23   0.000     3.251205    7.185549
             _cons |   16.61374   2.908957     5.71   0.000     10.87705    22.35043
      ------------------------------------------------------------------------------
      
     4 . sum
      
          Variable |       Obs        Mean    Std. Dev.       Min        Max
      -------------+--------------------------------------------------------
                id |       200       100.5    57.87918          1        200
            female |       200        .545    .4992205          0          1
              race |       200        3.43    1.039472          1          4
               ses |       200       2.055    .7242914          1          3
            schtyp |       200        1.16     .367526          1          2
      -------------+--------------------------------------------------------
              prog |       200       2.025    .6904772          1          3
              read |       200       52.23    10.25294         28         76
             write |       200      52.775    9.478586         31         67
              math |       200      52.645    9.368448         33         75
           science |       200       51.85    9.900891         26         74
      -------------+--------------------------------------------------------
             socst |       200      52.405    10.73579         26         71
      
     5 . translate @Results mylog.txt

How to cite this page

Report an error on this page or leave a comment

UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services


The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California.