R Markdown

r = getOption("repos")
r["CRAN"] = "http://cran.us.r-project.org"
options(repos = r)
all=readxl::excel_sheets("growth.xlsx")
all
##  [1] "growth"             "Trade"              "INFDI"             
##  [4] "OUFDI"              "UNEMP"              "PUBLIC_EXPENSE"    
##  [7] "POPULATION"         "GDP_DEFLATOR"       "PRIVATE_SECTOR"    
## [10] "TAX REVENUE"        "Access_Electricity" "BROAD_MONEY"
growth=readxl::read_excel("growth.xlsx",sheet="growth")
trade=readxl::read_excel("growth.xlsx",sheet="Trade")
infdi=readxl::read_excel("growth.xlsx",sheet="INFDI")
oufdi=readxl::read_excel("growth.xlsx",sheet="OUFDI")
unemp=readxl::read_excel("growth.xlsx",sheet="UNEMP")
pbe=readxl::read_excel("growth.xlsx",sheet="PUBLIC_EXPENSE")
pop=readxl::read_excel("growth.xlsx",sheet="POPULATION")
gdpd=readxl::read_excel("growth.xlsx",sheet="GDP_DEFLATOR")
psect=readxl::read_excel("growth.xlsx",sheet="PRIVATE_SECTOR")
tax=readxl::read_excel("growth.xlsx",sheet="TAX REVENUE")
accelec=readxl::read_excel("growth.xlsx",sheet="Access_Electricity")
bmoney=readxl::read_excel("growth.xlsx",sheet="BROAD_MONEY")
head(growth,3)
## # A tibble: 3 x 33
##      ID `Country Name` `Country Code` `1990` `1991` `1992` `1993` `1994` `1995`
##   <dbl> <chr>          <chr>           <dbl>  <dbl>  <dbl>  <dbl>  <dbl>  <dbl>
## 1     1 Aruba          ABW              3.96  7.96    5.88   7.31   8.20   2.55
## 2     2 Afghanistan    AFG             NA    NA      NA     NA     NA     NA   
## 3     3 Angola         AGO             -3.45  0.991  -5.84 -24.0    1.34  15.0 
## # … with 24 more variables: `1996` <dbl>, `1997` <dbl>, `1998` <dbl>,
## #   `1999` <dbl>, `2000` <dbl>, `2001` <dbl>, `2002` <dbl>, `2003` <dbl>,
## #   `2004` <dbl>, `2005` <dbl>, `2006` <dbl>, `2007` <dbl>, `2008` <dbl>,
## #   `2009` <dbl>, `2010` <dbl>, `2011` <dbl>, `2012` <dbl>, `2013` <dbl>,
## #   `2014` <dbl>, `2015` <dbl>, `2016` <dbl>, `2017` <dbl>, `2018` <dbl>,
## #   `2019` <dbl>

Reshape wide to long

#growth1=na.omit(growth)
#head(growth1,4)
growth1=reshape(growth, 
        direction = "long",
        varying = list(names(growth)[4:33]),
        v.names = "growth",
        idvar = c("ID","Country Name", "Country Code"),
        timevar = "Year",
        times = 1990:2019)
## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.
trade1=reshape(trade, 
        direction = "long",
        varying = list(names(trade)[4:33]),
        v.names = "trade",
        idvar = c("ID","Country Name", "Country Code"),
        timevar = "Year",
        times = 1990:2019)
## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.
infdi1=reshape(infdi, 
        direction = "long",
        varying = list(names(infdi)[4:33]),
        v.names = "infdi",
        idvar = c("ID","Country Name", "Country Code"),
        timevar = "Year",
        times = 1990:2019)
## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.
oufdi1=reshape(oufdi, 
        direction = "long",
        varying = list(names(oufdi)[4:33]),
        v.names = "oufdi",
        idvar = c("ID","Country Name", "Country Code"),
        timevar = "Year",
        times = 1990:2019)
## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.
unemp1=reshape(unemp, 
        direction = "long",
        varying = list(names(unemp)[4:33]),
        v.names = "unemp",
        idvar = c("ID","Country Name", "Country Code"),
        timevar = "Year",
        times = 1990:2019)
## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.
psect1=reshape(psect, 
        direction = "long",
        varying = list(names(psect)[4:33]),
        v.names = "psect",
        idvar = c("ID","Country Name", "Country Code"),
        timevar = "Year",
        times = 1990:2019)
## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.
tax1=reshape(tax, 
        direction = "long",
        varying = list(names(tax)[4:33]),
        v.names = "tax",
        idvar = c("ID","Country Name", "Country Code"),
        timevar = "Year",
        times = 1990:2019)
## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.
pbe1=reshape(pbe, 
        direction = "long",
        varying = list(names(pbe)[4:33]),
        v.names = "pbe",
        idvar = c("ID","Country Name", "Country Code"),
        timevar = "Year",
        times = 1990:2019)
## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.
pop1=reshape(pop, 
        direction = "long",
        varying = list(names(pop)[4:33]),
        v.names = "pop",
        idvar = c("ID","Country Name", "Country Code"),
        timevar = "Year",
        times = 1990:2019)
## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.
gdpd1=reshape(gdpd, 
        direction = "long",
        varying = list(names(gdpd)[4:33]),
        v.names = "gdpd",
        idvar = c("ID","Country Name", "Country Code"),
        timevar = "Year",
        times = 1990:2019)
## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.
accelec1=reshape(accelec, 
        direction = "long",
        varying = list(names(growth)[4:33]),
        v.names = "accelec",
        idvar = c("ID","Country Name", "Country Code"),
        timevar = "Year",
        times = 1990:2019)
## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.
bmoney1=reshape(bmoney, 
        direction = "long",
        varying = list(names(bmoney)[4:33]),
        v.names = "bmoney",
        idvar = c("ID","Country Name", "Country Code"),
        timevar = "Year",
        times = 1990:2019)
## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

## Warning: Setting row names on a tibble is deprecated.

MERGE DATA

#str(growth1)
total1= merge(growth1,trade1,by=c("ID","Country Name","Country Code","Year"))
total2= merge(total1,infdi1,by=c("ID","Country Name","Country Code","Year"))
total3= merge(total2,oufdi1,by=c("ID","Country Name","Country Code","Year"))
total4= merge(total3,unemp1,by=c("ID","Country Name","Country Code","Year"))
total5= merge(total4,psect1,by=c("ID","Country Name","Country Code","Year"))
total6= merge(total5,tax1,by=c("ID","Country Name","Country Code","Year"))
total7= merge(total6,pbe1,by=c("ID","Country Name","Country Code","Year"))
total8= merge(total7,pop1,by=c("ID","Country Name","Country Code","Year"))
total9= merge(total8,gdpd1,by=c("ID","Country Name","Country Code","Year"))
total10= merge(total9,accelec1,by=c("ID","Country Name","Country Code","Year"))
total11= merge(total10,bmoney1,by=c("ID","Country Name","Country Code","Year"))
head(total11)
##   ID Country Name Country Code Year   growth    trade      infdi      oufdi
## 1  1        Aruba          ABW 1990 3.961402       NA 17.0617063 63.6553106
## 2  1        Aruba          ABW 1991 7.962872       NA 21.1833966 20.3030007
## 3  1        Aruba          ABW 1992 5.882353       NA -3.8585979  1.0375082
## 4  1        Aruba          ABW 1993 7.307692       NA -1.6558907  0.6345002
## 5  1        Aruba          ABW 1994 8.203903       NA -5.8750138  0.1210881
## 6  1        Aruba          ABW 1995 2.547144 171.3875 -0.4188437  0.1269223
##   unemp    psect tax pbe   pop     gdpd accelec   bmoney
## 1    NA 44.48402  NA  NA 62149 5.815738      NA 55.59662
## 2  6.08 44.22231  NA  NA 64622 5.612127      NA 56.97110
## 3    NA 43.29178  NA  NA 68235 3.792575      NA 58.32440
## 4    NA 40.91200  NA  NA 72504 5.296524      NA 54.91893
## 5  6.45 42.44904  NA  NA 76700 6.303148      NA 53.75696
## 6    NA 43.06822  NA  NA 80324 3.370637      NA 53.36272

First Analysis

total= dplyr::select(total11,(5:16))
corr=cor(total,use ="complete.obs")
corrplot::corrplot(corr,method='number')

totalx=dplyr::rename(total,GDP.Growth=growth,Trade=trade,FDI.NetInflows=infdi,
                         FDI.NetOutflows=oufdi,Unemployment=unemp,
                         Private_Sector=psect,Tax.Revenue=tax,Public.Expense=pbe,
                         Population=pop,GDP.Deflator=gdpd,Access.Electricity=accelec,Broad.Money=bmoney)
