0

I have a series of 33 fixed effects regressions. Each regression has its own unique dependent variable: the cost of different trade product types. Each trade product type has two regressions for two different key independent variables, STC_exp and STC_import.

lval28_exports_tradeonly <- felm(lval28 ~ STC_exp | pair + year | 0 | pair, subset(STC_Data, NoTrade28 == 1))
lval28_imports_tradeonly <- felm(lval28 ~ STC_imp | pair + year | 0 | pair, subset(STC_Data, NoTrade28 == 1))

lval29_exports_tradeonly <- felm(lval29 ~ STC_exp | pair + year | 0 | pair, subset(STC_Data, NoTrade29 == 1))
lval29_imports_tradeonly <- felm(lval29 ~ STC_imp | pair + year | 0 | pair, subset(STC_Data, NoTrade29 == 1))

What I want to do is create a coefficient plot so that the two independent variables for each of the dependent variables either share the same line on the coefficient plot or can be grouped together. I tried doing this with plot_summs in jtools package and some other packages, but I'm not having much success.

I can make each figure individually:

ore <- plot_summs(lval26_imports_tradeonly, lval26_exports_tradeonly, coefs = c("Ore" = "STC_exp", "Ore" = "STC_imp"), model.names = c("STC on importer", "STC on exporter"))

inorganic.chemicals <- plot_summs(lval28_imports_tradeonly, lval28_exports_tradeonly, coefs = c("Inorganic Chemicals" = "STC_exp", "Inorganic Chemicals" = "STC_imp"), model.names = c("STC on importer", "STC on exporter"))

But I would like to be able to combine them in some way. Perhaps the jtools package isn't the right away to go?

enter image description here enter image description here

1 Answer 1

3

You could just make it with ggplot directly.

Below, I make some example data that looks to have similar properties to yours. Without your data, I can't replicate your example directly.

library(tibble)
library(dplyr)
library(tidyr)

set.seed(25443)
dat <- tibble(STC_exp  = runif(500, -3, 3), 
              STC_imp = runif(500, -3, 3))

b1 <- runif(33, .1, .5)
b2 <- runif(33, .1, .5)
for(i in 1:33){
  dat[[paste0("lval", i)]] <- b1[i] * dat$STC_exp + b2[i] * dat$STC_imp + rnorm(500, 0, .25)
}

reshape the data to long-format on both STC_ variables and all of the lval variables.

library(tidyr)
dat <- dat %>% pivot_longer(cols=c("STC_exp", "STC_imp"), names_to= "ie", values_to = "stc")
dat <- dat %>% pivot_longer(cols=starts_with("lval"), names_to="var", values_to = "lval")

Run the models and collect the output.

library(purrr)
library(broom)

mods <- dat %>%
  group_by(ie, var) %>% 
  summarise(lm_mod= list(lm(lval ~ stc))) %>%
  mutate(tidied = map(lm_mod,tidy,conf.int = TRUE)) %>%
  unnest(tidied)
mods <- select(mods, -lm_mod) %>% 
  filter(term == "stc")

Make the plot

library(ggplot2)
mods %>% 
  mutate(ie = factor(ie, levels=c("STC_exp", "STC_imp"), 
                     labels=c("STC on Exporter", "STC on Importer"))) %>% 
ggplot(aes(x=estimate, y=var, colour=ie)) + 
  geom_point(position = position_dodge(width=.75)) + 
  geom_errorbarh(aes(xmin=conf.low, xmax=conf.high), position=position_dodge(width=.75), height=0) + 
  labs(x="Estimate", y="", colour="Model") + 
  theme_bw()

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you, I can see how that code could work. The data set is over 500k, and my computer I don't think has enough memory to make the necessary vector to run the remainder of the code. Also, each chapter of trade uses a different set of observations, so I'd have to play around with it. But I understand what you did. Can I make the same graph you did but just extract the necessary coefficient and ci's from the data?
@Keith absolutely, you'd just need a column that identifies STC export or import (i called it ie in my data), one that identifies the dependent variable (I called it var) and then columns for the estimate Estimate, lower bound conf.low and upper bound, conf.high.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.