R Markdown

Importing GHED Data

ghed_raw <- read_xlsx("GHED_data.xlsx", sheet = "Data") %>%
  select(country, code, year, 
         gghed_usd, gghed_usd2021, gghed_usd2021_pc,
         gdp_usd2021_pc, gghed_gdp, gge_gdp) %>%
  mutate(est_type = "observed")

# View the resulting data frame
#print(ghed_raw)

Get Logs and Run Fixed Effects Model with PLM (Full Dataset)

# Calculate log values and add them to the data frame
ghed_raw <- ghed_raw %>%
  mutate(
    log_gdp_pc = log(gdp_usd2021_pc),
    log_gghed_pc = log(gghed_usd2021_pc),
    contract = ifelse((log_gdp_pc - dplyr::lag(log_gdp_pc)) < 0, 1, 0)
  )


fixed_model <- plm(log_gghed_pc ~ log_gdp_pc + contract +
                     log_gdp_pc*contract , data = ghed_raw,index =
                     c("country", "year"), model = "within")

Exclude certain countries and years

ghed_filtered <- ghed_raw %>%
    mutate(
    log_gdp_pc = log(gdp_usd2021_pc),
    log_gghed_pc = log(gghed_usd2021_pc),
    log_gge_gdp = log(gge_gdp),
    contract = ifelse((log_gdp_pc-dplyr::lag(log_gdp_pc))<0,1,0)
    ) %>%
    filter(!(country %in% c("Cuba", "South Sudan", "Venezuela", "Yemen",
                          "Zimbabwe"))) %>%
    filter(!(year %in% c("2020", "2021", "2022"))) %>%
    na.omit()  # Remove any rows with NA values



model1 <- plm(log_gghed_pc ~ log_gdp_pc, data = ghed_filtered,index =
                     c("country", "year"), model = "within")
model2 <- plm(log_gghed_pc ~ log_gdp_pc + contract +log_gdp_pc*contract, 
              data = ghed_filtered,index = c("country", "year"), model = "within")
model3 <- plm(log_gghed_pc ~ log_gdp_pc + contract + log_gdp_pc*contract + 
                log_gge_gdp + log_gge_gdp*contract,data = ghed_filtered,
                index = c("country", "year"), model = "within")

# Use stargazer to display the model summary
stargazer(model1, model2, model3, type="text",align = TRUE,
           out = "model_comparison.txt")  # Export to a text file)
## 
## ========================================================================================================
##                                                      Dependent variable:                                
##                      -----------------------------------------------------------------------------------
##                                                         log_gghed_pc                                    
##                                  (1)                         (2)                         (3)            
## --------------------------------------------------------------------------------------------------------
## log_gdp_pc                    1.269***                    1.276***                    1.161***          
##                                (0.022)                     (0.022)                     (0.020)          
##                                                                                                         
## contract                                                  -0.134**                     -0.064           
##                                                            (0.057)                     (0.066)          
##                                                                                                         
## log_gge_gdp                                                                           0.617***          
##                                                                                        (0.023)          
##                                                                                                         
## log_gdp_pc:contract                                       0.021***                     -0.005           
##                                                            (0.006)                     (0.006)          
##                                                                                                         
## contract:log_gge_gdp                                                                   0.041**          
##                                                                                        (0.019)          
##                                                                                                         
## --------------------------------------------------------------------------------------------------------
## Observations                    3,698                       3,698                       3,698           
## R2                              0.493                       0.498                       0.593           
## Adjusted R2                     0.466                       0.471                       0.570           
## F Statistic          3,415.132*** (df = 1; 3509) 1,159.300*** (df = 3; 3507) 1,019.727*** (df = 5; 3505)
## ========================================================================================================
## Note:                                                                        *p<0.1; **p<0.05; ***p<0.01