totalxx=na.omit(totalx)
totalxxx=as.data.frame(totalxx)
summary(totalxxx)
##    GDP.Growth          Trade        FDI.NetInflows    FDI.NetOutflows   
##  Min.   :-21.595   Min.   : 15.16   Min.   :-41.063   Min.   :-43.3725  
##  1st Qu.:  1.710   1st Qu.: 50.41   1st Qu.:  1.384   1st Qu.:  0.1442  
##  Median :  3.246   Median : 69.51   Median :  2.737   Median :  0.7496  
##  Mean   :  3.320   Mean   : 78.60   Mean   :  3.964   Mean   :  1.7900  
##  3rd Qu.:  4.947   3rd Qu.: 94.10   3rd Qu.:  4.780   3rd Qu.:  2.1857  
##  Max.   : 26.756   Max.   :437.33   Max.   :103.337   Max.   : 75.9995  
##   Unemployment     Private_Sector    Tax.Revenue        Public.Expense  
##  Min.   : 0.1413   Min.   :  3.59   Min.   :  0.04349   Min.   : 4.066  
##  1st Qu.: 4.4780   1st Qu.: 33.66   1st Qu.: 12.92218   1st Qu.:18.329  
##  Median : 6.7522   Median : 52.16   Median : 15.44675   Median :25.797  
##  Mean   : 7.8341   Mean   : 71.22   Mean   : 16.82193   Mean   :25.824  
##  3rd Qu.: 9.4875   3rd Qu.:106.60   3rd Qu.: 20.49038   3rd Qu.:31.975  
##  Max.   :35.4600   Max.   :308.98   Max.   :110.18305   Max.   :83.616  
##    Population         GDP.Deflator      Access.Electricity  Broad.Money    
##  Min.   :4.460e+04   Min.   : -25.958   Min.   :  2.624    Min.   : 17.31  
##  1st Qu.:5.101e+06   1st Qu.:   1.810   1st Qu.: 95.588    1st Qu.: 44.13  
##  Median :1.653e+07   Median :   3.503   Median : 99.990    Median : 58.82  
##  Mean   :2.120e+08   Mean   :   9.554   Mean   : 93.140    Mean   : 69.81  
##  3rd Qu.:8.552e+07   3rd Qu.:   6.933   3rd Qu.:100.000    3rd Qu.: 87.72  
##  Max.   :7.592e+09   Max.   :2700.442   Max.   :100.000    Max.   :252.92
total_plus=dplyr::rename(total,GDP.Growth=growth,Trade=trade,FDI.NetInflows=infdi,
                         FDI.NetOutflows=oufdi,Unemployment=unemp,
                         Private_Sector=psect,Tax.Revenue=tax,Public.Expense=pbe,
                         Population=pop,GDP.Deflator=gdpd,Access.Electricity=accelec,Broad.Money=bmoney)

Select Country by region

total_22=dplyr::rename(total11,GDP.Growth=growth,Trade=trade,FDI.NetInflows=infdi,
                         FDI.NetOutflows=oufdi,Unemployment=unemp,
                         Private_Sector=psect,Tax.Revenue=tax,Public.Expense=pbe,
                         Population=pop,GDP.Deflator=gdpd,Access.Electricity=accelec,Broad.Money=bmoney)
region=subset(total_22,`Country Name`=="East Asia & Pacific"|`Country Name`=="Europe & Central Asia"|
              `Country Name`=="Latin America & Caribbean"|`Country Name`=="Middle East & North Africa"|
                `Country Name`=="Sub-Saharan Africa")

Income=subset(total_22,`Country Name`=="High income"|`Country Name`=="Low income"|
              `Country Name`=="Middle income"|`Country Name`=="Upper middle income")
library(foreign)
coplot(GDP.Growth ~ Year|`Country Name`, type="l",col="red",data=region, pch=40)

coplot(GDP.Growth ~ Year|`Country Name`, type="l",col="blue", data=Income)

coplot( GDP.Deflator ~ Year|`Country Name`, type="l",col='dark green', data=region)

coplot( GDP.Deflator ~ Year|`Country Name`, type="l",col='dark orange', data=Income)

#print(summary(Income))
#print(summary(region))
library(stats)
total_scale=scale(total_plus)
total_scale1=as.data.frame(total_scale)
ols=lm(GDP.Growth ~ Trade + FDI.NetInflows + Unemployment + 
    Private_Sector + Tax.Revenue + Public.Expense ,data=total_scale1)
summary(ols)
## 
## Call:
## lm(formula = GDP.Growth ~ Trade + FDI.NetInflows + Unemployment + 
##     Private_Sector + Tax.Revenue + Public.Expense, data = total_scale1)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -4.7648 -0.2293  0.0330  0.2642  5.8290 
## 
## Coefficients:
##                 Estimate Std. Error t value Pr(>|t|)    
## (Intercept)    -0.002135   0.014216  -0.150   0.8806    
## Trade           0.062283   0.012253   5.083 4.06e-07 ***
## FDI.NetInflows  0.075756   0.031389   2.413   0.0159 *  
## Unemployment   -0.108872   0.015564  -6.995 3.62e-12 ***
## Private_Sector -0.128550   0.011519 -11.160  < 2e-16 ***
## Tax.Revenue     0.104580   0.018138   5.766 9.41e-09 ***
## Public.Expense -0.228264   0.019309 -11.822  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.5546 on 1969 degrees of freedom
##   (5944 observations deleted due to missingness)
## Multiple R-squared:  0.1714, Adjusted R-squared:  0.1688 
## F-statistic: 67.86 on 6 and 1969 DF,  p-value: < 2.2e-16
car::vif(ols)
##          Trade FDI.NetInflows   Unemployment Private_Sector    Tax.Revenue 
##       1.136152       1.163757       1.111203       1.056231       1.716455 
## Public.Expense 
##       1.698027
ols2=lm(GDP.Growth~Trade+FDI.NetInflows+Unemployment+Private_Sector+
          Tax.Revenue +Public.Expense, data=total_scale1)
