简体   繁体   中英

stargazer output: how to omit one value of as.factor(variable)?

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? ( NB : this is not what this question asks, which wants to omit ALL entries of the variables.)

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

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"))

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM