You can try using a listing. First, choose Insert --> Program listing, which will give you a box. With the cursor inside this box, choose Insert --> File --> Plain text, and select the text file.
You can change the settings (fonts etc.) for one such box by right clicking inside it and clicking Settings, or globally by going to Document --> Settings --> Listings. You can get a list of all available parameters in LyX by writing a question mark (as mentioned in the settings dialog), or refer to the listings
manual, where they'll also be explained.
With default settings:
You were on the right track, but you did not follow the Jörg's instructions completely.
First make sure that you add Jörg's preamble into your document preamble (in LyX: Document > Settings > Latex-Preamble):
% Packages for tables
\usepackage{booktabs}% Pretty tables
\usepackage{threeparttablex}% For Notes below table
% *****************************************************************
% siunitx
% *****************************************************************
\newcommand{\sym}[1]{\rlap{#1}} % Thanks to Joseph Wright & David Carlisle
\usepackage{siunitx}
\sisetup{
detect-mode,
group-digits = false,
input-symbols = ( ) [ ] - +,
table-align-text-post = false,
input-signs = ,
}
% Character substitution that prints brackets and the minus symbol in text mode. Thanks to David Carlisle
\def\yyy{%
\bgroup\uccode`\~\expandafter`\string-%
\uppercase{\egroup\edef~{\noexpand\text{\llap{\textendash}\relax}}}%
\mathcode\expandafter`\string-"8000 }
\def\xxxl#1{%
\bgroup\uccode`\~\expandafter`\string#1%
\uppercase{\egroup\edef~{\noexpand\text{\noexpand\llap{\string#1}}}}%
\mathcode\expandafter`\string#1"8000 }
\def\xxxr#1{%
\bgroup\uccode`\~\expandafter`\string#1%
\uppercase{\egroup\edef~{\noexpand\text{\noexpand\rlap{\string#1}}}}%
\mathcode\expandafter`\string#1"8000 }
\def\textsymbols{\xxxl[\xxxr]\xxxl(\xxxr)\yyy}
% *****************************************************************
% Estout related things
% *****************************************************************
\let\estinput=\input % define a new input command so that we can still flatten the document
\newcommand{\estwide}[3]{
\vspace{.75ex}{
\textsymbols% Note the added command here
\begin{tabular*}
{\textwidth}{@{\hskip\tabcolsep\extracolsep\fill}l*{#2}{#3}}
\toprule
\estinput{#1}
\bottomrule
\addlinespace[.75ex]
\end{tabular*}
}
}
\newcommand{\estauto}[3]{
\vspace{.75ex}{
\textsymbols% Note the added command here
\begin{tabular}{l*{#2}{#3}}
\toprule
\estinput{#1}
\bottomrule
\addlinespace[.75ex]
\end{tabular}
}
}
% Allow line breaks with \\ in specialcells
\newcommand{\specialcell}[2][c]{%
\begin{tabular}[#1]{@{}c@{}}#2\end{tabular}
}
% *****************************************************************
% Custom subcaptions
% *****************************************************************
% Note/Source/Text after Tables
% The new approach using threeparttables to generate notes that are the exact width of the table.
\newcommand{\Figtext}[1]{%
\begin{tablenotes}[para,flushleft]
\hspace{6pt}
\hangindent=1.75em
#1
\end{tablenotes}
}
\newcommand{\Fignote}[1]{\Figtext{\emph{Note:~}~#1}}
\newcommand{\Figsource}[1]{\Figtext{\emph{Source:~}~#1}}
\newcommand{\Starnote}{\Figtext{* p < 0.1, ** p < 0.05, *** p < 0.01. Standard errors in parentheses.}}% Add significance note with \starnote
You said you did that but Jörg made some refinements in his follow-up posts. I took this from his sample document. Note that I included the threeparttablex
package instead of threeparttable
, since the former also supports longtable
(for tables spanning more than one page, should you need that). For this example, however, this does not matter.
e-birk is right that not everyone has access to Stata, but for those that do, it helps to add a MWE that makes use of the example datasets installed with Stata (help sysuse
). So I adjusted your example like this:
sysuse auto
regress mpg weight length foreign, robust // specification with 'foreign'
eststo C1
regress mpg weight length, robust // specification without 'foreign'
eststo C2
regress price weight length foreign, robust // specification with 'foreign'
eststo C3
regress price weight length, robust // specification without 'foreign'
eststo C4
Now export the table from Stata as a fragment and without the table notes (we add these later into the LaTeX/LyX document). The right esttab
command should be something like this:
esttab C1 C2 C3 C4 using test_tex, booktabs fragment replace ///
se(%3.2f) b(3) label indicate(Controls=foreign) ///
star(* 0.1 ** 0.05 *** 0.01) nonotes nomtitles drop(_cons) ///
mgroups("mpg" "weight", pattern(1 0 1 0) ///
prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))
Note that I added the fragment option. I also reformated the command a little. This way you can just add , ///
before using
in the first line to test your table in Stata first (e.g. to see whether labels are correct, etc.).
Finally, include the table in LyX with this (adjust accordingly):
\begin{table}\centering
\begin{threeparttable}
\caption{Table with Better Notes and Better Symbols}
\estauto{test_tex}{4}{c}
\Figtext{Some basic text about the table.}
\Fignote{Standard errors corrected for heteroskedasticity in brackets. \\
\textit{* p < 0.10, ** p < 0.5, *** p < 0.01}}
\Figsource{auto.dta (Stata example dataset)}
% \Starnote
\end{threeparttable}
\end{table}
You can insert this into your LyX document with Evil Red Text (Insert > Tex-Code) or use a .tex document and insert that as a file into your document.
I added the p-value note directly, but you could also use the \Starnote
command (useful if you have multiple tables with the same p-symbols). Adjust the p-values on the last line of the preamble accordingly.
I also used the center alignment {c}
in \estauto{test_tex}{4}{c}
instead of the decimal alignment {S}
, since the latter seems to choke on the Controls row. I am not very familiar with the siunitx
package, so I might be wrong here or there might be an easy fix.
Obviously, this is mostly Jörg's code, he deserves the credit.
Best Answer
Since STATA seems to be able to provide text output, use the
minted
orlistings
packages to display the content of the STATA file in your document, as it could be done for source code.More specifically, with the
listings
package, do something likeSee this website for more information