\documentclass{article} \usepackage[margin=1in]{geometry} \usepackage{mathpazo,color} % Special formatting for chunks and output \StataweaveOpts{codefmt="formatcom=\color{blue}", outfmt="frame=single"} \begin{document} \section*{Stata Test} We'll look at the dataset they seem to use for all examples in the Stata manual: \begin{Statacode} sysuse auto summ mpg disp \end{Statacode} There are \Stataexpr{r(N)} observations and the maximum displacement is \Stataexpr{r(max)}. And here is a \textbf{\Stataexpr{`"`="more"+""+" complicated"'"'}} expression. \paragraph{Backward-compatibility test} Note: Pre-2012 versions of the Stata engine used '\verb"egen"' to eveluate expressions. This has changed. We now just pass the expression to '\verb"display"'. If you want backward compatibility, set the \verb"egen" option, as shown here: \StataweaveOpts{egen=TRUE} The maximum displacement is \Stataexpr{max(disp)}. % revert to new behavior: \StataweaveOpts{!egen} \paragraph{Moving on\ldots} Let's generate new variables and fit a regression model. Also test the continuation prompt \begin{Statacode}{cont=" "} gen gp100m = 100/mpg gen for_disp = foreign*displacement label var gp100m "Gallons per 100 miles" regr gp100m /// This line continues foreign disp /// and yet again for_disp // no more display "We're done" \end{Statacode} And here is a nice plot of the results \begin{Statacode}{fig, hide, height=4.5in, width=9in, dispw=4in} predict g_hat twoway (scatter gp100m disp) (line g_hat disp, sort), by(foreign) \end{Statacode} \subsection*{Using Mata} Let's try some matrix stuff, in case it Matas to you. \begin{Statacode}{outfmt="fontsize=\footnotesize"} mata pr = st_data(.,("price")) printf("Price in thousands\n") pr' / 1000 \end{Statacode} The variable \texttt{pr} has \Stataexpr{rows(pr)} elements and the maximum price is \$\Stataexpr{max(pr)}. \begin{Statacode} end disp "Now we are back in interactive mode" \end{Statacode} \subsection*{Using a \texttt{do} file} When you run a \texttt{do} file, the commands therein are displayed along with the output: \begin{Statacode} do simpy.do \end{Statacode} \end{document}