### Stata Journal Style in LaTeX

• Installation - installing Stata Journal style LaTeX files
• An Example - Output with Stata Journal style in a LaTeX file

Installation

Stata has created a suite of LaTeX files for creating LaTeX documents in the Stata Journal style. In this page we will show how to install the Stata LaTeX package to MikTeX and how to use it in a LaTeX file. Let's assume that we have the following:

• Connection to the internet
• Stata 7 or above
• MiKTeX for generating and compiling LaTeX files

Step 1: In Stata, in Stata Command window, issue command  "findit  sjlatex". This will bring the Viewer window. Click on a link that points to sjlatex. Then click the link to install it.

Step 2: This step is an important step. It will perform installing Stata's package of Stata Journal style LaTeX files. It is strongly recommended that the package is installed within the folder where all the other LaTeX style packages are in. This will make the last step a lot easier, that is to make the linkage of the Stata Journal style to a LaTeX document.

When MiKTeX is installed, many folders are created for placing different types of files. For example, a folder called \texmf\tex\latex is created for placing all the style files for LaTeX document. We will therefore install Stata Journal style LaTeX files to a subfolder called sjlatex inside folder \texmf\tex\latex. You don't have to create the subfolder yourself. Stata will create it for you. If the folder \texmf\tex\latex\sjlatex already exists, you can use the "replace" option to force the installation process.

In Stata, we do:

sjlatex install using d:\texmf\tex\latex\sjlatex
Updating Stata Journal LaTeX files...
Stata Journal LaTeX files
folder:             d:\texmf\tex\latex\sjlatex
installed release:  (unknown)
. pwd
d:\texmf\tex\latex\sjlatex
view sjstart.smcl for Getting Started instructions.

Here is a screen shot of all the files installed to the folder.

Step 3: Choose MiKTeX Options from MiKTeX menu. You will see the following window:

Click on the Refresh Now button and the Update Now button. When it is done, click on Apply button. This finishes the installation process.

Now you can use Stata Journal style in your LaTeX file.

Example

Stata Journal style consists of output in Stata log format, graphics in Stata graph format and general text. We will show some examples here on how to produce these different types of Stata Journal style formats.

In this example, we are going to show how to create a text file containing the LaTeX code for creating a Stata log style text. To create Stata log style is extremely easy.  Stata command sjlog can be used first to create a log file in Stata Journal style. There are then two ways to create the LaTeX file. One way is to include the file created by sjlog in a LaTeX file and use stlog environment around it. The other way is to use sjlog again with the type option to display the LaTeX code in Stata's Results Window and copy and paste it to a LaTeX file. For example, to create the output from command describe in Stata Journal LaTeX style, we can do the following:

use http://www.ats.ucla.edu/stat/stata/notes/hsb2
(highschool and beyond (200 cases))
sjlog using desc_hsb2
describe
Contains data from http://www.ats.ucla.edu/stat/stata/notes/hsb2.dta
obs:           200                          highschool and beyond (200
cases)
vars:            11                          20 Jun 2000 14:13
size:         9,600 (99.1% of memory free)
-------------------------------------------------------------------------------
storage  display     value
variable name   type   format      label      variable label
-------------------------------------------------------------------------------
id              float  %9.0g
female          float  %9.0g       fl
race            float  %12.0g      rl
ses             float  %9.0g       sl
schtyp          float  %9.0g       scl        type of school
prog            float  %9.0g       sel        type of program
write           float  %9.0g                  writing score
math            float  %9.0g                  math score
science         float  %9.0g                  science score
socst           float  %9.0g                  social studies score
-------------------------------------------------------------------------------
Sorted by:  
sjlog close
(note: file e:\xiao_usb\stata2latex\desc_hsb2.smcl.bak not found)
sjlog type desc_hsb2.log.tex
. describe
{\smallskip}
Contains data from http://www.ats.ucla.edu/stat/stata/notes/hsb2.dta
obs:           200                          highschool and beyond (200
cases)
vars:            11                          20 Jun 2000 14:13
size:         9,600 (99.1\% of memory free)
\HLI{79}
storage  display     value
variable name   type   format      label      variable label
\HLI{79}
id              float  \%9.0g
female          float  \%9.0g       fl
race            float  \%12.0g      rl
ses             float  \%9.0g       sl
schtyp          float  \%9.0g       scl        type of school
prog            float  \%9.0g       sel        type of program
write           float  \%9.0g                  writing score
math            float  \%9.0g                  math score
science         float  \%9.0g                  science score
socst           float  \%9.0g                  social studies score
\HLI{79}
Sorted by:  

We copy and paste the code above to a LaTeX file and here is the pdf file corresponding to it.

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.