Adjust prices to 2014 prices

library(jsonlite)
## 
## Attaching package: 'jsonlite'
## The following object is masked from 'package:purrr':
## 
##     flatten
library(priceR)

country <- "United States"
countries_dataframe <- show_countries()

Generating URL to request all 299 results

inflation_dataframe <- retrieve_inflation_data(country, countries_dataframe)

Retrieving inflation data for US Generating URL to request all 61 results

# Provide a World Bank API URL and `url_all_results` will convert it into one with all results for that indicator
original_url <- "http://api.worldbank.org/v2/country" 

# "http://api.worldbank.org/v2/country?format=json&per_page=304"
url_all_results(original_url)

Generating URL to request all 299 results [1] “http://api.worldbank.org/v2/country?format=json&per_page=299

my_df$budget_2014_const <- adjust_for_inflation(my_df$pd_budget, 
                                                my_df$year, 
                                                country, 
                                                to_date = 2014,
                                                inflation_dataframe = inflation_dataframe,
                                                countries_dataframe = countries_dataframe)

my_df$budget_pc_2014_const <- adjust_for_inflation(my_df$pd_budget_pc, 
                                                   my_df$year, 
                                                   country, 
                                                   to_date = 2014,
                                                   inflation_dataframe = inflation_dataframe,
                                                   countries_dataframe = countries_dataframe)
my_df %<>% 
  group_by(year) %>% 
  mutate(total_budget = sum(pd_budget, na.rm = TRUE)) %>% 
  ungroup() %>% 
  group_by(cow_code, year) %>% 
  mutate(budget_proportion = pd_budget / total_budget ) %>% 
  mutate(budget_percent = budget_proportion*100) %>% 
  ungroup()  

Full

my_df %<>% 
  mutate(total_trade = us_exports + us_imports) %>% 
  mutate(us_trade_dep  = (total_trade / gdp_current)*100)


stargazer(full_model <- plm(lead(log(budget_pc_2014_const)) ~ log(gdp_pc) + 
                              log(pop) + 
                              percent_muslim + 
                              un_agreement_score +
                              polity_index +
                              log(us_exports),
  
                            data = my_df,
                            model = "within", effect = "time",
                            index = c("cow_code", "year")), type = "html", style = "apsr")
lead(log(budget_pc_2014_const))
log(gdp_pc) 0.111***
(0.036)
log(pop) -0.455***
(0.026)
percent_muslim 0.004***
(0.001)
un_agreement_score 0.097
(0.231)
polity_index 0.015***
(0.005)
log(us_exports) 0.021
(0.021)
N 1,066
R2 0.477
Adjusted R2 0.471
F Statistic 160.259*** (df = 6; 1053)
p < .1; p < .05; p < .01
stargazer(full_model <- plm(lead(log(budget_pc_2014_const)) ~ log(gdp_pc) + 
                              log(pop) + 
                              percent_muslim + 
                              un_agreement_score +
                              polity_index +
                              log(us_exports),
  
                            data = my_df,
                            model = "within", effect = "time",
                            index = c("cow_code", "year")), type = "html", style = "asr")
lead(log(budget_pc_2014_const))
log(gdp_pc) 0.111**
log(pop) -0.455***
percent_muslim 0.004***
un_agreement_score 0.097
polity_index 0.015**
log(us_exports) 0.021
N 1,066
R2 0.477
Adjusted R2 0.471
F Statistic 160.259*** (df = 6; 1053)
p < .05; p < .01; p < .001
stargazer(full_model <- plm(lead(log(budget_pc_2014_const)) ~ log(gdp_pc) + 
                              log(pop) + 
                              percent_muslim + 
                              un_agreement_score +
                              polity_index +
                              log(us_exports),
  
                            data = my_df,
                            model = "within", effect = "time",
                            index = c("cow_code", "year")), type = "html", style = "aer")
lead(log(budget_pc_2014_const))
log(gdp_pc) 0.111***
(0.036)
log(pop) -0.455***
(0.026)
percent_muslim 0.004***
(0.001)
un_agreement_score 0.097
(0.231)
polity_index 0.015***
(0.005)
log(us_exports) 0.021
(0.021)
Observations 1,066
R2 0.477
Adjusted R2 0.471
F Statistic 160.259*** (df = 6; 1053)
Notes: ***Significant at the 1 percent level.
**Significant at the 5 percent level.
*Significant at the 10 percent level.
stargazer(full_model <- plm(lead(log(budget_pc_2014_const)) ~ log(gdp_pc) + 
                              log(pop) + 
                              percent_muslim + 
                              un_agreement_score +
                              polity_index +
                              log(us_exports),
  
                            data = my_df,
                            model = "within", effect = "time",
                            index = c("cow_code", "year")), type = "html", style = "io")
