Using stargazer with Rstudio and Knitr

Since the topic has gone a bit stale, I'll assume the issue at hand is to somehow use stargazer with knitr, and not per se the conversion of the stargazer objects into HTML.

Being an avid fan of stargazer, I have come up with the following workflow:

  1. Write my code in an .Rmd file.
  2. Knit it into .md. Stargazer tables remain as LaTeX code in the resulting markdown file.
  3. Use pandoc to convert the markdown file to PDF. Pandoc translates the LaTeX code into proper tables. Alternatively, one can use LyX with knitr plugin to get stargazer tables nicely output in PDF format.

If one wants stargazer tables in MS Word, the best way I have found is to use LaTeX2RTF. Although the very top cells are distorted a bit, fixing it is a matter of removing an erroneous empty cell. For the rest the table is preserved and can be pasted/imported into Word.

These two strategies help use stargazer outside LaTeX. Hope it helps.


Use the following code and you get a working version

```{r, results='asis'}
stargazer(model)
```

When converting to pdf, the following code works perfectly for stargazer 4.0:

```{r, results='asis'}
stargazer(model, header=FALSE, type='latex')
```

Tags:

R

Knitr

Stargazer