How to create a table of gravity models side by side, using the Gravity Package in r

谁说胖子不能爱 提交于 2021-01-28 00:55:54

问题


I would like to create a table like the tables from the stargazer Package. But using the Gravity Package for creating gravity models, this package isn´t supported by the stargazer package yet.

Do you have an idea, how to create a similar table with 3-5 models side by side for better comparison?

Output should look like this, just with gravity models from the gravity package in r:

Desired Output Style: Desired Output Style


回答1:


Please provide an example of model object created by gravity package.

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



来源:https://stackoverflow.com/questions/63300261/how-to-create-a-table-of-gravity-models-side-by-side-using-the-gravity-package

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!