summary(ols2)
## 
## Call:
## lm(formula = GDP.Growth ~ Trade + FDI.NetInflows + Unemployment + 
##     Private_Sector + Tax.Revenue + Public.Expense, data = total_scale1)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -4.7648 -0.2293  0.0330  0.2642  5.8290 
## 
## Coefficients:
##                 Estimate Std. Error t value Pr(>|t|)    
## (Intercept)    -0.002135   0.014216  -0.150   0.8806    
## Trade           0.062283   0.012253   5.083 4.06e-07 ***
## FDI.NetInflows  0.075756   0.031389   2.413   0.0159 *  
## Unemployment   -0.108872   0.015564  -6.995 3.62e-12 ***
## Private_Sector -0.128550   0.011519 -11.160  < 2e-16 ***
## Tax.Revenue     0.104580   0.018138   5.766 9.41e-09 ***
## Public.Expense -0.228264   0.019309 -11.822  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.5546 on 1969 degrees of freedom
##   (5944 observations deleted due to missingness)
## Multiple R-squared:  0.1714, Adjusted R-squared:  0.1688 
## F-statistic: 67.86 on 6 and 1969 DF,  p-value: < 2.2e-16
car::vif(ols2)
##          Trade FDI.NetInflows   Unemployment Private_Sector    Tax.Revenue 
##       1.136152       1.163757       1.111203       1.056231       1.716455 
## Public.Expense 
##       1.698027
library(olsrr)
## 
## Attaching package: 'olsrr'
## The following object is masked from 'package:datasets':
## 
##     rivers
ols3=MASS::rlm(GDP.Growth~Trade+FDI.NetInflows+Unemployment+Private_Sector+
          Tax.Revenue +Public.Expense, data=total_scale1)
summary(ols3)
## 
## Call: rlm(formula = GDP.Growth ~ Trade + FDI.NetInflows + Unemployment + 
##     Private_Sector + Tax.Revenue + Public.Expense, data = total_scale1)
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -4.79524 -0.24167  0.01213  0.24180  5.91184 
## 
## Coefficients:
##                Value    Std. Error t value 
## (Intercept)      0.0123   0.0108     1.1423
## Trade            0.0561   0.0093     6.0312
## FDI.NetInflows   0.0556   0.0238     2.3347
## Unemployment    -0.0826   0.0118    -6.9888
## Private_Sector  -0.1182   0.0087   -13.5112
## Tax.Revenue      0.1166   0.0138     8.4705
## Public.Expense  -0.2428   0.0147   -16.5675
## 
## Residual standard error: 0.3585 on 1969 degrees of freedom
##   (5944 observations deleted due to missingness)
car::vif(ols3)
##          Trade FDI.NetInflows   Unemployment Private_Sector    Tax.Revenue 
##       1.136152       1.163757       1.111203       1.056231       1.716455 
## Public.Expense 
##       1.698027
high=dplyr::select(total_22,GDP.Growth,Trade,FDI.NetInflows,Unemployment,Private_Sector,
          Tax.Revenue,Public.Expense)
GGally::ggpairs(high)
## Registered S3 method overwritten by 'GGally':
##   method from   
##   +.gg   ggplot2
## Warning: Removed 728 rows containing non-finite values (stat_density).
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 1426 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 1212 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 3923 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 2471 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 4194 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 4436 rows containing missing values
## Warning: Removed 1426 rows containing missing values (geom_point).
## Warning: Removed 1341 rows containing non-finite values (stat_density).
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 1667 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 4149 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 2791 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 4364 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 4593 rows containing missing values
## Warning: Removed 1212 rows containing missing values (geom_point).
## Warning: Removed 1667 rows containing missing values (geom_point).
## Warning: Removed 1111 rows containing non-finite values (stat_density).
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 4096 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 2460 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 4231 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 4464 rows containing missing values
## Warning: Removed 3923 rows containing missing values (geom_point).
## Warning: Removed 4149 rows containing missing values (geom_point).
## Warning: Removed 4096 rows containing missing values (geom_point).
## Warning: Removed 3838 rows containing non-finite values (stat_density).
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 4896 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 5186 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 5326 rows containing missing values
## Warning: Removed 2471 rows containing missing values (geom_point).
## Warning: Removed 2791 rows containing missing values (geom_point).
## Warning: Removed 2460 rows containing missing values (geom_point).
## Warning: Removed 4896 rows containing missing values (geom_point).
## Warning: Removed 2403 rows containing non-finite values (stat_density).
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 4932 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 5155 rows containing missing values
## Warning: Removed 4194 rows containing missing values (geom_point).
## Warning: Removed 4364 rows containing missing values (geom_point).
## Warning: Removed 4231 rows containing missing values (geom_point).
## Warning: Removed 5186 rows containing missing values (geom_point).
## Warning: Removed 4932 rows containing missing values (geom_point).
## Warning: Removed 4178 rows containing non-finite values (stat_density).
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 4431 rows containing missing values
## Warning: Removed 4436 rows containing missing values (geom_point).
## Warning: Removed 4593 rows containing missing values (geom_point).
## Warning: Removed 4464 rows containing missing values (geom_point).
## Warning: Removed 5326 rows containing missing values (geom_point).
## Warning: Removed 5155 rows containing missing values (geom_point).
## Warning: Removed 4431 rows containing missing values (geom_point).
## Warning: Removed 4421 rows containing non-finite values (stat_density).

