UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

Stata FAQ
How can I translate a file into a Postscript file?

Sometimes you might want to convert a file into a postscript file. For example, you might want to convert the Stata help file on regress command into a postscript file so you can read it any time you want even without Stata. Or you might want to convert the output to the Result window into a postscript file. Here are some examples on converting different types of Stata files into postscript files.

Example 1 - Converting a help file into a postscript file

We want to study iverg command and would want to convert the help file into a postscript file. Here is what we can do. First, we have to locate the physical location of the help file for ivreg command. We use the Stata command findfile. One of the features of this command is that it stores the path in a macro variable. So we can do a "return list" to see what is being stored. The last thing is to "translate" the help file into a postscript file named ivreg.ps.

findfile ivreg.hlp
C:\stata9\Stata9\ado\base/i/ivreg.hlp

return list

macros:
                r(fn) : "C:\stata9\Stata9\ado\base/i/ivreg.hlp"

translate "`r(fn)'" ivreg.ps, translator(smcl2ps)
(file ivreg.ps written in PostScript format)

Example 2 - Converting the output from Results Window to a text file

Let's say that you have run a bunch of analyses and then you realize that you forgot to open a log file to capture all the results. Stata offers a neat and simple solution with the translate command. In the example run below, we have 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

Example 3 - Converting the output from Results Window to a postscript file

Following the previous example, if you want to convert the output from the Results Window directly to a postscript file, instead of a text file, you can do it in a similar way. Here it is. We need to tell Stata the translator to use is from Results to postscript by using the option trans(Results2ps). That is all to it. The postscript file myout.ps is created as we have expected.

translate @Results myout.ps, trans(Results2ps)
(file myout.ps written in PostScript format)

Example 4 - Converting any text file into postscript file

Let's say that you want to convert a text file into a postscript file, it can be actually any text file. You can use Stata's translate command to convert it to a postscript file. Here is an example. Earlier on, we have saved a text file called test.out with the result of a regression analysis using the estout command. We used the type command to display the content of this text file. Next we used  translate command to convert it to a postscript file.

type test.out
        writing score
math score      0.400
        (5.53)**
reading score   0.307
        (4.61)**
ses==2  -0.922
        (0.72)
ses==3  -0.032
        (0.02)
Constant        16.108
        (5.20)**
Observations    200
R-squared       0.45
Test1 F 0.54
Test2 F 0.53
Absolute value of t statistics in parentheses   
* significant at 5%; ** significant at 1%       
translate test.out test.ps, trans(txt2ps) replace
(file test.ps written in PostScript format)

This is how it looks in the postscript file format.



How to cite this page

Report an error on this page

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