lead(log(budget_pc_2014_const))
LOG(GDP_PC) 0.111***
(0.036)
LOG(POP) -0.455***
(0.026)
PERCENT_MUSLIM 0.004***
(0.001)
UN_AGREEMENT_SCORE 0.097
(0.231)
POLITY_INDEX 0.015***
(0.005)
LOG(US_EXPORTS) 0.021
(0.021)
Observations 1,066
R-squared 0.477
Adjusted R-squared 0.471
F statistic 160.259*** (df = 6; 1053)
Notes: p < .01; p < .05; p < .1
stargazer(full_model <- plm(lead(log(budget_pc_2014_const)) ~ log(gdp_pc) + 
                              log(pop) + 
                              percent_muslim + 
                              un_agreement_score +
                              polity_index +
                              log(us_exports),
  
                            data = my_df,
                            model = "within", effect = "time",
                            index = c("cow_code", "year")), type = "html", style = "qje")
lead(log(budget_pc_2014_const))
log(gdp_pc) 0.111***
(0.036)
log(pop) -0.455***
(0.026)
percent_muslim 0.004***
(0.001)
un_agreement_score 0.097
(0.231)
polity_index 0.015***
(0.005)
log(us_exports) 0.021
(0.021)
N 1,066
R2 0.477
Adjusted R2 0.471
F Statistic 160.259*** (df = 6; 1053)
Notes: ***Significant at the 1 percent level.
**Significant at the 5 percent level.
*Significant at the 10 percent level.
stargazer(full_model <- plm(lead(log(budget_pc_2014_const)) ~ log(gdp_pc) + 
                              log(pop) + 
                              percent_muslim + 
                              un_agreement_score +
                              polity_index +
                              log(us_exports),
  
                            data = my_df,
                            model = "within", effect = "time",
                            index = c("cow_code", "year")), type = "html", style = "ajs")
LEAD(LOG(BUDGET_PC_2014_CONST))
log(gdp_pc) .111**
(.036)
log(pop) -.455***
(.026)
percent_muslim .004***
(.001)
un_agreement_score .097
(.231)
polity_index .015**
(.005)
log(us_exports) .021
(.021)
Observations 1,066
R2 .477
Adjusted R2 .471
F Statistic 160.259*** (df = 6; 1053)
Notes: *P < .05
**P < .01
***P < .001

Including Plots

library(rnaturalearth)

map <- ne_countries(scale = "medium", returnclass = "sf")


my_df %<>% 
  dplyr::mutate(political_geo = ifelse(geo_region == 1, "Post Soviet",
                                       ifelse(geo_region == 2, "Latin", 
                                              ifelse(geo_region == 10, "Latin",
                                                     ifelse(geo_region == 9, "Latin",
                                                            ifelse(geo_region == 3, "MENA",
                                                                   ifelse(geo_region == 4, "Africa",
                                                                          ifelse(geo_region == 5, "West",
                                                                                 ifelse(geo_region == 6, "Asia",
                                                                                        ifelse(geo_region == 7, "Asia",
                                                                                               ifelse(geo_region == 8, "Asia", geo_region)))))))))))


my_df19 <- my_df[which(my_df$year == 2019),]

map$COWcode <- countrycode(map$sov_a3, "iso3c", "cown") 

map19 <- merge(map, my_df19, by.x = "COWcode", by.y = "cow_code", all.x = TRUE)

map19 %>% 
  group_by(country_name.x) %>% 
  fill(geo_region, .direction = "updown") -> map2

ggplot(data = map19) +
  geom_sf(aes(fill = as.factor(political_geo)), 
          position = "identity") + 
  labs(fill='Freedom of Association Index') + ggthemes::theme_map() + theme(legend.position = "blank")

soviet_model <- plm(lead(log(budget_2014_const)) ~ log(gdp_pc) + 
                              log(pop) + 
                              percent_muslim + 
                              log(us_troops + 1) + 
                              un_agreement_score +
                              as.factor(president) +
                              # polity_index + 
                              civ_lib_fh +
                              pol_right_fh +
                              log(us_exports + 1) +
                              log(us_imports + 1),
                            data = post_sov_df,
                            model = "within", effect = "time",
                            index = c("cow_code", "year"))

