I used package jtools to plot coefficients from multiple separate regression. Here is the code I used:
library(tidyverse)
library(dplyr)
library(tibble)
library(readr)
library(psych)
library(ggplot2)
library(gghighlight)
library(stargazer)
library(lmtest)
library(sandwich)
library(multiwayvcov)
library(jtools)
setwd("/cloud/project")
data <- read_csv("mydata.csv")
str(data)
# delete missing value
data1<-data%>%
pivot_wider(names_from=year, values_from=lrgdpchlight)%>%
pivot_longer(
cols=c('1992','1993','1994','1995','1996','1997','1998','1999','2000','2001','2002','2003','2004','2005','2006','2007','2008','2009','2010'),
names_to = "year",
values_to = "lrgdpchlight",
values_drop_na = TRUE
)
data2<-data1%>%
pivot_wider(names_from=year, values_from=lrgdpchWB)%>%
pivot_longer(
cols=c('1992','1993','1994','1995','1996','1997','1998','1999','2000','2001','2002','2003','2004','2005','2006','2007','2008','2009','2010'),
names_to = "year",
values_to = "lrgdpchWB",
values_drop_na = TRUE
)
str(data2)
## Delete outlier
mydata<-filter(data2, (e_hat<1)|(e_hat==1))
str(mydata)
mydata<-as.data.frame(mydata)
# dependent variable
y <-mydata$e_hat
# country fixed effect
country_fixed_effect <-factor(mydata$iso_n)
## Regress country fixed effect
reg0<-lm(y~country_fixed_effect)
summary(reg0)
adjust.r.squared0<-summary(reg0)$adj.r.squared
adjust.r.squared0
vcov_country0 <- cluster.vcov(reg0, mydata$iso_n) # Clustered standard errors
model0<-coeftest(reg0,vcov_country0)
## GDP sectors analysis
# Agriculture, forestry, and fishing, value added (% of GDP)
agriculture <-mydata$NV.AGR.TOTL.ZS
reg1<-lm(y~country_fixed_effect+agriculture)
summary(reg1)
#Industry (including construction), value added (% of GDP)
industry<-mydata$NV.IND.TOTL.ZS
reg2<-lm(y~country_fixed_effect+industry)
summary(reg2)
#Services, value added (% of GDP)
service <-mydata$NV.SRV.TOTL.ZS
reg3<-lm(y~country_fixed_effect+service)
summary(reg3)
plot_summs(reg1,reg2,reg3,point.shape=FALSE,robust=TRUE,scale=TRUE, omit.coefs = c("(Intercept)","country_fixed_effect"))
I got the following error:
Error: Assigned data `x$coeftable[, lci_lab]` must be compatible with existing data.
x Existing data has 0 rows.
x Assigned data has 165 rows.
ℹ Only vectors of size 1 are recycled.
Backtrace:
Could you please help me?