TransWikia.com

Stata output directly to Latex

TeX - LaTeX Asked by Mroweczka on August 5, 2021

I am looking for a best, most universal option to transfer stata output to latex (of any kind) i know esttab and things like this however what if i want to transfer something different (any type of output not only reg)? What is the most universal and efficient method to do that?

I am using Stata SE 11.2.

In general what i want to have a stata log in .tex format. For example i want to have a tex version of vif table.

Command:

. vif

Output:

Variable |      VIF      1/VIF  
---------+----------------------
   meals |      2.73    0.366965
     ell |      2.51    0.398325
    emer |      1.41    0.706805
---------+----------------------
Mean VIF |      2.22

One Answer

The most flexible tool for this I can think of is John Luke Gallup's frmttable:

frmttable is a programmer's command that takes a Stata matrix of statistics and creates a fully-formatted Word or TeX table which can be written to a file.

I added the emphasis regarding matrices.

Here's a little example of a VIF table:

sysuse auto, clear
qui reg price mpg rep78 weight
estat vif
return list

mat A = `r(vif_1)', 1/`r(vif_1)'  `r(vif_2)', 1/`r(vif_2)'  `r(vif_3)', 1/`r(vif_3)'
mat B = A[1...,1]               // extract first column in order to compute mean
mat sm = J(rowsof(B),1,1)'*B    // sum of column elements
mat vifmean = sm/rowsof(B)      // compute VIF mean
mat A = A vifmean, .           // append A by vifmean
mat rownames A = `r(name_1)' `r(name_2)' `r(name_3)' "Mean VIF"
mat colnames A = VIF 1/VIF

frmttable using your-path/vifexample, statmat(A) sdec(2) varlabels tex fragment nocenter replace

This stores the following LaTeX output

begin{tabular}{lcc}
hline noalign{smallskip} & VIF & 1/VIF
noalign{smallskip}hline noalign{smallskip}Mileage (mpg) & 2.91 & 0.34
Weight (lbs.) & 2.91 & 0.34
Repair Record 1978 & 1.22 & 0.82
Mean VIF & 2.34 & 
noalign{smallskip}hlineend{tabular}

in the file your-path/vifexample.tex. You can then input this file in your document, for instance in a table float:

documentclass{article}

begin{document}

begin{table}
centering
caption{An example of a VIF table}

input{your-path/vifexample.tex}

end{table}
end{document}

This produces the output

enter image description here

Edit: Extended LaTeX code in order to produce compilable example after @Bobyandbob's comment.

Edit 2: Split LaTeX code for clarification.

Answered by Turtle on August 5, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP