I have two regressions to report in stargazer
in R
, with add.lines()
adding a predicted table at the end. My table currently looks like:
but I want to add a line right below "Predicted Values on x Values", so that it is its own row like we have in the "Observations" row. Is there a way to do this?
Code to generate regression data:
x <- 1:100
y <- rnorm(100, 4*x, 5)
mod1 <- lm(y ~ x)
mod2 <- lm(y ~ 1)
se1 <- summary(mod1)$coef[2,2]
se2 <- summary(mod2)$coef[1,2]
mod1.pred1 <- predict(mod1, newdata=data.frame(x=1))
mod2.pred1 <- predict(mod2, newdata=data.frame(x=1))
mod1.pred2 <- predict(mod1, newdata=data.frame(x=2))
mod2.pred2 <- predict(mod2, newdata=data.frame(x=2))
Stargazer output with table:
stargazer(mod1, mod2, se = list(se1, se2), out="Results.html", notes="Two Models", keep.stat="n", type = "text",
table.layout ="ldmc#-t-s-a=n",
add.lines = list(
c("Predicted Values on x Values"),
c("", "", "", ""), # add empty list element
c("Predict when x=1",mod1.pred1,mod2.pred1),
c("Predict when x=2",mod1.pred2,mod2.pred2)),
add.lines.separator = c(1) # add separator after fourth element)