Created
May 20, 2014 03:30
-
-
Save bsouthga/188c304727e894834504 to your computer and use it in GitHub Desktop.
LaTeX and Stata integration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Initialize the TeX master source document */ | |
texdoc init test.tex, replace | |
/* Begin stream of LaTeX code */ | |
/*tex | |
\documentclass{article} | |
\usepackage[top=1in, left=1in]{geometry} | |
\usepackage{stata, hyperref, fancyhdr} | |
\setlength\parindent{0pt} | |
\pagestyle{fancyplain} | |
% (LateX Comment) Define new command to add | |
% tables with linked header | |
\newcommand{\addtab}[1]{ | |
\lhead{} \rhead{} | |
\chead{\hyperlink{top}{Back To Top}} | |
\newpage | |
\begin{table} | |
\caption{#1} | |
\centering | |
\input{#1} | |
\end{table} | |
} | |
\begin{document} | |
% Manual title (with a link target), and a line break | |
\thispagestyle{empty} | |
\hypertarget{top}{\textbf{\Large Model Building Example}} | |
\vspace{10pt} | |
Author: Ben Southgate | |
tex*/ | |
/* End Stream of LaTeX */ | |
/* Use Stata global macros to record run time/date */ | |
tex Compiled: $S_TIME, on $S_DATE | |
tex \vspace{20pt} | |
/* Load system data */ | |
sysuse auto, clear | |
/* Clear any current estimation storage macros */ | |
eststo clear | |
tex | |
tex \textbf{\large Sample Restrictions} | |
/* Comments and code after this point will be ouput to | |
LaTeX document in full */ | |
texdoc stlog | |
/* Sample Restrictions */ | |
keep if ( /// | |
weight < 4500 & /// | |
price < 10000 /// | |
) | |
texdoc stlog close | |
/* Now stata code is no longer output */ | |
/* List all the LaTeX tables */ | |
tex \listoftables | |
/* Run regressions and store results */ | |
eststo: reg price mpg rep78 | |
eststo: reg price mpg rep78 headroom trunk | |
eststo: reg price mpg rep78 headroom trunk weight length turn | |
eststo: reg price mpg rep78 headroom trunk weight length turn displacement gear_ratio | |
/* Create LaTeX table to be included in a separate document */ | |
esttab using ModelBuild.tex, tex r2 replace | |
tex \addtab{ModelBuild} | |
tex \end{document} | |
texdoc close | |
/* Stop LaTeX output from requiring manual continuation */ | |
set more off | |
/* Execulte shell commands to compile and open LaTeX output, | |
move the pdf to the output folder, and remove latex junk */ | |
local date = subinstr("$S_DATE _"," ","",.) | |
local time = subinstr("$S_TIME",":","_",.) | |
shell /usr/texbin/pdflatex test.tex | |
shell /usr/texbin/pdflatex test.tex | |
shell mv test.pdf ./output/test`date'`time'.pdf | |
shell open ./output/test`date'`time'.pdf | |
shell rm *test* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment