简体   繁体   中英

Formatting notes in R's stargazer tables

I am using stargazer package to produce (regression output) tables. Everything working miracles until I start editing the notes. First : line breaks are hard, but Bryan suggests a manual solution that is not elegant, but works. Second I need to make it start from the very left of the table.

Here is an example of the notes I am trying to produce from within R . 在此处输入图片说明

Produced by changing the original LaTeX code from:

\textit{Note:}  & \multicolumn{4}{l}{Logistic regression. Dependent variable: an indicator varible ... AND Some very long and interesting comment.} \\ 

To

   \multicolumn{5}{l} {\parbox[t]{11cm}{ \textit{Notes:} Logistic regression. Dependent variable: an indicator varible ... AND Some very long and interesting comment.}} \\

在此处输入图片说明

Editing by hand is time-consuming and error-prone. So I am looking for a way to solve this from R , where I am currently using the following:

stargazer([...],
          style = "qje", notes.append = FALSE, notes.align = "l",
          notes = "\\parbox[t]{7cm}{Logistic regression. Dependent variable: an indicator 
                   varible ... AND Some very long and interesting comment.}")

stargazer returns its output invisibly as a character vector, specifically so you can post-process it. Depending what you want to change, this may involve some regex. Or, as in this case, if you know what your notes line should look like, you can simply replace the wrong line with what you want. Here's a minimal reproducible example:

df <- data.frame(x = 1:10 + rnorm(100),
                 y = 1:10 + rnorm(100))
reg <- lm(y ~ x, data = df)

star <- stargazer(reg,
          style = "qje", notes.append = FALSE, notes.align = "l",
          notes = "This will be replaced")


note.latex <- "\\multicolumn{5}{l} {\\parbox[t]{11cm}{ \\textit{Notes:} Logistic regression. Dependent variable: an indicator varible ... AND Some very long and interesting comment.}} \\\\"
star[grepl("Note",star)] <- note.latex
cat (star, sep = "\n")

You can replace 7cm with \\textwidth, making your solution generic.

stargazer([...],
      style = "qje", notes.append = FALSE, notes.align = "l",
      notes = "\\parbox[t]{\\textwidth}{Logistic regression. Dependent variable: an indicator varible ... AND Some very long and interesting comment.}")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM