0

I want to include outputs of a regression as latex table in rmarkdown as html output. I tried:

regression <- function(analysis_data,formula) {
  print(xtable(etable(feols(fml = formula,
               data = analysis_data 
               , cluster = ~ cluservar)
         ,
         keep = c("var1", "var2")), type = "html", include.rownames = F, floating=FALSE))
}

and

regression <- function(analysis_data,formula) {
  print(xtable(etable(feols(fml = formula,
               data = analysis_data 
               , cluster = ~ cluservar)
         ,
         keep = c("var1", "var2"), tex = T)
}

with in the header of the chunk of the rmarkdown results = 'asis'. My output should be html and my general header of the rmarkdown is:

---
title: "Title"
#author: "Author"
output: html_document
editor_options: 
  chunk_output_type: inline

---

<style>
div.hidecode + pre {display: none}
</style>
<script>
doclick=function(e){
e.nextSibling.nextSibling.style.display="block";
}
</script>

It doesn't include the output correctly as latex table either way and I don't get why. Thanks for the help!

tiny
  • 129
  • 6

1 Answers1

1

In my opinion you have two options.

  1. use postprocess.df = pandoc.table.return and style = "rmarkdown" in etable.

Example:

---
output: html_document
---

```{r, results='asis', echo = FALSE}
library(fixest)
library(pander)

data(airquality)

# Setting a dictionary 
setFixest_dict(c(Ozone = "Ozone (ppb)", Solar.R = "Solar Radiation (Langleys)",
                 Wind = "Wind Speed (mph)", Temp = "Temperature"))
est = feols(Ozone ~ Solar.R + sw0(Wind + Temp) | csw(Month, Day), 
            airquality, cluster = ~Day)
etable(est, postprocess.df = pandoc.table.return, style = "rmarkdown")

Output:

enter image description here

  1. Use Quarto and the parse-latex filter, e.g.
    ---
    format: html
    filters: [parse-latex]
    ---
    
    ```{r}
    #| echo: false
    #| results: asis
    #| warning: false
    library(fixest)
    
    data(airquality)
    
    # Setting a dictionary 
    setFixest_dict(c(Ozone = "Ozone (ppb)", Solar.R = "Solar Radiation (Langleys)",
                     Wind = "Wind Speed (mph)", Temp = "Temperature"))
    est = feols(Ozone ~ Solar.R + sw0(Wind + Temp) | csw(Month, Day), 
                airquality, cluster = ~Day)
    
    est_slopes = feols(Ozone ~ Solar.R + Wind | Day + Month[Temp], airquality)
    
    
    etable(est, est_slopes, tex = TRUE)
    ```

Output:

enter image description here

Julian
  • 6,586
  • 2
  • 9
  • 33
  • Thank you, so the first option works for me, the second doesn't. But it doesn't show me different models side-by-side (as your est.1 and est.2 that are side-by-side in the table), but beneath each other. Any suggestions on that? – tiny Mar 06 '23 at 23:42
  • Did you install the parse latex filter as suggested in the link? – Julian Mar 10 '23 at 20:09