### Browsed byCategory: LaTeX

Fitting tables to the width of a page

## Fitting tables to the width of a page

Ever have the problem of Stata regression output being a little too wide? Worry no more.

I use Ben Jann’s excellent esttab to export Stata regressions into LaTeX documents.

My only problem with esttab is that the tables can be too wide, i.e. wider than the width of the text in the PDF. So I made a few edits to esttab that automatically scale the tables to the text-width.

I have called this program estwide. You can download it here. As it is based on estout, Ben Jann should be considered a co-author. Click here to see an example of its effect. (If you wish to replicate the above example, you can download the associated do-file here and the TeX file here.)

To use estwide:
1. Make sure estout is installed. To do this, in Stata type ssc inst estout, replace
2. Save estwide.ado to the same folder that estout is now installed in. You can check the folder by typing which estout
3. Restart Stata.
4. Rather than exporting your tables using the esttab command, simply replace esttab with estwide, e.g. estwide using hello.tex, style(tex) replace
5. Make sure you have both the adjustbox and booktabs LaTeX packages installed.
6. Make sure you have called both of these packages up by including \usepackage{booktabs} and \usepackage{adjustbox} in the header of your LaTeX file.
7. Include your tables as normal. You can copy and paste the output into your TeX file, or have the tables update automatically when you make changes by using \input{myfilename}.

Update, September 2017: after some emails from people, I have two things to add. Firstly, estwide seems to work much better if you include a caption to the table.

Secondly, if you have a problem with the caption appearing on one page and the table itself on another, wrap the input in a LaTeX table. For example, this code works well for me:
\begin{table}[ht]
\input{myfilename}
\end{table}

Partial derivative shortcut in LaTeX

## Partial derivative shortcut in LaTeX

This is incredibly simple code but may be of use to some people. Typing out derivatives in LaTeX (e.g. ) can be shortened.