latin_model <- plm(lead(log(budget_2014_const)) ~ log(gdp_pc) + 
                              log(pop) + 
                              percent_muslim + 
                              log(us_troops + 1) + 
                              un_agreement_score +
                              as.factor(president) +
                              # polity_index +
                              civ_lib_fh +
                              pol_right_fh +
                              log(us_exports + 1) +
                              log(us_imports + 1),
                            data = latin_am_df,
                            model = "within", effect = "time",
                            index = c("cow_code", "year"))


mena_model <- plm(lead(log(budget_2014_const)) ~ log(gdp_pc) + 
                              log(pop) + 
                              percent_muslim + 
                              log(us_troops + 1) + 
                              un_agreement_score +
                              as.factor(president) +
                              civ_lib_fh +
                              pol_right_fh +
                              # polity_index + 
                              log(us_exports + 1) +
                              log(us_imports + 1),
                            data = mena_df,
                            model = "within", effect = "time",
                            index = c("cow_code", "year"))


west_model <- plm(lead(log(budget_2014_const)) ~ log(gdp_pc) + 
                              log(pop) + 
                              percent_muslim + 
                              log(us_troops + 1) + 
                              un_agreement_score +
                              as.factor(president) +
                    civ_lib_fh +
                              pol_right_fh +
                              # polity_index + 
                              log(us_exports + 1) +
                              log(us_imports + 1),
                            data = west_df,
                            model = "within", effect = "time",
                            index = c("cow_code", "year"))


asia_model <- plm(lead(log(budget_2014_const)) ~ log(gdp_pc) + 
                              log(pop) + 
                              percent_muslim + 
                              log(us_troops + 1) + 
                              un_agreement_score +
                    civ_lib_fh +
                              pol_right_fh +
                              # as.factor(president) +
                              # polity_index + 
                              log(us_exports + 1) +
                              log(us_imports + 1),
                            data = asia_df,
                            model = "within", effects = "time",
                            index = c("cow_code", "year"))


africa_model  <- plm(lead(log(budget_2014_const)) ~ log(gdp_pc) + 
                              log(pop) + 
                              percent_muslim + 
                              log(us_troops + 1) + 
                              un_agreement_score +
                       civ_lib_fh +
                              pol_right_fh +
                              as.factor(president) +
                              # polity_index + 
                              log(us_exports + 1) +
                              log(us_imports + 1),
  
                            data = africa_df,
                            model = "within", effect = "time",
                            index = c("cow_code", "year"))

full_model  <- plm(lead(log(budget_2014_const)) ~ log(gdp_pc) + 
                              log(pop) + 
                              percent_muslim + 
                              log(us_troops + 1) + 
                              un_agreement_score +
                              as.factor(president) +
                              # polity_index + 
                     civ_lib_fh +
                              pol_right_fh +
                              log(us_exports + 1) +
                              log(us_imports + 1),
  
                            data = my_df,
                            model = "within", effect = "time",
                            index = c("cow_code", "year"))
 

stargazer(africa_model, west_model, mena_model, latin_model, soviet_model, asia_model,  
          column.labels = c("Africa", "West", "MENA", "Latin", "Soviet", "Asia"), type = "html", style = "io")
lead(log(budget_2014_const))
Africa West MENA Latin Soviet Asia
(1) (2) (3) (4) (5) (6)
LOG(GDP_PC) 0.180* 0.167 -0.310* -0.025 -0.325** 1.631**
(0.097) (0.154) (0.181) (0.109) (0.146) (0.706)
LOG(POP) 0.498*** 0.554*** 0.163 0.451*** 0.289*** 0.318
(0.066) (0.096) (0.139) (0.059) (0.104) (2.449)
PERCENT_MUSLIM 0.002* -0.004 0.001 0.004 -0.001 0.001
(0.001) (0.002) (0.002) (0.003) (0.002) (0.002)
LOG(US_TROOPS + 1) 0.056 -0.006 0.117*** 0.008 -0.048 0.272**
(0.044) (0.029) (0.035) (0.049) (0.042) (0.105)
UN_AGREEMENT_SCORE -0.490 0.984 0.407 -0.729 1.327** -0.748
(0.802) (0.910) (0.544) (0.911) (0.627) (0.650)
CIV_LIB_FH -0.162** -0.307 -0.078 -0.241** 0.009 0.382
(0.075) (0.245) (0.133) (0.099) (0.104) (0.246)
POL_RIGHT_FH 0.015 0.408 -0.065 0.021 0.102 -0.220
(0.062) (0.282) (0.092) (0.083) (0.083) (0.150)
LOG(US_EXPORTS + 1) -0.005 -0.002 0.105 0.096 -0.001 -0.177
(0.060) (0.084) (0.118) (0.103) (0.070) (0.275)
LOG(US_IMPORTS + 1) 0.023 -0.129* 0.136** -0.040 0.046 -0.065
(0.038) (0.077) (0.056) (0.049) (0.072) (0.168)
Observations 257 149 118 167 178 127
R-squared 0.432 0.622 0.489 0.666 0.427 0.174
Adjusted R-squared 0.397 0.580 0.414 0.633 0.374 -0.051
F statistic 20.371*** (df = 9; 241) 24.362*** (df = 9; 133) 10.842*** (df = 9; 102) 33.452*** (df = 9; 151) 13.426*** (df = 9; 162) 2.318** (df = 9; 99)
Notes: p < .01; p < .05; p < .1
pd_budget <- plm(lead(log(pd_budget)) ~ log(gdp_pc) + 
                              log(pop) + 
                   as.factor(war_terror)*log(us_troops + 1) + 
                              percent_muslim + 
                             un_agreement_score +
                              as.factor(president) +
                              # civ_lib_fh + 
                              # pol_right_fh +
                              polity_index +
                              us_imports,
                              data = my_df,
                            model = "within", effect = "time",
                            index = c("cow_code", "year"))

