When exporting graphics from Stata or Matlab, it’s better to select a lossless/vectorized format instead of a rasterized pic. This ensures your image is high-quality and not grainy/pixelated.

Grainy exports

Poor quality, grainy image

Better quality export

Unfortunately, Matlab does not allow lossless PDF exports of pictures with non-standard fonts. (I’m not the first person to notice this problem. I failed to implement Juan Guerrero’s suggested solution.) Matlab will export the font in PNG no problem, but your image will appear grainy. If you try to export as a PDF, your fonts will be reverted to something weird. Obviously this doesn’t matter if you’re happy with the default fonts, but this bug does limit your ability to customize the output.

Thankfully, with the help of the nice people at Inkscape (https://inkscape.org/) there is a workaround.

  1. Install Inkscape
  2. Generate your figure in Matlab
  3. In “Export Setup”, change the Font to anything saved on your system. Export as Scalable Vector Graphic (SVG) file
  4. Open the SVG in Inkscape
  5. Save it a lossless PDF as, say, figure7.pdf
  6. Include in your LaTeX document with \includegraphics{figure7}

Done!

//

Usually my exams have a large blank space for students to write their names in.

If, instead, I wanted to generate individualised exams with their names printed in that space, this code will do that for you. It uses the pgffor package to loop over the list of names you provide.

\documentclass{article}
\usepackage{pgffor}
\def\classlist{Enda Hargaden,
George Akerlof,
Joe Stiglitz,
Don Bruce}
\pagenumbering{gobble}
\begin{document}
\foreach \studentname in \classlist{

Econ 381 Problem Set: \studentname's Copy

\begin{enumerate}
\item What is OLS?
\item What's the square root of 25?
\item More questions yadda yadda
\end{enumerate}

\newpage}

\end{document}
//

Over on Twitter, Gray Kimbrough suggests using colour to indicate statistical significance/p-values instead of the traditional stars. This was part of a broader argument for Powerpoint over Beamer.

I much prefer Beamer to Powerpoint, and I knew it would be very easy to implement coloured cells in regression tables directly from Stata into LaTeX/beamer.

I use the wonderful estout to produce regression tables (and have modified it in the past) so here’s how to produce the table above with one extra line in your do-file.

clear
sysuse auto

** This line generates a local named siggreen, defining significance with green opacity
local siggreen "star(\cellcolor{green!10} 0.10 \cellcolor{green!35} 0.05 \cellcolor{green!95} 0.01) nonotes"

** Run a few sample regressions
qui eststo: reg price foreign mpg weight
qui eststo: reg price foreign mpg weight turn
qui eststo: reg price foreign mpg weight turn gear_ratio displacement headroom

** Using esttab, produce the output with Enda's preferred options
esttab using myoutput.tex, replace booktabs nodepvars nomtitle se label ar2 `siggreen' title("Green Regression")

Then, to include that table into your TeX document:

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{booktabs}
\begin{document}
\input{myoutput}
\end{document} 

If you want to include this tables in your Beamer slides, see this post.

//

I’ve discussed in the past how to indicate statistical significance with colour rather than stars. Another concern people have about using Beamer is that it can be hard to squish results into one slide. In my opinion, that is solved very easily with my tinytable command.

\documentclass[xcolor={table}]{beamer}
\usepackage{booktabs}

\newcommand{\tinytable}[1]{\textcolor{black}{\tiny \input{#1} }}

\begin{document}
\begin{frame}
\frametitle{Fascinating}
\input{myoutput}
\end{frame}

\begin{frame}
\frametitle{Still fascinating, but smaller}
\tinytable{myoutput}
\end{frame}
\end{document} 

This generates the following:

//

The economic package includes old commands that are now deprecated within LaTeX. This caused me a problem using the AER bibliography style (aer.bst), and likely causes problems with other BibTeX styles too. My particular problem was with scrartcl refusing to recognise the \bf command rather than the newer \textbf version.

Very specifically, the problem was “Class scrartcl Error: undefined old font command `\bf’.”

The fix for this is simple. Just include the following two lines in the preamble of your document.

\DeclareOldFontCommand{\bf}{\normalfontbfseries}{\textbf}
\DeclareOldFontCommand{\it}{\normalfont\itshape}{\textit}

You could alternatively open up your *.bst file and manually change the code, but the two lines above should fix it.

//

I like being able to hide content in documents, for example including but not revealing the answers in a problem set. That makes it very easy to then produce the problem set solutions, simply by revealing the answers. I made this easier with a \hide{} command, that can be “turned off” so the answers are revealed.

This is the basic code I use for producing problem sets. The only change needed to convert a problem set into a solution set is to redefine the \showanswers variable to equal 1 rather than 0.

\documentclass{article}
% Set this =0 to hide, =1 to show
\def\showanswers{0}

\newcommand{\hide}[1]{
\ifnum\showanswers=1

#1 \vspace{\baselineskip}
\fi

\ifnum\showanswers=0

\vspace{2\baselineskip} \hspace{2cm}
\fi
}

\begin{document}

\begin{enumerate}
\item This is question 1.
\hide{Here is a hidden solution.}


\item What is the answer to question 2?
\hide{The answer is here.}
\end{enumerate}

\end{document}
//

I typeset the euro symbol (€) regularly and I’ve always thought the version produced in LaTeX sticks out a bit like a sore thumb. (I re-assure myself that noticing these things is evidence that I adequately proof-read my prose.) The code below makes a new command \yuro that (in my opinion) fits in better with the surrounding text.

\documentclass[12pt]{article}
\usepackage{eurosym}
\usepackage{graphicx}
\newcommand{\yuro}{\scalebox{0.95}{\euro}}
\begin{document}
This is the size with the \euro 1,000 original configuration.

This is the size with the \yuro 1,000 newer configuration.
\end{document}

The code shrinks the size of the symbol to make it fit better with other characters. Similarities to the status of the eurozone are unintentional.

//
I have generated an easy-to-read PDF of William Petty's Taxes and Contributions. You can download it here. Hard copies of the book, comprising poor photocopies of older editions, make difficult work on the eyes. This edition is typeset as a modern document. I did write a script to generate it though, so it's likely that there are some errors in there. Please let me know if you find any. Due credit to the nice people from McMaster University who transcribed the plain-text copy.
//

Economists often denote a Lagrangian maximization problem with a scripted L. Unless you exert a little bit of effort, this looks poorly when produced by LaTeX. The code below allows you to easily typeset the symbol in a larger font-size.

The code creates four new commands: \lagrange1, \lagrange2, \lagrange3, and \lagrange4. They produce the “Lagrangian L” with increasing size.

\documentclass{article}

\usepackage{relsize}
\usepackage{mathrsfs}
\usepackage{xstring}

\newcommand{\lagrange}[1]{\IfEqCase{#1}{{1}{\mathscr{L}}{2}{\mathlarger{\mathscr{L}}}{3}{\mathlarger{\mathlarger{\mathscr{L}}}}{4}{\mathlarger{\mathlarger{\mathlarger{\mathscr{L}}}}}}}

\begin{document}
$$ \lagrange1 $$
$$ \lagrange2 $$
$$ \lagrange3 $$
$$ \lagrange4 $$
\end{document}


//
Scroll to Top