0

I have a model like this

model <-lm(outcome ~ var0 + var1 + as.factor(var2))

with var2 taking the values A, B, and C. I create the output with stargazer. I would like to omit var0 and as.factor(var2)A from the output. I couldn't achieve this; I tried:

stargazer(model, type = "html", out = "./output.html",
    omit = c("var0", "var2")) # omits ALL var2 entries

stargazer(model, type = "html", out = "./output.html",
    omit = c("var0", "as.factor(var2)B")) # omits no var2 entry in addition to the base category (A)

Can someone point me to the solution? (N.B.: this is not what this question asks, which wants to omit ALL entries of the variables.)

The second example results in this output. But I would like the entry marked in yellow to be omitted.

Ivo
  • 3,890
  • 5
  • 22
  • 53
  • using `stargazer` 5.2.2 and `R` 3.6.1 your second example works for me (BTW you're missing a comma in the examples) – starja May 26 '20 at 10:16
  • Thank you for your comment and the help; I fixed the comma and updated the question. (Unfortunately my example was poorly chosen since the base category (here: `A`) is omitted anyway - not due to my code, however. I have adjusted my example and added a desired output.) – Ivo May 26 '20 at 10:41

1 Answers1

1

This has something to do how stargazer treats the omit argument. The documentation says that it expects a vector of regular expressions. In a regular expression, ., ( and ) are a special characters, so you have to escape them, in R this is done with a double backslash\\. So your argument becomes omit = c("var0", "as\\.factor\\(var2\\)B").

stargazer(model, type = "html", out = "./output.html",
    omit = c("var0", "as\\.factor\\(var2\\)B"))

enter image description here

starja
  • 9,887
  • 1
  • 13
  • 28