stargazer(pd_budget, type = "html")
Dependent variable:
lead(log(pd_budget))
log(gdp_pc) 0.134***
(0.023)
log(pop) 0.415***
(0.019)
as.factor(war_terror)1 1.162**
(0.535)
log(us_troops + 1) 0.017
(0.013)
percent_muslim 0.002***
(0.001)
un_agreement_score 0.085
(0.213)
polity_index 0.008
(0.005)
us_imports -0.00000*
(0.00000)
as.factor(war_terror)1:log(us_troops + 1) 0.114
(0.070)
Observations 1,010
R2 0.496
Adjusted R2 0.488
F Statistic 108.629*** (df = 9; 994)
Note: p<0.1; p<0.05; p<0.01
peace_corps_model <- plm(lead(log(sum_peace_corps + 1)) ~ log(gdp_pc) + 
                              log(pop) + 
                              percent_muslim +
                              log(us_troops + 1) + 
                              un_agreement_score +
                              as.factor(president) +
                              # civ_lib_fh + 
                              # pol_right_fh +
                              polity_index +
                              log(us_exports + 1) +
                              log(us_imports + 1),
                         data = my_df,
                            model = "within", effect = "time",
                            index = c("cow_code", "year"))


disaster_model <- plm(lead(log(sum_disaster_assist + 1)) ~ log(gdp_pc) + 
                              log(pop) + 
                              percent_muslim + 
                              log(us_troops + 1) + 
                              un_agreement_score +
                              as.factor(president) +
                              # civ_lib_fh + 
                              # pol_right_fh +
                              polity_index + 
                              log(us_exports + 1) +
                              log(us_imports + 1),
                      data = my_df,
                            model = "within", effect = "time",
                            index = c("cow_code", "year"))


food_aid_model <- plm(lead(log(sum_food_assist + 1)) ~ log(gdp_pc) + 
                              log(pop) + 
                              percent_muslim + 
                              log(us_troops + 1) + 
                              un_agreement_score +
                              as.factor(president) + 
                              # civ_lib_fh + 
                              # pol_right_fh +
                             polity_index + 
                              log(us_exports + 1) +
                              log(us_imports + 1) ,
                      data = my_df,
                            model = "within", effect = "time",
                            index = c("cow_code", "year"))


econ_aid_model <- plm(lead(log(sum_econ + 1)) ~ log(gdp_pc) + 
                              log(pop) + 
                              percent_muslim + 
                              log(us_troops + 1) + 
                              un_agreement_score +
                              as.factor(president) +
                              # civ_lib_fh + 
                              # pol_right_fh + 
                              polity_index + 
                              log(us_exports + 1) +
                              log(us_imports + 1),
                      data = my_df,
                            model = "within", effect = "time",
                            index = c("cow_code", "year"))

military_aid_model  <- plm(lead(log(sum_military + 1)) ~ log(gdp_pc) + 
                              log(pop) + 
                              percent_muslim + 
                              log(us_troops + 1) + 
                              un_agreement_score +
                              as.factor(president) + 
                              # civ_lib_fh + 
                              # pol_right_fh +
                              polity_index + 
                              log(us_exports + 1) +
                              log(us_imports + 1),
                           data = my_df,
                            model = "within", effect = "time",
                            index = c("cow_code", "year"))