install.packages('tseries')
## Installing package into '/Users/vincenttanoe/Library/R/4.0/library'
## (as 'lib' is unspecified)
## 
## The downloaded binary packages are in
##  /var/folders/sw/m_qbgxpn3pzcgbb04_cl0mxh0000gn/T//RtmpdaBfnN/downloaded_packages
install.packages('plm')
## Installing package into '/Users/vincenttanoe/Library/R/4.0/library'
## (as 'lib' is unspecified)
## 
## The downloaded binary packages are in
##  /var/folders/sw/m_qbgxpn3pzcgbb04_cl0mxh0000gn/T//RtmpdaBfnN/downloaded_packages
library(tseries)
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
library(plm)

Random effect

total_23=na.omit(total_22)
random <- plm(GDP.Growth ~  Trade + FDI.NetInflows + Unemployment + 
    Private_Sector + Tax.Revenue + Public.Expense + Public.Expense, 
    data=total_22, index=c("Country Code", "Year"), model="random")
summary(random)
## Oneway (individual) effect Random Effect Model 
##    (Swamy-Arora's transformation)
## 
## Call:
## plm(formula = GDP.Growth ~ Trade + FDI.NetInflows + Unemployment + 
##     Private_Sector + Tax.Revenue + Public.Expense + Public.Expense, 
##     data = total_22, model = "random", index = c("Country Code", 
##         "Year"))
## 
## Unbalanced Panel: n = 150, T = 1-30, N = 1976
## 
## Effects:
##                 var std.dev share
## idiosyncratic 8.244   2.871 0.867
## individual    1.263   1.124 0.133
## theta:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
## 0.06881 0.44609 0.48417 0.47486 0.55881 0.57732 
## 
## Residuals:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
## -27.974  -1.146   0.195   0.004   1.356  32.187 
## 
## Coefficients:
##                  Estimate Std. Error  z-value  Pr(>|z|)    
## (Intercept)     6.6310620  0.3836623  17.2836 < 2.2e-16 ***
## Trade           0.0097386  0.0022027   4.4211 9.819e-06 ***
## FDI.NetInflows  0.0077976  0.0038950   2.0020   0.04529 *  
## Unemployment   -0.1286126  0.0200284  -6.4215 1.349e-10 ***
## Private_Sector -0.0230004  0.0022903 -10.0427 < 2.2e-16 ***
## Tax.Revenue     0.1365066  0.0176864   7.7182 1.180e-14 ***
## Public.Expense -0.1449152  0.0130493 -11.1052 < 2.2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Total Sum of Squares:    20745
## Residual Sum of Squares: 17130
## R-Squared:      0.17427
## Adj. R-Squared: 0.17175
## Chisq: 346.992 on 6 DF, p-value: < 2.22e-16

Fixed effect

fixed <- plm(GDP.Growth ~  Trade + FDI.NetInflows + Unemployment + 
    Private_Sector + Tax.Revenue + Public.Expense + Public.Expense, 
    data=total_22, index=c("Country Name", "Year"), model="within")
summary(fixed)
## Oneway (individual) effect Within Model
## 
## Call:
## plm(formula = GDP.Growth ~ Trade + FDI.NetInflows + Unemployment + 
##     Private_Sector + Tax.Revenue + Public.Expense + Public.Expense, 
##     data = total_22, model = "within", index = c("Country Name", 
##         "Year"))
## 
## Unbalanced Panel: n = 150, T = 1-30, N = 1976
## 
## Residuals:
##      Min.   1st Qu.    Median   3rd Qu.      Max. 
## -27.15939  -1.03481   0.10827   1.27146  29.94624 
## 
## Coefficients:
##                  Estimate Std. Error  t-value  Pr(>|t|)    
## Trade           0.0304084  0.0048579   6.2595 4.804e-10 ***
## FDI.NetInflows  0.0127019  0.0042442   2.9928  0.002802 ** 
## Unemployment   -0.1576514  0.0291623  -5.4060 7.295e-08 ***
## Private_Sector -0.0344033  0.0034734  -9.9049 < 2.2e-16 ***
## Tax.Revenue     0.2193848  0.0254099   8.6338 < 2.2e-16 ***
## Public.Expense -0.2260035  0.0212379 -10.6415 < 2.2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Total Sum of Squares:    18074
## Residual Sum of Squares: 15005
## R-Squared:      0.16981
## Adj. R-Squared: 0.099112
## F-statistic: 62.0469 on 6 and 1820 DF, p-value: < 2.22e-16

Hausman test

