3

I have an issue to run the following code in an align environment:

\begin{align*}
&\mathrm{
    E(Y_i|D_i=1)-E(Y_i|D_i=0)&=E(Y_{1i}|D_i=1)-E(Y_{0i}|D_i=0)
    }\\
    \mathrm{
    &=\underbrace{E(Y_{1i}|D_i=1)-E(Y_{0i}|D_i=1)}_{\text{ATT}}+\underbrace{E(Y_{0i}|D_i=1)-E(Y_{0i}|D_i=0)}_{\text{selection bias}}
    }.
\end{align*}

The error message shows me the following: !Missing } inserted.\end {align}

I have tried to debug the code myself, however, all debug attempts were unsuccessful.

Can anyone figure out where the mistake is?

0
1

Since you put & inside the \mathrm{}, it will cause that error. I modified your code a little bit (move the & out of \mathrm{} and add some spaces with \:).

\begin{align*}
&\mathrm{
    E(Y_i|D_i=1)-E(Y_i|D_i=0)}\\
    =\:&\mathrm{E(Y_{1i}|D_i=1)-E(Y_{0i}|D_i=0)
    }\\
    =\:&\mathrm{\underbrace{E(Y_{1i}|D_i=1)-E(Y_{0i}|D_i=1)}_{\text{ATT}}+\underbrace{E(Y_{0i}|D_i=1)-E(Y_{0i}|D_i=0)}_{\text{selection bias}}
    }.
\end{align*}

Here is the result: enter image description here

For the last line to get normal text too, you can try this

\begin{align*}
&\mathrm{
    E(Y_i|D_i=1)-E(Y_i|D_i=0)}\\
    =\:&\mathrm{E(Y_{1i}|D_i=1)-E(Y_{0i}|D_i=0)
    }\\
    =\:&\underbrace{\mathrm{E(Y_{1i}|D_i=1)-E(Y_{0i}|D_i=1)}}_{\text{ATT}}+\underbrace{\mathrm{E(Y_{0i}|D_i=1)-E(Y_{0i}|D_i=0)}}_{\text{selection bias}}.
\end{align*}

enter image description here

2
  • This is what I was just looking for. But how can I solve the issue that the last line is still italic?
    – randomname
    Jun 5 '21 at 8:34
  • 1
    You can add \mathrm to each underbrace. You can see the edit in my post. Jun 5 '21 at 8:40
5

If you really want to print math upright, use a dedicated package rather than adding unwanted markup such as \mathrm.

\documentclass{article}
\usepackage{amsmath}
\usepackage{mathastext}

\begin{document}

\begin{align*}
& E(Y_i|D_i=1)-E(Y_i|D_i=0)
\\
&=E(Y_{1i}|D_i=1)-E(Y_{0i}|D_i=0)
\\
&=\underbrace{E(Y_{1i}|D_i=1)-E(Y_{0i}|D_i=1)}_{\text{ATT}}
 +\underbrace{E(Y_{0i}|D_i=1)-E(Y_{0i}|D_i=0)}_{\text{selection bias}}.
\end{align*}

\end{document}

enter image description here

2
  • Hi, in this case is it important to write | or \mid?
    – Sebastiano
    Jun 5 '21 at 9:04
  • 2
    @Sebastiano I'd use \mid, or, at least, \,|\, But the OP seems not to be worried about correct appearance of math…
    – egreg
    Jun 5 '21 at 9:09
3

Welcome! This is due to the mathrm{…} commands containing an ampersand. Anyway, with align*, the equation does not fit the text width, so I suggest using multline*. I also replaced the various | with \mid, which has a better spacing, and added a small vertical spacing between the two lines.

\documentclass{article}
\usepackage{amsmath, amssymb}

\begin{document}

\begin{multline*}
    \mathrm{E(Y_i\mid D_i=1)-E(Y_i\mid D_i=0) =E(Y_{1i}\mid D_i=1)-E(Y_{0i}\mid D_i=0)}
   \\[0.8ex]
=\underbrace{\mathrm{E(Y_{1i}\mid D_i = 1) - E(Y_{0i}\mid D_i=1)}}_{\text{ATT}} + \underbrace{\mathrm{E(Y_{0i}\mid D_i=1)-E(Y_{0i}\mid D_i=}0)}_{\text{selection bias}}.
\end{multline*}

\end{document} 

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.