Search code examples
rgravity

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


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


Solution

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