phtest(fixed, random)
## 
##  Hausman Test
## 
## data:  GDP.Growth ~ Trade + FDI.NetInflows + Unemployment + Private_Sector +  ...
## chisq = 100.08, df = 6, p-value < 2.2e-16
## alternative hypothesis: one model is inconsistent
install.packages('apsrtable')
## Installing package into '/Users/vincenttanoe/Library/R/4.0/library'
## (as 'lib' is unspecified)
## 
## The downloaded binary packages are in
##  /var/folders/sw/m_qbgxpn3pzcgbb04_cl0mxh0000gn/T//RtmpdaBfnN/downloaded_packages
library(apsrtable)
apsrtable(ols,ols2, model.names = c("OLS_general","OLS_correction"))
## \begin{table}[!ht]
## \caption{}
## \label{} 
## \begin{tabular}{ l D{.}{.}{2}D{.}{.}{2} } 
## \hline 
##   & \multicolumn{ 1 }{ c }{ OLS_general } & \multicolumn{ 1 }{ c }{ OLS_correction } \\ \hline
##  %                & OLS_general    & OLS_correction\\ 
## (Intercept)      & -0.00          & -0.00         \\ 
##                  & (0.01)         & (0.01)        \\ 
## Trade            & 0.06 ^*        & 0.06 ^*       \\ 
##                  & (0.01)         & (0.01)        \\ 
## FDI.NetInflows   & 0.08 ^*        & 0.08 ^*       \\ 
##                  & (0.03)         & (0.03)        \\ 
## Unemployment     & -0.11 ^*       & -0.11 ^*      \\ 
##                  & (0.02)         & (0.02)        \\ 
## Private\_Sector & -0.13 ^*       & -0.13 ^*      \\ 
##                  & (0.01)         & (0.01)        \\ 
## Tax.Revenue      & 0.10 ^*        & 0.10 ^*       \\ 
##                  & (0.02)         & (0.02)        \\ 
## Public.Expense   & -0.23 ^*       & -0.23 ^*      \\ 
##                  & (0.02)         & (0.02)         \\
##  $N$              & 1976           & 1976          \\ 
## $R^2$            & 0.17           & 0.17          \\ 
## adj. $R^2$       & 0.17           & 0.17          \\ 
## Resid. sd        & 0.55           & 0.55           \\ \hline
##  \multicolumn{3}{l}{\footnotesize{Standard errors in parentheses}}\\
## \multicolumn{3}{l}{\footnotesize{$^*$ indicates significance at $p< 0.05 $}} 
## \end{tabular} 
##  \end{table}
total_m=na.omit(total_plus)
library(caret)
## Loading required package: lattice
## Loading required package: ggplot2
#prepare training scheme
control <- trainControl(method="repeatedcv", number=10, repeats=3)
#train the model
model <- train(GDP.Growth~.,data=total_m, preProcess="scale", trControl=control, na.rm=TRUE)
#estimate variable importance
importance <- varImp(model,scale=FALSE)
print(importance)
## rf variable importance
## 
##                    Overall
## Public.Expense      2392.6
## Tax.Revenue         1803.9
## GDP.Deflator        1639.3
## Private_Sector      1567.2
## FDI.NetInflows      1476.3
## Population          1356.6
## Unemployment        1344.3
## Broad.Money         1241.7
## Trade               1180.3
## FDI.NetOutflows     1128.3
## Access.Electricity   698.4
plot(importance)

summary(total_m)
##    GDP.Growth          Trade        FDI.NetInflows    FDI.NetOutflows   
##  Min.   :-21.595   Min.   : 15.16   Min.   :-41.063   Min.   :-43.3725  
##  1st Qu.:  1.710   1st Qu.: 50.41   1st Qu.:  1.384   1st Qu.:  0.1442  
##  Median :  3.246   Median : 69.51   Median :  2.737   Median :  0.7496  
##  Mean   :  3.320   Mean   : 78.60   Mean   :  3.964   Mean   :  1.7900  
##  3rd Qu.:  4.947   3rd Qu.: 94.10   3rd Qu.:  4.780   3rd Qu.:  2.1857  
##  Max.   : 26.756   Max.   :437.33   Max.   :103.337   Max.   : 75.9995  
##   Unemployment     Private_Sector    Tax.Revenue        Public.Expense  
##  Min.   : 0.1413   Min.   :  3.59   Min.   :  0.04349   Min.   : 4.066  
##  1st Qu.: 4.4780   1st Qu.: 33.66   1st Qu.: 12.92218   1st Qu.:18.329  
##  Median : 6.7522   Median : 52.16   Median : 15.44675   Median :25.797  
##  Mean   : 7.8341   Mean   : 71.22   Mean   : 16.82193   Mean   :25.824  
##  3rd Qu.: 9.4875   3rd Qu.:106.60   3rd Qu.: 20.49038   3rd Qu.:31.975  
##  Max.   :35.4600   Max.   :308.98   Max.   :110.18305   Max.   :83.616  
##    Population         GDP.Deflator      Access.Electricity  Broad.Money    
##  Min.   :4.460e+04   Min.   : -25.958   Min.   :  2.624    Min.   : 17.31  
##  1st Qu.:5.101e+06   1st Qu.:   1.810   1st Qu.: 95.588    1st Qu.: 44.13  
##  Median :1.653e+07   Median :   3.503   Median : 99.990    Median : 58.82  
##  Mean   :2.120e+08   Mean   :   9.554   Mean   : 93.140    Mean   : 69.81  
##  3rd Qu.:8.552e+07   3rd Qu.:   6.933   3rd Qu.:100.000    3rd Qu.: 87.72  
##  Max.   :7.592e+09   Max.   :2700.442   Max.   :100.000    Max.   :252.92
fit=brms::brm(GDP.Growth~Trade+FDI.NetInflows+Unemployment+Private_Sector+
          Tax.Revenue +Public.Expense, data=total_scale1)
