1

I am trying to write a research paper in rmarkdown, in which I am trying to create a summary stat table using stargazer package, but I it shows me the following errors when I include the argument notes = c("All variables are defined in Appendix A.", "All continuous variables are winsorized at 1% and 99%.", "The pctl(25(75) corresponds to 25% (75%) percentile.") in stargazer -

! File ended while scanning use of \multicolumn.
<inserted text> 
                \par 
<*> sample_articles.tex

Below is the table portion from my tex file for the above problem-

\begin{table}[!htbp] \centering 
  \caption{Summary Stat of Variables} 
  \label{} 
\tiny 
\begin{tabular}{@{\extracolsep{-5pt}}lcccccc} 
\\[-1.8ex]\hline 
\hline \\[-1.8ex] 
Statistic & \multicolumn{1}{c}{N} & \multicolumn{1}{c}{Mean} & \multicolumn{1}{c}{St. Dev.} & \multicolumn{1}{c}{Pctl(25)} & \multicolumn{1}{c}{Median} & \multicolumn{1}{c}{Pctl(75)} \\ 
\hline \\[-1.8ex] 
DEGREE & 19,114 & 67.7 & 15.7 & 56.3 & 68.7 & 79.7 \\ 
EIGENVECTOR & 19,114 & 61.6 & 20.1 & 48.7 & 64 & 77 \\ 
BETWEENNESS & 19,114 & 67.8 & 23.7 & 53.0 & 72.8 & 87.0 \\ 
CLOSENESS & 19,114 & 61.2 & 21.9 & 46.1 & 63 & 78 \\ 
OVERALLCENTRALITY & 19,114 & 67.4 & 21.6 & 51.8 & 71 & 85 \\ 
LNASSETS & 19,114 & 6.9 & 2.2 & 5.5 & 7.0 & 8.4 \\ 
LEVERAGE & 19,114 & 0.5 & 0.3 & 0.4 & 0.5 & 0.7 \\ 
INVREC & 19,114 & 0.2 & 0.2 & 0.1 & 0.2 & 0.3 \\ 
LOSS & 19,114 & 0.3 & 0.4 & 0 & 0 & 1 \\ 
ROA & 19,114 & 1.1 & 22.3 & $-$0.01 & 4.9 & 10.6 \\ 
ZSCORE & 19,114 & 0.9 & 0.9 & 0 & 1 & 2 \\ 
MERGER & 19,114 & 0.4 & 0.5 & 0 & 0 & 1 \\ 
MTB & 19,114 & 3.0 & 4.7 & 1.3 & 2.1 & 3.6 \\ 
FOREIGN & 19,114 & 0.5 & 0.5 & 0 & 0 & 1 \\ 
EXTRAORDINARY & 19,114 & 0.01 & 0.1 & 0 & 0 & 0 \\ 
SEGMENT & 19,114 & 2.1 & 0.8 & 1.4 & 2.0 & 2.6 \\ 
SPECIALIZED & 19,114 & 0.3 & 0.5 & 0 & 0 & 1 \\ 
MATERIALWEAKNESS & 19,114 & 0.05 & 0.2 & 0 & 0 & 0 \\ 
RESTATEMENT & 19,114 & 0.1 & 0.3 & 0 & 0 & 0 \\ 
BIGN & 19,114 & 0.8 & 0.4 & 1 & 1 & 1 \\ 
GOINGCONCERN & 19,114 & 0.02 & 0.1 & 0 & 0 & 0 \\ 
CALENDARYEAR & 19,114 & 0.8 & 0.4 & 1 & 1 & 1 \\ 
LNNONAUDFEES & 19,114 & 11.9 & 1.8 & 10.7 & 12.0 & 13.2 \\ 
LNAUDFEES & 19,114 & 14.0 & 1.3 & 13.2 & 14.0 & 14.8 \\ 
AUDTURNOVER & 19,114 & 0.1 & 0.2 & 0 & 0 & 0 \\ 
RESTRUCTURE & 19,114 & $-$0.002 & 0.1 & $-$0.001 & 0.0 & 0.0 \\ 
LITIGATE & 19,114 & 0.3 & 0.4 & 0 & 0 & 1 \\ 
AGE & 19,114 & 3.0 & 0.7 & 2.5 & 3.0 & 3.6 \\ 
AUDITORTENURE & 19,114 & 8.2 & 4.4 & 5 & 8 & 12 \\ 
AUDITLAG & 19,114 & 8.0 & 1.1 & 7.4 & 7.7 & 8.6 \\ 
AUDFEES (ml) & 19,114 & 2.7 & 5.7 & 0.5 & 1.2 & 2.7 \\ 
NAUDFEES (ml) & 19,114 & 0.7 & 2.1 & 0.05 & 0.2 & 0.5 \\ 
\hline \\[-1.8ex] 
\multicolumn{7}{l}{All variables are defined in Appendix A.} \\ 
\multicolumn{7}{l}{All continuous variables are winsorized at level 1% and 99%.} \\ 
\multicolumn{7}{l}{The pctl(25 (75)) corresponds to 25% (75%) percentile.} \\ 
\end{tabular} 
\end{table}

