M.Qasim
M.Qasim

Reputation: 1878

How to exclude standard errors from stargazer table?

Amazing R gurus,

I am just wondering if there is any way to exclude standard errors from stargazer table.

Here is a quick reproducible example:

---
title: "Test regression"
output: html_document
date: "`r format(Sys.time(), '%d %B, %Y')`"
---

```{r setup, echo=FALSE, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
knitr::opts_chunk$set(warning = FALSE)
knitr::opts_chunk$set(cashe = TRUE)

rm(list=ls())
library(stargazer)
library(ggplot2)

```


```{r, results='asis', echo=FALSE}

fit <- lm(price ~ carat + table + x + y + z, data = diamonds)

stargazer(fit, title="Diamonds Regression",
          single.row = TRUE, type ="html", header = FALSE, df=FALSE, digits=2, se = NULL)

```

I would like to see results without standard error like shown in the following screenhsot.

enter image description here

Your time and help is much appreciated.

Upvotes: 2

Views: 3417

Answers (2)

Christoph Pahmeyer
Christoph Pahmeyer

Reputation: 626

I just wanted to achieve the same thing, and found the report argument in the stargazer documentation, wich can be used to control the elements shown (and the order) in the output table. If used like this:

fit <- lm(price ~ carat + table + x + y + z, data = diamonds)

stargazer(fit, title="Diamonds Regression",
          single.row = TRUE, 
          type ="html", 
          report = "vc*", 
          header = FALSE, 
          df=FALSE, 
          digits=2, 
          se = NULL
)

It produces the desired output without the need to capture the output first (or any other additional code). enter image description here

Upvotes: 3

Martin Schmelzer
Martin Schmelzer

Reputation: 23889

Here is a simple way:

```{r, results='asis', echo=FALSE}
fit <- lm(price ~ carat + table + x + y + z, data = diamonds)
mytab <- capture.output(stargazer(fit, title="Diamonds Regression",
                        single.row = TRUE, type ="html", header = FALSE, df=FALSE,
                        digits=2, 
                        apply.se = function(x) { 0 }))

cat(paste(gsub("\\(0.00\\)", "", mytab), collapse = "\n"), "\n")
```

We first capture the output of stargazer and suppress automatic printing. In stargazer we set all standard errors to be 0 (makes the following replacement more failsave). Lastly, we print the output and replace these standard errors.

enter image description here

Upvotes: 1

Related Questions