Colored cells in LaTeX Tables with overlay

If you like to highlight single cells in LaTeX tables in the overlay mode, there is a very simple way to do so:

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

\renewcommand<>\cellcolor[1]{\only#2{\beameroriginal\cellcolor{#1}}}

\begin{document}

\begin{frame}
\frametitle{Table Slide}

\begin{table}[h]
\begin{center}
\begin{tabular}{lc}
\hline\hline
 & (1) \\
 \hline
 Treatment dummy & \cellcolor{red}<2>{0.0694*} \\
 & (0.0401) \\
Constant & -1.2238*** \\
 & (0.0764)  \\
\hline
Observations & 1,673  \\
 R-squared & 0.0401 \\
\hline\hline
\end{tabular}
\end{center}
\end{table}

\end{frame}

\end{document}

The “<2>” will tell LaTeX that the cell will only be highlighted in the second layer of the slide, “red” defines the color with which it is highlighted.

Advertisements

Formatted numbers in figure (sub)headers

My dear colleague Anders Stenberg recently taught me a very nice trick to include numbers (such as: number of observations, R2s or any other number that can be saved to a local) in Stata figures. While including numbers can be simply done with a local, the trick is to have them nicely formatted. I.e., to include commas in a larger number, or to have decimals rounded.

In the example that follows, the variable of interest is “aht”, of which I want to produce a histogram with mean and underlying number of observations in a subtitle

quietly sum aht, det
local n = trim("`: display %11.0gc r(N)'")
local mean = trim("`: display %09.3g r(mean)'")
twoway (hist aht), title("Histogram of AHT" "(N=`n'; Mean = `mean')")

Note that the trim is optional, but helps to avoid unwanted spaces in the subtitle.

For more information on how to format output, also check

help format

Track Changes in LaTeX and compare documents

One big disadvantage of writing in LaTeX compared to writing in other software, such as Word, is that its absence of track changes. Although there are ways to do track changes, such as the online tex-editor Sharelatex or the trackchanges package, I have sticked to commenting out deleted parts of the text, or by highlighting new passages in red.

I just came across this cool website on which you can compare different tex codes, e.g. before and after one of your co-authors worked on a text. On this website, you simply paste the original and the revised version, and you will receive a tex-code to generate a “track changes” document, which exactly highlights deleted and new text.

Follow this link to get compare your documents: https://3142.nl/latex-diff/

Open Stata 13 data files in Stata 12

I just ran across a very useful ado.-file called use13 which allows to open files in Stata 12 which were originally saved in Stata 13 (which often results in the error code “r(610): file not Stata format”). use13 can be installed by typing

ssc install use13
use13 filename.dta

This will then convert the Stata13 data file to use in Stata12.

Note: An alternative to use13 is to use saveold when creating the data file in Stata 13 (instead of save):

saveold filename [, saveold_options]

Use images from pdf documents in Latex

While you can simply drag & drop images in MS Word or Powerpoint, doing this in Latex requires a few more steps. An important difference is that in Latex, you first need to save the copied file as a separate image file which can then be included in the Latex code. For this purpose, we need a decent image editor. I recommend using Continue reading