Below is a code to put a stargazer
table in R markdown. To do so, I used some code found in the documentation of the stargazer
package and I customize it a little bit.
---
title: "test stargazer in r markdown"
author: ""
date: "18/09/2019"
header-includes:
- \usepackage{dcolumn}
output: pdf_document
---
```{r results='asis', echo = FALSE, message = FALSE}
library(stargazer)
set.seed(5)
temp <- rnorm(500, mean = 80, sd = 12)
sales <- 2 + temp * 3
for (i in 1:length(sales)) {
if (temp[i]<75 | temp[i]>95) sales[i] <- sales[i] + rnorm(1, 0, 25)
else sales[i] <- sales[i] + rnorm(1, 0, 8)
}
female <- rnorm(500, mean = 0.5, sd = 0.01)
icecream <- as.data.frame(cbind(temp, sales, female))
reg.model <- lm(sales ~ temp + female, data = icecream)
library(sandwich)
cov <- vcovHC(reg.model, type = "HC")
robust.se <- sqrt(diag(cov))
stargazer(reg.model, reg.model,
se = list(NULL, robust.se),
column.labels = c("default", "robust"),
align = TRUE,
notes.align = "l",
type = "latex",
header = FALSE,
notes = "Tout ceci est un texte bidon qui a pour unique but de prendre de la place afin de voir comment les notes sont traitées par le package 'stargazer'."
)
```
The text in the notes
argument is long and therefore increases the width of the table whereas I'd like the text to be confined (with multiple break lines if necessary) under the original (narrower) table. I don't think this is possible with the functions of the package (but I may be wrong), is there a tweak to make that possible?
First image is the obtained output, second image is the desired output:
Edit: I would like a solution so that the lines are broken automatically, not manually