However if I take out the above notes argument, it works fine.

Below is my r code in rmarkdown without notes argument in stargazer -

sumstat_label <- c(
  "DEGREE", 
  "EIGENVECTOR", 
  "BETWEENNESS", 
  "CLOSENESS", 
  "OVERALLCENTRALITY",
  "LNASSETS",
  "LEVERAGE", 
  "INVREC", 
  "LOSS",
  "ROA", 
  "ZSCORE",
  "MERGER",
  "MTB",
  "FOREIGN",
  "EXTRAORDINARY",
  "SEGMENT",
  "SPECIALIZED",
  "MATERIALWEAKNESS",
  "RESTATEMENT",
  "BIGN",
  "GOINGCONCERN",
  "CALENDARYEAR",
  "LNNONAUDFEES",
  "LNAUDFEES",
  "AUDTURNOVER",
  "RESTRUCTURE",
  "LITIGATE",
  "AGE", 
  "AUDITORTENURE",
  "AUDITLAG", 
  "AUDFEES (ml)",
  "NAUDFEES (ml)")

note_label <- c("All variables are defined in Appendix A.",
                "All continuous variables are winsorized at 1% and 99%.",
                "The pctl(25(75) corresponds to 25% (75%) percentile.")
stargazer(as.data.frame(sum_stat[c(
  "DEGREE", 
  "EIGENVECTOR", 
  "BETWEENNESS", 
  "CLOSENESS", 
  "OVERALLCENTRALITY",
  "LNASSETS",
  "LEVERAGE", 
  "INVREC", 
  "LOSS",
  "ROA", 
  "ZSCORE",
  "MERGER",
  "MTB",
  "FOREIGN",
  "EXTRAORDINARY",
  "SEGMENT",
  "SPECIALIZED",
  "MATERIALWEAKNESS",
  "RESTATEMENT",
  "BIGN",
  "GOINGCONCERN",
  "CALENDARYEAR",
  "LNNONAUDFEES",
  "LNAUDFEES",
  "AUDTURNOVER",
  "RESTRUCTURE",
  "LITIGATE",
  "AGE", 
  "AUDITORTENURE",
  "AUDITLAG", 
  "AUDFEES",
  "NAUDFEES")]),
  summary.stat = c("n", "mean", "sd", "p25", "median", "p75"),
  column.sep.width = "-5pt",
  title= "Summary Stat of Variables", type = "latex",
  digits= 1, 
  header = FALSE,
  notes.align = "l",
  font.size = "small",
  single.row = T,
  no.space = T,
  covariate.labels = sumstat_label
)

Does any body have any idea how I can append the notes argument in the table with the type = latex in stargazer. Thanks.

Sharif
  • 163
  • 1
  • 9
  • I have been able to solve it. Just changing the `notes` argument help to solve the problem. I change the `notes` argument like this - `notes = c("All continuous variables are winsorized at 1 and 99 percent", "All variables are defined in Appendix A", "The Pctl (25 (75) corresponds to 25 and 75 percentile")` . The issue was using the `%` sign; I just change it to the word `percent`. Thanks – Sharif May 29 '20 at 07:07

1 Answers1

0

The issue is that the '%' symbol in your notes is passed to Latex as a special character. In Latex '%' means "start a comment here and ignore everything after the percent symbol." One solution is to replace the percent symbol with the word percent or percentile (as noted in the comment by the original author).

In some cases, though, a symbol is preferable (such as in labels that we want to keep short). In those cases, "escaping" the percent symbol will often solve the problem. Stargazer is usually pretty good at cleaning up or "sanitizing" special characters but not always as in this case with the note_label option. Some possible solutions:

  • try using the word percent instead of the symbol % and see if everything knits

  • try using backslash percent as in \% which tells Latex treat this as a regular character and not a special character.

  • oftentimes R / R Markdown prefer two backslashes (one to escape the backslash and one to escape the percent) so worth trying that too (ie, \\%) if neither of the other options work

  • try manually sanitizing text strings with characters like underscores, percents, ^s, etc with a function like Hmisc::latexTranslate(). See more, here: Function to sanitize strings for LaTeX compilation?

Omar Wasow
  • 1,870
  • 24
  • 24