I am using the command texdoc on stata to generate LaTex code. However, whenever I try running the code using pdfLaTex on TexWorks, I get an error saying that the package stata.sty could not be found when I try to use package stata. The code looks something like:

\section{For Q1}
In this section, we cover the following information:
\item HH availability and consent, by surveyor

I have tried changing document class to statapress and using various other packages such as pagedims and sj, based on suggestions on this forum, but it doesn't seem to help. I also tried installing sjextra on stata, but that doesn't work either. Any suggestions would be greatly appreciated!

Thanks, Smriti

  • Welcome to TeX.SE. I took the freedom to suggest a completion of your MWE. – CampanIgnis Aug 30 '18 at 11:53
  • 1
    I do not know of any package of that name. You might have to install it manually. – CampanIgnis Aug 30 '18 at 11:55
  • CTAN does not about it either, so you'll need to get it from the producer. Is it related to the Stata programme?, i so try their homepage. We see it also with R, their sweave package is also not included on CTAN. – daleif Aug 30 '18 at 12:09

As the stata package and sjlatex are not developed by stata, and are thus not subject to being explained over there, I will provide a tutorial to link the two here. I hope this works out for you, otherwise you can always pay a visit to the link below and you might detect an error in the tutorial or just notice what you did wrong during following this tutorial. Any comments appreciated. If the tutorial becomes outdated, please let me know or feel free to update it. I do not own a recent license of Stata any more, so I probably won't be able to update it myself, I guess.

Linking Stata 14 and MikTeX on Windows

in stata

ssc install texdoc, replace
net from http://www.stata-journal.com/production
net install sjlatex
sjlatex install

in file explorer

  • go to Stata root working directory (e.g. C:\Stata or the one you chose during Stata installation)
    • there you will find the .sty and .cls files pertinent to LaTeX, which you can install to a localtexmf tree
    • if you don't remember what that was, open Stata and type pwd --> your standard directory will be displayed
  • open new instance of file explorer
  • go to C:, open cmd


enter the following commands, which will create directories to mimic the TDS (Original publication, Wikipedia article about it containing further links

mkdir localtexmf\tex\latex\stata
mkdir localtexmf\bibtex\bib\sj
mkdir localtexmf\bibtex\bst\sj

file explorer

  • copy *.sty, *.cls, and sj.version into new directories in accordance with TDS
    • sj.bib into bib
    • sj.bst into bst
  • open "MikTeX Console" (Admin, in case you installed as root)

MikTeX console

  • go to "Settings" > "Directories"
  • click "+" and add C:\localtexmf
  • open "Tasks" and click "Refresh FNDB" and optionally also "Refresh font map files", if you installed the Stata fonts
  • exit MikTeX console

TeX editor or cmd or PowerShell

  • test installation with main.tex provided with sjlatex package
  • if main.tex doesn't work, something is wrong. Don't try with your own file as long as main.tex doesn't work. This file is proved to work. It's like the hello world of stata and TeX.

finally (and very importantly)

check the website http://repec.sowi.unibe.ch/stata/texdoc/index.html for any updates to texdoc

If you are not trying to publish for the Stata journal, but just want to use LaTeX to include Stata code and examples in your duckuments, it is recommended to use texdoc instead of sjlatex, sj.cls, and sj.bib. You should check out the introductory tutorial by the texdo developer found at https://www.stata.com/meeting/switzerland16/slides/jann-switzerland16.pdf for help to get started with texdoc.


I don't compile stata-texdoc file on my Linux machine, but the process is very similar, except that you can't install stata on Linux and thus don't need to install texdoc in Stata for Linux (which doesn't exist). I don't compile stata-texdoc file on my Linux machine, so, I won't provide a tutorial for it. It would be hit or miss. You're welcome to add your Linux tutorial here or as a separate answer.



How can I manually install a package on MiKTeX (Windows)

Purpose of local texmf trees

Not the answer you're looking for? Browse other questions tagged or ask your own question.