1

I am trying to reproduce nice stargazer model (lm) output for model that is not supperted by stargazer.

can linear model stargazer output be produced by hand? Since we can create a dataframe from every model and than insert the created dataframe to stargazer:



library(spdep)

data(afcon, package="spData")

afcon$Y = rnorm(42, 50, 20)

cns <- knearneigh(cbind(afcon$x, afcon$y), k=7, longlat=T)
scnsn <- knn2nb(cns, row.names = NULL, sym = T)
W <- nb2listw(scnsn, zero.policy = TRUE)

ols <- lm(totcon ~ Y, data = afcon)

spatial.lag <- lagsarlm(totcon ~ Y, data = afcon, W)
summary(model)

stargazer(ols, type = "text")


summary(spatial.lag)
data.frame(
  spatial.lag$coefficients,
  spatial.lag$rest.se
) %>%
  rename(coeffs = spatial.lag.coefficients, 
         se = spatial.lag.rest.se) %>% 
  stargazer(type = "text", summary = F)

when we do stargazer(ols) output is very nice, I woud like to reproduce same output by hand for spatial.lag is there a way how to do so, how superscript etc...

Petr
  • 1,606
  • 2
  • 14
  • 39

2 Answers2

0

You mean ^{*}? If so it's not possible in stargazer!! I've already tried it so I recommend you to check the xtable package like I did here.

cdcarrion
  • 574
  • 6
  • 22
0

I will show one approach that can be used: stargazer is really nice and you CAN even create table like above even with the model objects that are not yet supported, e.g. lets say that quantile regression model is not supported by stargazer (even thought is is):

Trick is, you need to be able to obtain coefficients and standart error e.g. as vector. Then supply stargazer with model object that is suppoerted e.g. lm as a template and then mechanically specify which coefficients and standart errors should be used:

library(stargazer)
library(tidyverse)
library(quantreg)


df <- mtcars

model1 <- lm(hp ~ factor(gear) + qsec + disp, data = df)
quantreg <- rq(hp ~ factor(gear) + qsec + disp, data = df)
summary_qr <- summary(quantreg, se = "boot")

# Standart Error for quant reg
se_qr = c(211.78266, 29.17307, 58.61105, 9.70908, 0.12090)

stargazer(model1, model1, 
          coef = list(NULL, summary_qr$coefficients),
          se = list(NULL, se_qr),
          type = "text")

Petr
  • 1,606
  • 2
  • 14
  • 39