I have a matrix of values (very non-standard summary statistics) that I want to pass from Stata to LaTeX. The command:
esttab matrix(matname) using $myfilename.tex, replace booktabs f
gives the matrix in LaTeX form but also gives the title of the matrix within the fragment. The same is true for:
outtable using myfilename, mat(matname) replace nobox
Currently, every time I rerun my Stata do file I have to go and edit myfilename.tex by hand.
Is there any way to non-manually remove the matrix name from the Stata to LaTeX output?
I tried using the option noheader, which works here:
matrix list matname, noheader
but doesn't seem to be active in esttab or outtable. It also occurred to me that if I could find a way to ask LaTex to just \input PART of the fragment file (lines 2 onward) that would work...
I think the nomtitles option will work. Here's reproducible example:
sysuse auto
reg price trunk headroom
matrix myMat = e(V)
esttab matrix(myMat) using temp.tex, replace booktabs f nomtitles
This produces the text (.tex) file below:
& trunk& headroom& \_cons\\
\midrule
trunk & 10557.96& -35339.31& -39464.18\\
headroom & -35339.31& 269901.5& -321726.7\\
\_cons & -39464.18& -321726.7& 1612951\\
Also, I used the following outtable command
outtable using "./temp", mat(myMat) replace center f(%9.2f) nobox
to produce this output:
% matrix: myMat file: ./temp.tex 10 Jun 2016 12:55:35
\begin{table}[htbp]
\begin{tabular}{lccc} \hline \hline
& trunk & headroom & cons \\ \hline
trunk & 10557.96 \\
headroom & -35339.31 & 269901.52 \\
cons & -39464.18 & -3.22e+05 & 1.61e+06 \\
\hline \hline \end{tabular}
\end{table}
While the matrix name is present in the output, it is commented out and so will not appear in the latex document.
Related
I am trying to produce financial statements with latex. An important convention of financial statements is that negative numbers are not presented with a negative sign, rather wrapped in parentheses, like this:
-100 -> (100)
The minimum necessary recreation of my issue is as follows:
\documentclass{report}
\usepackage{tabularx}
\usepackage{spreadtab}
\usepackage{numprint}
\npthousandsep{,}
\begin{document}
\begin{center}
\STautoround{0}
\begin{spreadtab}{{tabularx}{\linewidth}{XN{7}{0}N{7}{0}}}
#\multicolumn{3}{c}{\uppercase{Municipal Government}}\\
#\multicolumn{3}{c}{Statement of Net Position}\\
#\multicolumn{3}{c}{December 31, 2019}\\
&& \\
#\multicolumn{1}{c}{\uppercase{Assets}} & #\multicolumn{1}{c}{2019} & #\multicolumn{1}{c}{2018}\\
#\multicolumn{1}{c}{Current Assets}&&\\
# Cash & 12345 & 54321\\
# Receivables:&&\\
# \hspace{0.25in}Sewer Fees: & 12345 & 54321\\ \cline{2-3}
#\multicolumn{1}{r}{Total Current Assets} & sum(b7:[0,-1]) & sum(c7:[0,-1])\\ % r10
#\multicolumn{1}{c}{\uppercase{Fixed Assets}}&&\\
# Land & 12345 & 54321\\
# Garage & 99247 & 54321\\
# Equipment & 12345 & 54321\\
# Lagoon and Related & 12345 & 54321\\ \cline{2-3}
#\multicolumn{1}{r}{Total Fixed Assets} & sum(b12:[0,-1]) & sum(c12:[0,-1])\\ \cline{2-3} % r15
# Accumulated Depreciation & -12345 & -54321\\ \cline{2-3}
#\multicolumn{1}{r}{Net Fixed Assets} & sum(b16:[0,-1]) & sum(c16:[0,-1])\\ \cline{2-3}
#\multicolumn{1}{r}{Total Assets} & b18+b10 & c18+c10\\ \cline{2-3} \cline{2-3}
\end{spreadtab}
\end{center}
\end{document}
Where rather than Accumulated Depreciation -12345 -54321, it reads Accumulated Depreciation (12345) (54321).
I have found scant little information about it online, and I'm not entirely certain it's possible to do.
If at all possible, I would like to retain the decimal alignment while adding the parentheses. But again, I'm not sure it's possible.
A solution, below, was shared on StackOverflow several years ago, but it concludes in several errors which I am unsure how to move beyond: primarily the compiler complaining about dozens of "missing" or "extra" brackets.
\makeatletter
\renewcommand\STprintnum[1]{\FPifneg{#1}(\#gobble#1)\else#1\fi}
\makeatother
Update: Per the below answer, using SIunitx permits wrapping negative numbers in brackets, but this breaks the decimal alignment. A minimum working example of this is as follows:
\documentclass{report}
\usepackage{tabularx}
\usepackage{siunitx}
\usepackage{spreadtab}
\sisetup{group-separator = {,}}
\sisetup{bracket-negative-numbers = true}
\begin{document}
\begin{spreadtab}{{tabularx}{\linewidth}{XS[table-format=7.1]S[table-format=7.1]}}
# Fixed Assets & 123456.1 & 135791.1\\
# {Accumulated Depreciation} &-100000.1 &-90000.1\\ \cline{2-3}
#\multicolumn{1}{r}{Net Fixed Assets} & sum(b1:[0,-1]) & sum(c1:[0,-1])\\ \cline{2-3}
\end{spreadtab}
\end{document}
In the above example, the negative numbers are now offset in their alignment by the left and right parenthesis, so they cease to line up with the positive numbers.
I am trying to insert vertical and horizontal lines inside a matrix to divide it into 4 sections. I would like my matrix to look matrix 4.7 in Matrix Population Models by Dr. Caswell.
Please see my try below. How do I improve the code? Thanks a lot in advance.
$$A_{m,4} =
\begin{pmatrix}
a_{1,1} & a_{1,2} | & a_{1,3} & a_{1,n} \\
a_{2,1} & a_{2,2} | & a_{2,3} & a_{2,4} \\
----- | ----\\
a_{m,1} & a_{m,2} & a_{m,3} & a_{m,4}
\end{pmatrix}$$
You can use the following latex code in your RMD file:
$$A_{m,4} =
\left(
\begin{array}{cc|cc}
a_{1,1} & a_{1,2} & a_{1,3} & a_{1,n} \\
a_{2,1} & a_{2,2} & a_{2,3} & a_{2,4} \\
\hline
a_{m,1} & a_{m,2} & a_{m,3} & a_{m,4}
\end{array} \right)$$
The result:
I am working on a protocol using TeXMaker. I switched from Eclipse+Texlipse to Texmaker and what compiled successfully before, does not compile anymore.
I have a main.tex file, which contains the structure of my protocol. I have several tex-files as inputs and a design.sty, which provides my design. I want to compile and create the PDF-protocol.
When I try to execute the following code in TeXMaker (the main.tex):
\documentclass[11pt,a4paper,oneside,listof=totoc, bibliography=totoc
version=first]{scrreprt}
\usepackage{design}
\begin{document}
\pagenumbering{arabic}
% cover
\input{./cover.tex}
% introduction
\newpage
\chapter{Introduction}
\section{Synmikro}
\input{./synmicro.tex}
\section{Genetic Switches}
\input{./switches.tex}
\section{ECFs}
\input{./ECF.tex}
\section{Sinorhizobium Meliloti}
\input{./meliloti.tex}
\newpage
\section{Laboratory Internship}
\input{./internship.tex}
\section{Bioinformatics}
\input{./bioinfo.tex}
% materials and methods
\newpage
\chapter{Material and Methods}
\section{Used strains}
\input{./MMexoECFs.tex}
\section{Cultivation conditions}
\input{./MMcultivation.tex}
\section{RNA preparation}
\input{./MMrNAprep.tex}
\section{Quality control of total RNA}
\input{./MMtotalRNAQC.tex}
%\section{Quality control}
% \subsection{PCR and Agarose gel}
% \input{./MMnormPCR.tex}
%\subsection{RNA purity and integrity control}
% \input{./MMbioanalyzer.tex}
\section{qRT-PCR}
\input{./MMqRTPCR.tex}
%\section{QBit}
% \input{./MMqbit.tex}
\section{Bioinformatics}
\input{./MMbioinfo.tex}
\subsection{Non-restrictive approach}
\input{./MMnonRestrictive.tex}
\subsection{Levenshtein distance}
\input{./MMlev2.tex}
\subsection{Feature Search}
\input{./MMfeatureSearch.tex}
%\subsection{Position Specific Scoring Matrices}
% \input{./MMpssm.tex}
% results
\newpage
\chapter{Results}
%\section{Agarose Gel}
% \input{./Ragarose.tex}
\section{Nanodrop and Bioanalyzer}
\input{./Rbioanalyzer.tex}
%\section{Qbit}
% \input{./Rqubit.tex}
\newpage
\section{Real-Time PCR}
\input{./RRTpCR.tex}
\newpage
\section{Bioinformatics}
\input{./Rbioinfo.tex}
% discussion
\end{document}
TeXMaker gives me several errors for main.tex. They are:
Line 47: File ended while scanning use of \caption#xdblarg
Line 79: !Latex Error: \begin{figure} on input line 7 ended by \end{document}
Line 79: !You can't use '\end’ in internal vertical mode
Line 79: !Latex Error: \begin{figure} on input line 7 ended by \end{document}
! Missing } inserted
Line 1: ! Emergency stop. <*> main.tex ***(job aborted, no legal \end found)
Line 47 is "\input{./MMqRTPCR.tex}
Line 79 is "\end{document}"
I am honestly confused. TeXMaker's error description is about missing braces. Am I screen-blind? I checked the braces 3 times and cannot figure out, what I missed. So, I am guessing, I missed something crucial about Latex.
Thanks for any help!
UPDATE:
In the input file "MMqRTPCR.tex", I out-commented a figure and all errors are gone. Here is the content of the file.
TEXTEXTEXT
%\begin{figure}[H]
%\centering
% \includegraphics[scale=0.6,natwidth=764,natheight=218]%{deltaDeltaCorrectedFormula.png}
% \caption{mycaption}
%\label{deltaDelta}
%\end{figure}
TEXTEXTEXT
\begin{table}[!h]
\centering
\caption{Primer sequences and targets}
\label{table1}
\begin{tabular}{|l|l|l|ll}
\cline{1-3}
Primer Sequence & Target & Direction \\ \cline{1-3}
AACATGTGCCGGTTGATAG & ECF20_992 & forward \\ \cline{1-3}
GCTGCTTCGGTATTGCTCA & ECF20_992 & reverse \\ \cline{1-3}
TCGTACCATTGAAAGCCTG & ECF02_2817 & forward \\ \cline{1-3}
ATCAATGGCTTCACGTGCA & ECF02_2817 & reverse \\ \cline{1-3}
TTCAAGAAACCATGGCCAC & ECF11_987 & forward \\ \cline{1-3}
GCTCGGCCAAATATCATCG & ECF11_987 & reverse \\ \cline{1-3}
\end{tabular}
\end{table}
TEXTEXTEXT
** UPDATE & SOLUTION**
The error was not in the main.tex itself, but in an input file. So, when TeXMaker tells you about missing bracers, jump to the line, where the error occured in the main.tex and check the bracers in the input file, which you see there.
So,
the error was a missing curly brace after all! Yet, it was not missing in the main.tex, but in the input file within the figure caption!
Thanks anybody, who's brain might have melted trying to find a solution to my problem. I hope this helps others, if they encounter the same error. :)
Combining and modifying this code (http://www.stata.com/statalist/archive/2012-11/msg00756.html) and this code (http://www.stata.com/statalist/archive/2009-02/msg00023.html), I try to use esttab (part of estout) in Stata to export a file that can be compiled in LaTeX. A real application of this might involve a complicated summary statistics table where one is pulling the statistics from several different sources and thus needs to utilize matrices. I am getting an error, however, in LaTeX when I compile. The error is:
Extra alignment tab has been changed to \cr.
Stata code:
clear all
eststo clear
mat A = (1,2\5,6)
mat coln A = male:1979 male:2007
mat rown A = mystat
ereturn post
estadd matrix B = A'
eststo MaleLabel
mat A = (3,4\7,8)
mat coln A = female:1979 female:2007
mat rown A = mystat
ereturn post
estadd matrix B = A'
eststo FemaleLabel
esttab MaleLabel FemaleLabel using "esttab.tex", ///
cell((B["1979"]B["2007"])) booktabs ///
mgroups("Male" "Female", pattern(1 1) prefix(\multicolumn{#span}{c}{) suffix(}) span erepeat(\cmidrule(lr){#span})) ///
noobs replace nomtitles nonum
LaTeX code:
\documentclass[12pt]{article}
\usepackage{booktabs}
\begin{document}
\begin{table}[htbp]
\begin{center}
\input{esttab}
\end{center}
\end{table}
\end{document}
The file that is produced from esttab is:
{
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\begin{tabular}{l*{2}{c}}
\toprule
&\multicolumn{2}{c}{Male} &\multicolumn{2}{c}{Female}\\\cmidrule(lr){2-3}\cmidrule(lr){4-5}
& 1979& 2007& 1979& 2007\\
\midrule
mystat & 1& 2& 3& 4\\
mystat & 5& 6& 7& 8\\
\bottomrule
\end{tabular}
}
Now, I can get things to work if I tweak this line:
\begin{tabular}{l*{2}{c}}
to be:
\begin{tabular}{l*{2}{cc}}
(I added an extra c.)
But I only know how to do this manually. What can I change in the Stata code to make this happen automatically?
add this simple option to your estab code
prehead({\begin{tabular}{l*{2}{cc}}\toprule)
and you are all set my man!
Any table I define with "sidewaystable" appears at the last page of created pdf file. How can I solve this?
\begin{sidewaystable}[h]
\caption{Blah Measurements}
\centering % centering table
\begin{tabular}{c c c c c c c c c c}
\hline\hline % inserting double-line
A & B & \multicolumn{3}{c}{C} & C Time + & D & \multicolumn{3}{c}{D Signal} \\
ID & ID & \multicolumn{3}{c}{Coordinates} & Time Diff. & Time & \multicolumn{3}{c}{Parameters} \\ [0.5ex]
\hline % inserts single-line
1 & 1 & 4415633.126837 & 482211.909079 & 939.450000 & 06:07:40 & 06:07:40 & -85 dBm & 6 dB & 5 dBm \\
\hline
\end{tabular}
\label{tab:combined}
\end{sidewaystable}
Have you tried the something like htbp for the placement of the float object?
\begin{sidewaystable}[htbp]
...
\end{sidewaystable}
Just use \clearpage \newpage before \begin{sidewaystable} and \clearpage after the \end{sidewaystable}..
It works without any floats like H, h!, htpb, etc.
you can try and use \begin{table}[h!] -- the ! will try and tell latex to force your table into the exact spot. I've had hit or miss results.
Also, with the float package, you can use a capital H \begin{table}[H] to keep your table from floating.