ned_model  <- plm(lead(log(sum_ned + 1)) ~ log(gdp_pc) + 
                              log(pop) + 
                              percent_muslim + 
                              log(us_troops + 1) + 
                              un_agreement_score +
                              as.factor(president) + 
                              # civ_lib_fh + 
                              # pol_right_fh +
                              polity_index + 
                              log(us_exports + 1) +
                              log(us_imports + 1),
                            data = my_df,
                            model = "within", effect = "time",
                            index = c("cow_code", "year"))

stargazer(pd_budget, ned_model, peace_corps_model, military_aid_model, disaster_model, econ_aid_model, food_aid_model,
                    dep.var.labels.include = FALSE,
           column.labels = c("Public Diplomacy", "Endowment Democracy", "Peace Corps", "Military Aid", "Disaster Aid", "Economic Aid",  "Food Aid"), type = "html")
Dependent variable:
Public Diplomacy Endowment Democracy Peace Corps Military Aid Disaster Aid Economic Aid Food Aid
(1) (2) (3) (4) (5) (6) (7)
log(gdp_pc) 0.134*** -1.753*** -3.541*** -2.672*** -4.486*** -2.243*** -3.455***
(0.023) (0.281) (0.332) (0.250) (0.318) (0.163) (0.293)
log(pop) 0.415*** 1.054*** -1.512*** -1.038*** -0.190 0.007 0.174
(0.019) (0.208) (0.246) (0.185) (0.236) (0.120) (0.217)
as.factor(war_terror)1 1.162**
(0.535)
log(us_troops + 1) 0.017 -0.141 -0.288** 0.137 0.179 -0.006 0.468***
(0.013) (0.104) (0.123) (0.093) (0.118) (0.060) (0.109)
percent_muslim 0.002*** 0.009 -0.012* 0.024*** 0.009 0.007** -0.006
(0.001) (0.006) (0.007) (0.005) (0.006) (0.003) (0.006)
un_agreement_score 0.085 -3.564** -2.559 3.801*** -2.026 -2.495*** 1.534
(0.213) (1.653) (1.950) (1.471) (1.871) (0.957) (1.726)
polity_index 0.008 -0.167*** 0.203*** 0.070** 0.079* -0.029 0.040
(0.005) (0.037) (0.044) (0.033) (0.042) (0.022) (0.039)
us_imports -0.00000*
(0.00000)
as.factor(war_terror)1:log(us_troops + 1) 0.114
(0.070)
log(us_exports + 1) 0.296 1.410*** 0.484*** 0.696*** 0.343*** 0.139
(0.196) (0.231) (0.174) (0.222) (0.113) (0.204)
log(us_imports + 1) -0.284* -0.041 0.486*** 0.541*** 0.180** -0.142
(0.146) (0.172) (0.130) (0.165) (0.084) (0.152)
Observations 1,010 900 900 900 900 900 900
R2 0.496 0.361 0.240 0.152 0.387 0.453 0.400
Adjusted R2 0.488 0.351 0.228 0.139 0.377 0.444 0.391
F Statistic 108.629*** (df = 9; 994) 62.603*** (df = 8; 885) 34.886*** (df = 8; 885) 19.865*** (df = 8; 885) 69.832*** (df = 8; 885) 91.535*** (df = 8; 885) 73.808*** (df = 8; 885)
Note: p<0.1; p<0.05; p<0.01
# stargazer( pd_budget, ned_model, peace_corps_model, food_aid_model,
#                     dep.var.labels.include = FALSE,
#            column.labels = c("Public Diplomacy2", "Endowment Democracy", "Peace Corps", "Food Aid"), type = "html")

Examine only 2019

full <- lm(log(pd_budget) ~ log(gdp_pc) + 
                              log(pop) + 
                              percent_muslim + 
                              log(us_troops + 1) + 
                              un_agreement_score +
                              # polity_index + 
                              civ_lib_fh +
                              pol_right_fh,
                             # as.factor(contig_china) + 
                             # as.factor(contig_russia),
                              data = my_df19)

stargazer(full, type = "html")
Dependent variable:
log(pd_budget)
log(gdp_pc) 0.175***
(0.066)
log(pop) 0.416***
(0.047)
percent_muslim -0.001
(0.002)
log(us_troops + 1) 0.080*
(0.042)
un_agreement_score 0.767
(0.529)
civ_lib_fh 0.240**
(0.106)
pol_right_fh -0.137
(0.083)
Constant 4.971***
(1.030)
Observations 140
R2 0.549
Adjusted R2 0.525
Residual Std. Error 0.719 (df = 132)
F Statistic 22.977*** (df = 7; 132)
Note: p<0.1; p<0.05; p<0.01