## Registered S3 methods overwritten by 'lme4':
##   method                          from
##   cooks.distance.influence.merMod car 
##   influence.merMod                car 
##   dfbeta.influence.merMod         car 
##   dfbetas.influence.merMod        car
## Warning: Rows containing NAs were excluded from the model.
## Compiling Stan program...
## Trying to compile a simple C file
## Running /Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB foo.c
## clang -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I"/Users/vincenttanoe/Library/R/4.0/library/Rcpp/include/"  -I"/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/"  -I"/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported"  -I"/Library/Frameworks/R.framework/Versions/4.0/Resources/library/BH/include" -I"/Library/Frameworks/R.framework/Versions/4.0/Resources/library/StanHeaders/include/src/"  -I"/Library/Frameworks/R.framework/Versions/4.0/Resources/library/StanHeaders/include/"  -I"/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppParallel/include/"  -I"/Users/vincenttanoe/Library/R/4.0/library/rstan/include" -DEIGEN_NO_DEBUG  -DBOOST_DISABLE_ASSERTS  -DBOOST_PENDING_INTEGER_LOG2_HPP  -DSTAN_THREADS  -DBOOST_NO_AUTO_PTR  -include '/Library/Frameworks/R.framework/Versions/4.0/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp'  -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1   -I/usr/local/include   -fPIC  -Wall -g -O2  -c foo.c -o foo.o
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
## In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/Eigen/Dense:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/Eigen/Core:88:
## /Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/Eigen/src/Core/util/Macros.h:613:1: error: unknown type name 'namespace'
## namespace Eigen {
## ^
## /Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/Eigen/src/Core/util/Macros.h:613:16: error: expected ';' after top level declarator
## namespace Eigen {
##                ^
##                ;
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
## In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/Eigen/Dense:1:
## /Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/Eigen/Core:96:10: fatal error: 'complex' file not found
## #include <complex>
##          ^~~~~~~~~
## 3 errors generated.
## make: *** [foo.o] Error 1
## Start sampling
## 
## SAMPLING FOR MODEL 'de9bfce9a3b801fee317fa0a9490bff1' NOW (CHAIN 1).
## Chain 1: 
## Chain 1: Gradient evaluation took 2.3e-05 seconds
## Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 0.23 seconds.
## Chain 1: Adjust your expectations accordingly!
## Chain 1: 
## Chain 1: 
## Chain 1: Iteration:    1 / 2000 [  0%]  (Warmup)
## Chain 1: Iteration:  200 / 2000 [ 10%]  (Warmup)
## Chain 1: Iteration:  400 / 2000 [ 20%]  (Warmup)
## Chain 1: Iteration:  600 / 2000 [ 30%]  (Warmup)
## Chain 1: Iteration:  800 / 2000 [ 40%]  (Warmup)
## Chain 1: Iteration: 1000 / 2000 [ 50%]  (Warmup)
## Chain 1: Iteration: 1001 / 2000 [ 50%]  (Sampling)
## Chain 1: Iteration: 1200 / 2000 [ 60%]  (Sampling)
## Chain 1: Iteration: 1400 / 2000 [ 70%]  (Sampling)
## Chain 1: Iteration: 1600 / 2000 [ 80%]  (Sampling)
## Chain 1: Iteration: 1800 / 2000 [ 90%]  (Sampling)
## Chain 1: Iteration: 2000 / 2000 [100%]  (Sampling)
## Chain 1: 
## Chain 1:  Elapsed Time: 0.075835 seconds (Warm-up)
## Chain 1:                0.069244 seconds (Sampling)
## Chain 1:                0.145079 seconds (Total)
## Chain 1: 
## 
## SAMPLING FOR MODEL 'de9bfce9a3b801fee317fa0a9490bff1' NOW (CHAIN 2).
## Chain 2: 
## Chain 2: Gradient evaluation took 2.5e-05 seconds
## Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 0.25 seconds.
## Chain 2: Adjust your expectations accordingly!
## Chain 2: 
## Chain 2: 
## Chain 2: Iteration:    1 / 2000 [  0%]  (Warmup)
## Chain 2: Iteration:  200 / 2000 [ 10%]  (Warmup)
## Chain 2: Iteration:  400 / 2000 [ 20%]  (Warmup)
## Chain 2: Iteration:  600 / 2000 [ 30%]  (Warmup)
## Chain 2: Iteration:  800 / 2000 [ 40%]  (Warmup)
## Chain 2: Iteration: 1000 / 2000 [ 50%]  (Warmup)
## Chain 2: Iteration: 1001 / 2000 [ 50%]  (Sampling)
## Chain 2: Iteration: 1200 / 2000 [ 60%]  (Sampling)
## Chain 2: Iteration: 1400 / 2000 [ 70%]  (Sampling)
## Chain 2: Iteration: 1600 / 2000 [ 80%]  (Sampling)
## Chain 2: Iteration: 1800 / 2000 [ 90%]  (Sampling)
## Chain 2: Iteration: 2000 / 2000 [100%]  (Sampling)
## Chain 2: 
## Chain 2:  Elapsed Time: 0.077896 seconds (Warm-up)
## Chain 2:                0.07645 seconds (Sampling)
## Chain 2:                0.154346 seconds (Total)
## Chain 2: 
## 
## SAMPLING FOR MODEL 'de9bfce9a3b801fee317fa0a9490bff1' NOW (CHAIN 3).
## Chain 3: 
## Chain 3: Gradient evaluation took 1.3e-05 seconds
## Chain 3: 1000 transitions using 10 leapfrog steps per transition would take 0.13 seconds.
## Chain 3: Adjust your expectations accordingly!
## Chain 3: 
## Chain 3: 
## Chain 3: Iteration:    1 / 2000 [  0%]  (Warmup)
## Chain 3: Iteration:  200 / 2000 [ 10%]  (Warmup)
## Chain 3: Iteration:  400 / 2000 [ 20%]  (Warmup)
## Chain 3: Iteration:  600 / 2000 [ 30%]  (Warmup)
## Chain 3: Iteration:  800 / 2000 [ 40%]  (Warmup)
## Chain 3: Iteration: 1000 / 2000 [ 50%]  (Warmup)
## Chain 3: Iteration: 1001 / 2000 [ 50%]  (Sampling)
## Chain 3: Iteration: 1200 / 2000 [ 60%]  (Sampling)
## Chain 3: Iteration: 1400 / 2000 [ 70%]  (Sampling)
## Chain 3: Iteration: 1600 / 2000 [ 80%]  (Sampling)
## Chain 3: Iteration: 1800 / 2000 [ 90%]  (Sampling)
## Chain 3: Iteration: 2000 / 2000 [100%]  (Sampling)
## Chain 3: 
## Chain 3:  Elapsed Time: 0.077539 seconds (Warm-up)
## Chain 3:                0.073726 seconds (Sampling)
## Chain 3:                0.151265 seconds (Total)
## Chain 3: 
## 
## SAMPLING FOR MODEL 'de9bfce9a3b801fee317fa0a9490bff1' NOW (CHAIN 4).
## Chain 4: 
## Chain 4: Gradient evaluation took 1.8e-05 seconds
## Chain 4: 1000 transitions using 10 leapfrog steps per transition would take 0.18 seconds.
## Chain 4: Adjust your expectations accordingly!
## Chain 4: 
## Chain 4: 
## Chain 4: Iteration:    1 / 2000 [  0%]  (Warmup)
## Chain 4: Iteration:  200 / 2000 [ 10%]  (Warmup)
## Chain 4: Iteration:  400 / 2000 [ 20%]  (Warmup)
## Chain 4: Iteration:  600 / 2000 [ 30%]  (Warmup)
## Chain 4: Iteration:  800 / 2000 [ 40%]  (Warmup)
## Chain 4: Iteration: 1000 / 2000 [ 50%]  (Warmup)
## Chain 4: Iteration: 1001 / 2000 [ 50%]  (Sampling)
## Chain 4: Iteration: 1200 / 2000 [ 60%]  (Sampling)
## Chain 4: Iteration: 1400 / 2000 [ 70%]  (Sampling)
## Chain 4: Iteration: 1600 / 2000 [ 80%]  (Sampling)
## Chain 4: Iteration: 1800 / 2000 [ 90%]  (Sampling)
## Chain 4: Iteration: 2000 / 2000 [100%]  (Sampling)
## Chain 4: 
## Chain 4:  Elapsed Time: 0.073851 seconds (Warm-up)
## Chain 4:                0.071991 seconds (Sampling)
## Chain 4:                0.145842 seconds (Total)
## Chain 4:
summary(fit)
##  Family: gaussian 
##   Links: mu = identity; sigma = identity 
## Formula: GDP.Growth ~ Trade + FDI.NetInflows + Unemployment + Private_Sector + Tax.Revenue + Public.Expense 
##    Data: total_scale1 (Number of observations: 1976) 
## Samples: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
##          total post-warmup samples = 4000
## 
## Population-Level Effects: 
##                Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
## Intercept         -0.00      0.01    -0.03     0.02 1.00     6266     3359
## Trade              0.06      0.01     0.04     0.09 1.00     6283     3197
## FDI.NetInflows     0.08      0.03     0.01     0.14 1.00     5729     3140
## Unemployment      -0.11      0.02    -0.14    -0.08 1.00     5841     3139
## Private_Sector    -0.13      0.01    -0.15    -0.11 1.00     5555     2954
## Tax.Revenue        0.11      0.02     0.07     0.14 1.00     4282     3014
## Public.Expense    -0.23      0.02    -0.27    -0.19 1.00     4245     3162
## 
## Family Specific Parameters: 
##       Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
## sigma     0.55      0.01     0.54     0.57 1.00     5478     2794
## 
## Samples were drawn using sampling(NUTS). For each parameter, Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the potential
## scale reduction factor on split chains (at convergence, Rhat = 1).
plot(fit)

pp = brms::pp_check(fit)
## Using 10 posterior samples for ppc type 'dens_overlay' by default.
pp+theme_bw()

#Default Model Predictions
plot(brms::conditional_effects(fit),points=T)