safex
safex

Reputation: 2514

export entire stata table to latex

I have used esttab before to export regression results to Stata. However I have build a small table that I would like to export as it is:

Sample Data

* create a fake table with data to be exported to tex
sysuse auto, clear
keep make price mpg rep78 headroom
keep if _n < 20

Is there an easy way to have the data put into an latex-table? I can live without the variable names, but if labels can be exported even better.

Cross posted on Statalist.

Upvotes: 1

Views: 3024

Answers (1)

Wouter
Wouter

Reputation: 3261

The community-contributed texsave appears to be made for precisely this. It has a varlabels option to write labels in the header instead of variable names.

ssc install texsave
texsave * using whatever.tex, varlabels

If you want to keep only the tabularx part it's a bit harder, texsave doesn't seem to provide a way to do that. I see three options:

  1. Write your own code that produces the tex file you want
  2. Adjust texsave.ado to produce the file you want
  3. Adjust the output you get from texsave

The code below does the latter.

* create a fake table with data to be exported to tex
sysuse auto, clear
keep make price mpg rep78 headroom
keep if _n < 20

texsave * using whatever.tex, varlabels frag replace

import delimited using whatever.tex, clear
gen keep = strpos(v1, "{tabularx}") > 0
replace keep = cond(keep == 1, keep, sum(keep))
keep if keep == 1
drop keep
export delimited using whatever.tex, novarnames replace

You could still manually insert lines you want, for example with insobs, or adjust certain lines with replace.

Upvotes: 4

Related Questions