\newcommand{\dydx}[2]{\frac{\partial{#1}}{\partial{#2}}}


This creates a new command \dydx that takes two arguments, e.g. \dydx{P}{\tau}. Include this command in math mode (e.g. encased in dollar signs) and it will produce .

Some help with common LaTeX problems

## Some help with common LaTeX problems

What’s the easiest way to include a graphic (or graph, diagram, figure etc.) in my document?

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{figure}[h]
\centering
\caption{This is my picture}
\end{figure}
\end{document}


Then compile using pdflatex.

I’m getting a “no BoundingBox” error when I compile my document.

Have you tried compiling the document with pdflatex? In WinEdt, select PDFLaTeX from the dropdown menu that’s below ‘Accessories’ on the menu bar, and to the right of the recycle bin icon. If you’re compiling from the command prompt and your document is named thesis.tex, type pdflatex thesis.

I’m trying to compile my document and I am using natbib to do the references, but the document won’t compile with PDFLaTeX.

It’s unfortunate that natbib (as far as I can see) relies on latex (not pdflatex) but latex gets confused if you have graphics in the document. My workaround for this is to temporarily place a % sign in front of any graphics to turn them into comments, rather than code. This means the graphics are initially excluded, and you can run latex/bibtex and natbib will work. Once all the references are good and ready, you can remove the % signs (a quick Find > Replace All will do the trick) and compile using pdflatex.

Simple Problem Set Hack

## Simple Problem Set Hack

I had a problem set where each question had multiple sub-parts: a, b, c; etc. I was typing the solution up in LaTeX and it wasn’t obvious what was the cleanest way to identify my answers.

I ended up with code like this:

\section*{Question 1}
\new This is my answer to part a.

\new This is my answer to part b

This formatting results in something like this:

That’s exactly what I was looking for. It requires two lines of code at the start of your document:

\newcounter{my_count}

LaTeX mathematical expectation shortcut

## LaTeX mathematical expectation shortcut

I find it cumbersome to typeset , “the expectation of x”, in LaTeX. I’ve simplified the code a little.

\usepackage{amsmath}
\usepackage{amsfonts}
\newcommand{\e}[1]{{\mathbb E}\left[ #1 \right]}


This calls on the necessary packages and makes a new function \e which takes one argument. The outcome is that argument within appropriately-sized square brackets and prefaced with the expectation sign.

For example, the code \e{x^2}=10 results in .

Writing MCQs in LaTeX: the qanda class

## Writing MCQs in LaTeX: the qanda class

I was writing a series of practice multi-choice questions for the class I teach when I decided I wanted to write a LaTeX function to automate the formatting. I wanted to include the answer as an argument of that function (possibly with room for an explanation) but not to display the answer until the end of the document. (This is a reasonably simple process. For a more hardcore setup, see the eqexam package.)

I hacked away at the endnotes package until I got what I wanted. Editing packages is a pain though, so I summarized the changes into a Questions and Answers class: qanda.cls.

This does the dirty work in the background and defines two new commands: \q and \qtf. The former takes six arguments: the question, four multi-choice options, and the answer. The latter takes four arguments: the question, two multi-choice options (e.g. true and false, thus the tf in command name), and the answer.

This makes writing multi-choice questions very easy. Here is some sample code.

\documentclass{qanda}
\title{An Example of the qanda Class}
\begin{document}
\maketitle
This document is an example of the output of the qanda (q and a'') class.

\qtf{There are subtle historical parallels in \textit{Animal Farm}.}{True}{False}{True; it is an allegory for the unfortunate route Communism took.}

\newpage
\theendnotes

\end{document}


This produces this nifty document.

To use the qanda class:

2. Place it in the folder your .tex is in
3. Start your document with \documentclass{qanda}

To produce the answers to your questions, simply include the \theendnotes command where you want them in your document. Preface this with \newpage if you want them on a new page.

Note that the qanda class is based on the scrartcl class, so you need that on your computer. You also will need to have installed the enumerate and setspace packages.

Enjoy!

Latin phrases and Greek letters for economists

## Latin phrases and Greek letters for economists

Latin phrases for economists
Phrase Translation
A priori Pre-supposed; your “priors beliefs”.
Ad infinitum To infinity; and so on.
Ad valorem Per value; a 10% tax is an ad valorem tax, whereas a duty per gallon of gasoline is not.
Ceteris paribus All else equal e.g. “We would expect, ceteris paribus, that an increase in price would lower quantity demanded.”
De facto For all practical purposes, but not officially.
De jure By law.
Ex ante Before the event; in anticipation.
Ex post After the event; in retrospect.
Per se Literally; by itself.
Prima facie In the first instance; at first glance.
QED As has been asked to be shown; done.
Ultra vires Beyond their power, e.g. the court ruled that Congress were acting ultra vires.
Greek letters for economists
Lower-case Upper-case Pronunciation Economic meaning
A Alpha Capital share of income
B Beta Regression coefficient (econometrics), or rate of time discounting (economic theory)
Gamma N/A
Delta Depreciation
E Epsilon Elasticity
Z Zeta N/A
H Eta N/A
Theta Type, e.g. might represent a “high type”
I Iota N/A
K Kappa N/A
Lambda The Lagrange multiplier
M Mu Mean
N Nu N/A
Xi N/A
o O Omicron N/A
Pi Inflation, or profit (lower-case) or the product of a series (upper-case)
R Rho The coefficient of autoregression
Sigma Standard deviation (lower-case) or the sum of series (upper-case)
T Tau Tax
Upsilon N/A
Fy N/A
X Chi (rhymes with guy’) Used in statistics
Psi (like Si’) N/A
Omega N/A
A clarification on LaTeX

## A clarification on LaTeX

Just in case you’ve googled me and wondered why I happily link to something called LaTeX, I should clarify that LaTeX (most commonly pronounced “Lay-tek”) is a computer language for typesetting documents. (Well, it’s officially called and is a markup language rather than a standard computer language, but that’s splitting hairs.)

Most people use Microsoft Word to write documents. That’s fine. I prefer to use LaTeX, particularly if there is any mathematics in the document. The primary reason for this is ease. LaTeX can “read” math and I find it easier to type \sum x_i to obtain than to mess around with the equation editor.

LaTeX also produces remarkably beautiful documents. I appreciate that this sounds particularly nerdy, but it’s true: ask Dario for proof. Moreover, its settings are defaulted to look just right, so there’s no messing around with fonts, margins, line-spacing, etc.

Andrew Roberts has a thorough outline of the benefits of LaTeX. Here’s my summary:

1. Math(s) is much easier to write.
2. Presentations (via beamer) are cooler.
3. The documents look better.
4. You don’t have to worry about how it looks, so you can focus on content.

I admit the name is unfortunate, though.