Profile picture
Damon Jones @nomadj1s
, 14 tweets, 4 min read Read on Twitter
💾Stata Tutorial💾

In case it’s useful, here’s a way to write LaTeX table code within Stata and export to .tex

I learned this from @sacksdaniel

\begin{🤓}
First run your regressions and save the results in their own data set

Saving the results is not necessary, but if you ever need to get exact numbers, better to have them in a data set than in a pdf or .tex file
Next, use your results data and write LaTeX code *as string variables*

Use different variables for different columns (tc0,tc1,...)

one observation = one line of code, which is tracked using the `row’ macro

add “\\” to relevant lines

Use “outsheet” to export a .tex file
Here is how the Stata data set looks once the LaTeX code is written:
Here’s the .tex file that was created by “outsheet”:
Here’s the table pdf once the .tex file is compiled:
This is a very stripped down version. Once you get the hang of it, you can add stars, sample sizes, etc.

Also, many of the repetitive lines can be streamlined with loops
Why do this instead of using “outreg” or “estout”?

If those give you exactly what you need, don’t use my method.

I usually need to make slight modifications to tables that take forever to implement within other commands. This gives me complete control over the table layout.
A nice table will involve a lot more lines of code, but, like all code, once it’s set up, everything is automated
I know someone wants to tell me that I can do all of this in R ... I’m happy for you, and I’ma let you finish, but this was in response to a question about *Stata*

\end{🤓}
Someone asked for the data file & do file:

The data that was made as follows:

set obs 30
gen sample = ceil(_n/10)
gen x = _n
gen e = runiform()
gen y = sample*x + e

The entire code is pasted above in the images. If someone wants to transcribe, go for it
This way looks to be even easier

Relative to my case, you’d just need to know how to make variable values into macros, e.g. `=b[1]’

Update: I’m sold on “texdoc” as an even better way to do the last step above

h/t: @maibennett

repec.sowi.unibe.ch/stata/texdoc/
I’ve already used texdoc once last night
Missing some Tweet in this thread?
You can try to force a refresh.

Like this thread? Get email updates or save it to PDF!

Subscribe to Damon Jones
Profile picture

Get real-time email alerts when new unrolls are available from this author!

This content may be removed anytime!

Twitter may remove this content at anytime, convert it as a PDF, save and print for later use!

Try unrolling a thread yourself!

how to unroll video

1) Follow Thread Reader App on Twitter so you can easily mention us!

2) Go to a Twitter thread (series of Tweets by the same owner) and mention us with a keyword "unroll" @threadreaderapp unroll

You can practice here first or read more on our help page!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just three indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member and get exclusive features!

Premium member ($30.00/year)

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!