#Find a data set of which you can fit multiple linear regression and interpret your results

library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.2.1     ✔ readr     2.2.0
## ✔ forcats   1.0.1     ✔ stringr   1.6.0
## ✔ ggplot2   4.0.3     ✔ tibble    3.3.1
## ✔ lubridate 1.9.5     ✔ tidyr     1.3.2
## ✔ purrr     1.2.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(ggplot2)
library(dplyr)
setwd("D:/AUCA/R for data science/exam practice")
getwd()
## [1] "D:/AUCA/R for data science/exam practice"
df <- read.csv("CO2_emission.csv")

head(df)
##           Country.Name country_code                     Region
## 1                Aruba          ABW  Latin America & Caribbean
## 2          Afghanistan          AFG                 South Asia
## 3               Angola          AGO         Sub-Saharan Africa
## 4              Albania          ALB      Europe & Central Asia
## 5              Andorra          AND      Europe & Central Asia
## 6 United Arab Emirates          ARE Middle East & North Africa
##                           Indicator.Name      X1990      X1991       X1992
## 1 CO2 emissions (metric tons per capita)         NA         NA          NA
## 2 CO2 emissions (metric tons per capita)  0.1917451  0.1676816  0.09595774
## 3 CO2 emissions (metric tons per capita)  0.5536620  0.5445386  0.54355722
## 4 CO2 emissions (metric tons per capita)  1.8195416  1.2428102  0.68369983
## 5 CO2 emissions (metric tons per capita)  7.5218317  7.2353792  6.96307870
## 6 CO2 emissions (metric tons per capita) 30.1951886 31.7784962 29.08092584
##         X1993       X1994       X1995       X1996       X1997       X1998
## 1          NA          NA          NA          NA          NA          NA
## 2  0.08472111  0.07554583  0.06846796  0.06258803  0.05682662  0.05269086
## 3  0.70898423  0.83680440  0.91214149  1.07216847  1.08663697  1.09182531
## 4  0.63830704  0.64535519  0.60543625  0.61236736  0.46692147  0.57215370
## 5  6.72417752  6.54157891  6.73347949  6.99159455  7.30744115  7.63953851
## 6 29.27567777 30.84933296 31.12501806 30.92802588 30.48633262 29.66358052
##         X1999      X2000       X2001       X2002       X2003       X2004
## 1          NA         NA          NA          NA          NA          NA
## 2  0.04015697  0.0365737  0.03378536  0.04557366  0.05151838  0.04165539
## 3  1.10985966  0.9880774  0.94182891  0.89557767  0.92486944  0.93026295
## 4  0.95535931  1.0262131  1.05549588  1.23237878  1.33898498  1.40405869
## 5  7.92319165  7.9522863  7.72154906  7.56623988  7.24241557  7.34426233
## 6 28.88710798 27.0351591 29.43026994 28.50146173 27.96926982 27.03893822
##         X2005       X2006       X2007      X2008      X2009      X2010
## 1          NA          NA          NA         NA         NA         NA
## 2  0.06041878  0.06658329  0.06531235  0.1284166  0.1718624  0.2436140
## 3  0.81353929  0.82184008  0.81175351  0.8886580  0.9394040  0.9761842
## 4  1.33820940  1.33999574  1.39393137  1.3843112  1.4414936  1.5276237
## 5  7.35378001  6.79054277  6.53104692  6.4393039  6.1566875  6.1571978
## 6 25.38238104 22.93510429 21.37028576 22.0114692 19.8323489 19.0397698
##        X2011      X2012      X2013      X2014      X2015      X2016      X2017
## 1         NA         NA         NA         NA         NA         NA         NA
## 2  0.2965062  0.2592953  0.1856237  0.1462356  0.1728967  0.1497893  0.1316946
## 3  0.9855223  0.9506959  1.0362939  1.0997791  1.1350441  1.0318113  0.8133007
## 4  1.6694232  1.5032405  1.5336300  1.6683374  1.6037751  1.5576644  1.7887861
## 5  5.8508861  5.9446542  5.9428004  5.8071277  6.0261818  6.0806003  6.1041339
## 6 18.5094574 19.2078011 20.0556476 20.0516980 21.0776420 21.4806686 20.7690223
##        X2018      X2019    X2019.1
## 1         NA         NA         NA
## 2  0.1632953  0.1598244  0.1598244
## 3  0.7776749  0.7921371  0.7921371
## 4  1.7827389  1.6922483  1.6922483
## 5  6.3629754  6.4812174  6.4812174
## 6 18.3906781 19.3295633 19.3295633
glimpse(df)
## Rows: 215
## Columns: 35
## $ Country.Name   <chr> "Aruba", "Afghanistan", "Angola", "Albania", "Andorra",…
## $ country_code   <chr> "ABW", "AFG", "AGO", "ALB", "AND", "ARE", "ARG", "ARM",…
## $ Region         <chr> "Latin America & Caribbean", "South Asia", "Sub-Saharan…
## $ Indicator.Name <chr> "CO2 emissions (metric tons per capita)", "CO2 emission…
## $ X1990          <dbl> NA, 0.19174511, 0.55366196, 1.81954163, 7.52183166, 30.…
## $ X1991          <dbl> NA, 0.16768158, 0.54453865, 1.24281022, 7.23537924, 31.…
## $ X1992          <dbl> NA, 0.09595774, 0.54355722, 0.68369983, 6.96307870, 29.…
## $ X1993          <dbl> NA, 0.08472111, 0.70898423, 0.63830704, 6.72417752, 29.…
## $ X1994          <dbl> NA, 0.07554583, 0.83680440, 0.64535519, 6.54157891, 30.…
## $ X1995          <dbl> NA, 0.06846796, 0.91214149, 0.60543625, 6.73347949, 31.…
## $ X1996          <dbl> NA, 0.06258803, 1.07216847, 0.61236736, 6.99159455, 30.…
## $ X1997          <dbl> NA, 0.05682662, 1.08663697, 0.46692147, 7.30744115, 30.…
## $ X1998          <dbl> NA, 0.05269086, 1.09182531, 0.57215370, 7.63953851, 29.…
## $ X1999          <dbl> NA, 0.04015697, 1.10985966, 0.95535931, 7.92319165, 28.…
## $ X2000          <dbl> NA, 0.03657370, 0.98807738, 1.02621311, 7.95228628, 27.…
## $ X2001          <dbl> NA, 0.03378536, 0.94182891, 1.05549588, 7.72154906, 29.…
## $ X2002          <dbl> NA, 0.04557366, 0.89557767, 1.23237878, 7.56623988, 28.…
## $ X2003          <dbl> NA, 0.05151838, 0.92486944, 1.33898498, 7.24241557, 27.…
## $ X2004          <dbl> NA, 0.04165539, 0.93026295, 1.40405869, 7.34426233, 27.…
## $ X2005          <dbl> NA, 0.06041878, 0.81353929, 1.33820940, 7.35378001, 25.…
## $ X2006          <dbl> NA, 0.06658329, 0.82184008, 1.33999574, 6.79054277, 22.…
## $ X2007          <dbl> NA, 0.06531235, 0.81175351, 1.39393137, 6.53104692, 21.…
## $ X2008          <dbl> NA, 0.12841656, 0.88865801, 1.38431125, 6.43930386, 22.…
## $ X2009          <dbl> NA, 0.17186242, 0.93940398, 1.44149356, 6.15668748, 19.…
## $ X2010          <dbl> NA, 0.24361404, 0.97618420, 1.52762366, 6.15719778, 19.…
## $ X2011          <dbl> NA, 0.29650624, 0.98552231, 1.66942319, 5.85088610, 18.…
## $ X2012          <dbl> NA, 0.25929533, 0.95069588, 1.50324046, 5.94465417, 19.…
## $ X2013          <dbl> NA, 0.18562366, 1.03629385, 1.53363004, 5.94280041, 20.…
## $ X2014          <dbl> NA, 0.14623562, 1.09977911, 1.66833737, 5.80712772, 20.…
## $ X2015          <dbl> NA, 0.17289674, 1.13504405, 1.60377515, 6.02618182, 21.…
## $ X2016          <dbl> NA, 0.1497893, 1.0318113, 1.5576644, 6.0806003, 21.4806…
## $ X2017          <dbl> NA, 0.13169456, 0.81330073, 1.78878607, 6.10413391, 20.…
## $ X2018          <dbl> NA, 0.16329530, 0.77767493, 1.78273895, 6.36297540, 18.…
## $ X2019          <dbl> NA, 0.15982437, 0.79213707, 1.69224832, 6.48121743, 19.…
## $ X2019.1        <dbl> NA, 0.15982437, 0.79213707, 1.69224832, 6.48121743, 19.…
str(df)
## 'data.frame':    215 obs. of  35 variables:
##  $ Country.Name  : chr  "Aruba" "Afghanistan" "Angola" "Albania" ...
##  $ country_code  : chr  "ABW" "AFG" "AGO" "ALB" ...
##  $ Region        : chr  "Latin America & Caribbean" "South Asia" "Sub-Saharan Africa" "Europe & Central Asia" ...
##  $ Indicator.Name: chr  "CO2 emissions (metric tons per capita)" "CO2 emissions (metric tons per capita)" "CO2 emissions (metric tons per capita)" "CO2 emissions (metric tons per capita)" ...
##  $ X1990         : num  NA 0.192 0.554 1.82 7.522 ...
##  $ X1991         : num  NA 0.168 0.545 1.243 7.235 ...
##  $ X1992         : num  NA 0.096 0.544 0.684 6.963 ...
##  $ X1993         : num  NA 0.0847 0.709 0.6383 6.7242 ...
##  $ X1994         : num  NA 0.0755 0.8368 0.6454 6.5416 ...
##  $ X1995         : num  NA 0.0685 0.9121 0.6054 6.7335 ...
##  $ X1996         : num  NA 0.0626 1.0722 0.6124 6.9916 ...
##  $ X1997         : num  NA 0.0568 1.0866 0.4669 7.3074 ...
##  $ X1998         : num  NA 0.0527 1.0918 0.5722 7.6395 ...
##  $ X1999         : num  NA 0.0402 1.1099 0.9554 7.9232 ...
##  $ X2000         : num  NA 0.0366 0.9881 1.0262 7.9523 ...
##  $ X2001         : num  NA 0.0338 0.9418 1.0555 7.7215 ...
##  $ X2002         : num  NA 0.0456 0.8956 1.2324 7.5662 ...
##  $ X2003         : num  NA 0.0515 0.9249 1.339 7.2424 ...
##  $ X2004         : num  NA 0.0417 0.9303 1.4041 7.3443 ...
##  $ X2005         : num  NA 0.0604 0.8135 1.3382 7.3538 ...
##  $ X2006         : num  NA 0.0666 0.8218 1.34 6.7905 ...
##  $ X2007         : num  NA 0.0653 0.8118 1.3939 6.531 ...
##  $ X2008         : num  NA 0.128 0.889 1.384 6.439 ...
##  $ X2009         : num  NA 0.172 0.939 1.441 6.157 ...
##  $ X2010         : num  NA 0.244 0.976 1.528 6.157 ...
##  $ X2011         : num  NA 0.297 0.986 1.669 5.851 ...
##  $ X2012         : num  NA 0.259 0.951 1.503 5.945 ...
##  $ X2013         : num  NA 0.186 1.036 1.534 5.943 ...
##  $ X2014         : num  NA 0.146 1.1 1.668 5.807 ...
##  $ X2015         : num  NA 0.173 1.135 1.604 6.026 ...
##  $ X2016         : num  NA 0.15 1.03 1.56 6.08 ...
##  $ X2017         : num  NA 0.132 0.813 1.789 6.104 ...
##  $ X2018         : num  NA 0.163 0.778 1.783 6.363 ...
##  $ X2019         : num  NA 0.16 0.792 1.692 6.481 ...
##  $ X2019.1       : num  NA 0.16 0.792 1.692 6.481 ...
names(df)
##  [1] "Country.Name"   "country_code"   "Region"         "Indicator.Name"
##  [5] "X1990"          "X1991"          "X1992"          "X1993"         
##  [9] "X1994"          "X1995"          "X1996"          "X1997"         
## [13] "X1998"          "X1999"          "X2000"          "X2001"         
## [17] "X2002"          "X2003"          "X2004"          "X2005"         
## [21] "X2006"          "X2007"          "X2008"          "X2009"         
## [25] "X2010"          "X2011"          "X2012"          "X2013"         
## [29] "X2014"          "X2015"          "X2016"          "X2017"         
## [33] "X2018"          "X2019"          "X2019.1"
head(df)
##           Country.Name country_code                     Region
## 1                Aruba          ABW  Latin America & Caribbean
## 2          Afghanistan          AFG                 South Asia
## 3               Angola          AGO         Sub-Saharan Africa
## 4              Albania          ALB      Europe & Central Asia
## 5              Andorra          AND      Europe & Central Asia
## 6 United Arab Emirates          ARE Middle East & North Africa
##                           Indicator.Name      X1990      X1991       X1992
## 1 CO2 emissions (metric tons per capita)         NA         NA          NA
## 2 CO2 emissions (metric tons per capita)  0.1917451  0.1676816  0.09595774
## 3 CO2 emissions (metric tons per capita)  0.5536620  0.5445386  0.54355722
## 4 CO2 emissions (metric tons per capita)  1.8195416  1.2428102  0.68369983
## 5 CO2 emissions (metric tons per capita)  7.5218317  7.2353792  6.96307870
## 6 CO2 emissions (metric tons per capita) 30.1951886 31.7784962 29.08092584
##         X1993       X1994       X1995       X1996       X1997       X1998
## 1          NA          NA          NA          NA          NA          NA
## 2  0.08472111  0.07554583  0.06846796  0.06258803  0.05682662  0.05269086
## 3  0.70898423  0.83680440  0.91214149  1.07216847  1.08663697  1.09182531
## 4  0.63830704  0.64535519  0.60543625  0.61236736  0.46692147  0.57215370
## 5  6.72417752  6.54157891  6.73347949  6.99159455  7.30744115  7.63953851
## 6 29.27567777 30.84933296 31.12501806 30.92802588 30.48633262 29.66358052
##         X1999      X2000       X2001       X2002       X2003       X2004
## 1          NA         NA          NA          NA          NA          NA
## 2  0.04015697  0.0365737  0.03378536  0.04557366  0.05151838  0.04165539
## 3  1.10985966  0.9880774  0.94182891  0.89557767  0.92486944  0.93026295
## 4  0.95535931  1.0262131  1.05549588  1.23237878  1.33898498  1.40405869
## 5  7.92319165  7.9522863  7.72154906  7.56623988  7.24241557  7.34426233
## 6 28.88710798 27.0351591 29.43026994 28.50146173 27.96926982 27.03893822
##         X2005       X2006       X2007      X2008      X2009      X2010
## 1          NA          NA          NA         NA         NA         NA
## 2  0.06041878  0.06658329  0.06531235  0.1284166  0.1718624  0.2436140
## 3  0.81353929  0.82184008  0.81175351  0.8886580  0.9394040  0.9761842
## 4  1.33820940  1.33999574  1.39393137  1.3843112  1.4414936  1.5276237
## 5  7.35378001  6.79054277  6.53104692  6.4393039  6.1566875  6.1571978
## 6 25.38238104 22.93510429 21.37028576 22.0114692 19.8323489 19.0397698
##        X2011      X2012      X2013      X2014      X2015      X2016      X2017
## 1         NA         NA         NA         NA         NA         NA         NA
## 2  0.2965062  0.2592953  0.1856237  0.1462356  0.1728967  0.1497893  0.1316946
## 3  0.9855223  0.9506959  1.0362939  1.0997791  1.1350441  1.0318113  0.8133007
## 4  1.6694232  1.5032405  1.5336300  1.6683374  1.6037751  1.5576644  1.7887861
## 5  5.8508861  5.9446542  5.9428004  5.8071277  6.0261818  6.0806003  6.1041339
## 6 18.5094574 19.2078011 20.0556476 20.0516980 21.0776420 21.4806686 20.7690223
##        X2018      X2019    X2019.1
## 1         NA         NA         NA
## 2  0.1632953  0.1598244  0.1598244
## 3  0.7776749  0.7921371  0.7921371
## 4  1.7827389  1.6922483  1.6922483
## 5  6.3629754  6.4812174  6.4812174
## 6 18.3906781 19.3295633 19.3295633
df <- df %>%
  select(-matches("2019\\.1|2019\\.2"))
names(df)
##  [1] "Country.Name"   "country_code"   "Region"         "Indicator.Name"
##  [5] "X1990"          "X1991"          "X1992"          "X1993"         
##  [9] "X1994"          "X1995"          "X1996"          "X1997"         
## [13] "X1998"          "X1999"          "X2000"          "X2001"         
## [17] "X2002"          "X2003"          "X2004"          "X2005"         
## [21] "X2006"          "X2007"          "X2008"          "X2009"         
## [25] "X2010"          "X2011"          "X2012"          "X2013"         
## [29] "X2014"          "X2015"          "X2016"          "X2017"         
## [33] "X2018"          "X2019"
names(df) <- gsub("^X", "", names(df))
names(df)
##  [1] "Country.Name"   "country_code"   "Region"         "Indicator.Name"
##  [5] "1990"           "1991"           "1992"           "1993"          
##  [9] "1994"           "1995"           "1996"           "1997"          
## [13] "1998"           "1999"           "2000"           "2001"          
## [17] "2002"           "2003"           "2004"           "2005"          
## [21] "2006"           "2007"           "2008"           "2009"          
## [25] "2010"           "2011"           "2012"           "2013"          
## [29] "2014"           "2015"           "2016"           "2017"          
## [33] "2018"           "2019"
library(tidyverse)

df_long <- df %>%
  pivot_longer(
    cols = `1990`:`2019`,
    names_to = "year",
    values_to = "value"
  ) %>%
  mutate(
    year = as.numeric(year)
  )
df_long <- df_long %>%
  filter(!is.na(value))
df_long <- df_long %>%
  mutate(
    Region = as.factor(Region),
    country_code = as.factor(country_code)
  )
model1 <- lm(value ~ year + Region, data = df_long)

summary(model1)
## 
## Call:
## lm(formula = value ~ year + Region, data = df_long)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -9.008 -2.027 -0.625  0.888 41.640 
## 
## Coefficients:
##                                   Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                      -0.466189  13.940549  -0.033    0.973    
## year                              0.002332   0.006953   0.335    0.737    
## RegionEurope & Central Asia       2.543608   0.192548  13.210  < 2e-16 ***
## RegionLatin America & Caribbean  -1.345976   0.210110  -6.406 1.61e-10 ***
## RegionMiddle East & North Africa  5.108884   0.240492  21.243  < 2e-16 ***
## RegionNorth America              12.828038   0.605412  21.189  < 2e-16 ***
## RegionSouth Asia                 -3.481388   0.330366 -10.538  < 2e-16 ***
## RegionSub-Saharan Africa         -3.374782   0.194154 -17.382  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 4.538 on 5696 degrees of freedom
## Multiple R-squared:  0.3237, Adjusted R-squared:  0.3229 
## F-statistic: 389.5 on 7 and 5696 DF,  p-value: < 2.2e-16
model2 <- lm(value ~ year * Region + country_code, data = df_long)

summary(model2)
## 
## Call:
## lm(formula = value ~ year * Region + country_code, data = df_long)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -19.8681  -0.2507  -0.0051   0.2358  12.6094 
## 
## Coefficients: (6 not defined because of singularities)
##                                         Estimate Std. Error t value Pr(>|t|)
## (Intercept)                           -63.233898   9.959167  -6.349 2.34e-10
## year                                    0.032039   0.004967   6.450 1.21e-10
## RegionEurope & Central Asia           182.062538  12.491963  14.574  < 2e-16
## RegionLatin America & Caribbean        -8.006687  13.613063  -0.588 0.556448
## RegionMiddle East & North Africa       34.389482  15.578158   2.208 0.027317
## RegionNorth America                   250.437018  38.980981   6.425 1.43e-10
## RegionSouth Asia                       -3.016360  21.314495  -0.142 0.887467
## RegionSub-Saharan Africa               36.553223  12.602042   2.901 0.003739
## country_codeAGO                        -0.149129   0.325462  -0.458 0.646821
## country_codeALB                        -3.193489   0.325462  -9.812  < 2e-16
## country_codeAND                         2.336934   0.325462   7.180 7.87e-13
## country_codeARE                        24.251033   0.325462  74.513  < 2e-16
## country_codeARG                        -1.601866   0.325462  -4.922 8.82e-07
## country_codeARM                        -2.625059   0.325462  -8.066 8.87e-16
## country_codeATG                        -0.096989   0.325462  -0.298 0.765711
## country_codeAUS                        15.838322   0.325462  48.664  < 2e-16
## country_codeAUT                         3.547344   0.325462  10.899  < 2e-16
## country_codeAZE                        -0.527146   0.325462  -1.620 0.105357
## country_codeBDI                        -1.014670   0.325462  -3.118 0.001833
## country_codeBEL                         5.689041   0.325462  17.480  < 2e-16
## country_codeBEN                        -0.710719   0.325462  -2.184 0.029024
## country_codeBFA                        -0.934278   0.325462  -2.871 0.004112
## country_codeBGD                         0.152622   0.325462   0.469 0.639132
## country_codeBGR                         1.779374   0.325462   5.467 4.77e-08
## country_codeBHR                        21.677024   0.325462  66.604  < 2e-16
## country_codeBHS                         2.237421   0.325462   6.875 6.90e-12
## country_codeBIH                         0.049109   0.325462   0.151 0.880069
## country_codeBLR                         1.857654   0.325462   5.708 1.20e-08
## country_codeBLZ                        -3.378674   0.325462 -10.381  < 2e-16
## country_codeBOL                        -3.924199   0.325462 -12.057  < 2e-16
## country_codeBRA                        -3.493048   0.325462 -10.733  < 2e-16
## country_codeBRB                        -0.173706   0.325462  -0.534 0.593556
## country_codeBRN                        15.073230   0.325462  46.313  < 2e-16
## country_codeBTN                         0.478625   0.325462   1.471 0.141456
## country_codeBWA                         1.359778   0.325462   4.178 2.99e-05
## country_codeCAF                        -0.998843   0.325462  -3.069 0.002158
## country_codeCAN                        -2.230251   0.325462  -6.853 8.05e-12
## country_codeCHE                         1.304351   0.325462   4.008 6.21e-05
## country_codeCHL                        -1.725420   0.325462  -5.301 1.19e-07
## country_codeCHN                         3.561359   0.325462  10.942  < 2e-16
## country_codeCIV                        -0.719756   0.325462  -2.211 0.027043
## country_codeCMR                        -0.697514   0.325462  -2.143 0.032145
## country_codeCOD                        -1.004572   0.325462  -3.087 0.002035
## country_codeCOG                         0.108490   0.325462   0.333 0.738889
## country_codeCOL                        -3.823909   0.325462 -11.749  < 2e-16
## country_codeCOM                        -0.831300   0.325462  -2.554 0.010669
## country_codeCPV                        -0.311615   0.325462  -0.957 0.338380
## country_codeCRI                        -3.899059   0.325462 -11.980  < 2e-16
## country_codeCUB                        -2.937519   0.325462  -9.026  < 2e-16
## country_codeCYP                         2.474145   0.325462   7.602 3.41e-14
## country_codeCZE                         6.860147   0.325462  21.078  < 2e-16
## country_codeDEU                         5.496587   0.325462  16.889  < 2e-16
## country_codeDJI                        -0.288340   0.325462  -0.886 0.375689
## country_codeDMA                        -3.179410   0.325462  -9.769  < 2e-16
## country_codeDNK                         4.892993   0.325462  15.034  < 2e-16
## country_codeDOM                        -3.358059   0.325462 -10.318  < 2e-16
## country_codeDZA                         2.216244   0.325462   6.810 1.08e-11
## country_codeECU                        -3.272187   0.325462 -10.054  < 2e-16
## country_codeEGY                         1.226015   0.325462   3.767 0.000167
## country_codeERI                        -0.822484   0.331245  -2.483 0.013057
## country_codeESP                         1.853119   0.325462   5.694 1.31e-08
## country_codeEST                         8.481126   0.325462  26.059  < 2e-16
## country_codeETH                        -0.970977   0.325462  -2.983 0.002863
## country_codeFIN                         6.139156   0.325462  18.863  < 2e-16
## country_codeFJI                         0.289341   0.325462   0.889 0.374033
## country_codeFRA                         1.172116   0.325462   3.601 0.000319
## country_codeFSM                         0.270524   0.331260   0.817 0.414163
## country_codeGAB                         2.959318   0.325462   9.093  < 2e-16
## country_codeGBR                         3.717187   0.325462  11.421  < 2e-16
## country_codeGEO                        -2.382585   0.325462  -7.321 2.82e-13
## country_codeGHA                        -0.667153   0.325462  -2.050 0.040425
## country_codeGIN                        -0.846581   0.325462  -2.601 0.009316
## country_codeGMB                        -0.827194   0.325462  -2.542 0.011062
## country_codeGNB                        -0.891169   0.325462  -2.738 0.006198
## country_codeGNQ                         4.988095   0.325462  15.326  < 2e-16
## country_codeGRC                         3.335677   0.325462  10.249  < 2e-16
## country_codeGRD                        -2.856660   0.325462  -8.777  < 2e-16
## country_codeGTM                        -4.538142   0.325462 -13.944  < 2e-16
## country_codeGUY                        -3.039007   0.325462  -9.338  < 2e-16
## country_codeHND                        -4.464766   0.325462 -13.718  < 2e-16
## country_codeHRV                        -0.267895   0.325462  -0.823 0.410473
## country_codeHTI                        -5.135783   0.325462 -15.780  < 2e-16
## country_codeHUN                         0.786905   0.325462   2.418 0.015646
## country_codeIDN                         0.524591   0.325462   1.612 0.107055
## country_codeIND                         1.009405   0.325462   3.101 0.001935
## country_codeIRL                         4.929810   0.325462  15.147  < 2e-16
## country_codeIRN                         5.253277   0.325462  16.141  < 2e-16
## country_codeIRQ                         3.047444   0.325462   9.363  < 2e-16
## country_codeISL                         2.502198   0.325462   7.688 1.76e-14
## country_codeISR                         7.600754   0.325462  23.354  < 2e-16
## country_codeITA                         2.491582   0.325462   7.656 2.26e-14
## country_codeJAM                        -2.058446   0.325462  -6.325 2.74e-10
## country_codeJOR                         2.135598   0.325462   6.562 5.80e-11
## country_codeJPN                         8.236514   0.325462  25.307  < 2e-16
## country_codeKAZ                         7.406422   0.325462  22.757  < 2e-16
## country_codeKEN                        -0.779122   0.325462  -2.394 0.016704
## country_codeKGZ                        -2.812972   0.325462  -8.643  < 2e-16
## country_codeKHM                        -0.671830   0.325462  -2.064 0.039042
## country_codeKIR                        -0.485786   0.325462  -1.493 0.135598
## country_codeKNA                        -0.539886   0.325462  -1.659 0.097207
## country_codeKOR                         8.935886   0.325462  27.456  < 2e-16
## country_codeKWT                        23.112341   0.334467  69.102  < 2e-16
## country_codeLAO                        -0.375489   0.325462  -1.154 0.248668
## country_codeLBN                         3.005570   0.325462   9.235  < 2e-16
## country_codeLBR                        -0.846016   0.325462  -2.599 0.009363
## country_codeLBY                         7.409509   0.325462  22.766  < 2e-16
## country_codeLCA                        -2.516674   0.325462  -7.733 1.24e-14
## country_codeLIE                         1.493511   0.325462   4.589 4.55e-06
## country_codeLKA                         0.511548   0.325462   1.572 0.116064
## country_codeLSO                        -0.807198   0.325462  -2.480 0.013162
## country_codeLTU                        -0.227876   0.325462  -0.700 0.483856
## country_codeLUX                        17.115382   0.325462  52.588  < 2e-16
## country_codeLVA                        -0.545676   0.325462  -1.677 0.093674
## country_codeMAR                         0.574110   0.325462   1.764 0.077790
## country_codeMDA                        -0.849227   0.325462  -2.609 0.009097
## country_codeMDG                        -0.947529   0.325462  -2.911 0.003613
## country_codeMDV                         2.045187   0.325462   6.284 3.55e-10
## country_codeMEX                        -1.554325   0.325462  -4.776 1.84e-06
## country_codeMHL                         1.308436   0.331260   3.950 7.92e-05
## country_codeMKD                        -0.159153   0.325462  -0.489 0.624856
## country_codeMLI                        -0.923828   0.331227  -2.789 0.005303
## country_codeMLT                         4.977278   0.325462  15.293  < 2e-16
## country_codeMMR                        -0.751099   0.325462  -2.308 0.021048
## country_codeMNE                        -1.288668   0.325462  -3.960 7.61e-05
## country_codeMNG                         4.077466   0.325462  12.528  < 2e-16
## country_codeMOZ                        -0.928235   0.325462  -2.852 0.004360
## country_codeMRT                        -0.443590   0.325462  -1.363 0.172952
## country_codeMUS                         1.257699   0.325462   3.864 0.000113
## country_codeMWI                        -0.983667   0.325462  -3.022 0.002520
## country_codeMYS                         4.998246   0.325462  15.357  < 2e-16
## country_codeNAM                         0.282860   0.328261   0.862 0.388894
## country_codeNER                        -0.977335   0.325462  -3.003 0.002686
## country_codeNGA                        -0.354572   0.325462  -1.089 0.276006
## country_codeNIC                        -4.611968   0.325462 -14.171  < 2e-16
## country_codeNLD                         5.509005   0.325462  16.927  < 2e-16
## country_codeNOR                         3.267648   0.325462  10.040  < 2e-16
## country_codeNPL                         0.057174   0.325462   0.176 0.860559
## country_codeNRU                         6.383634   0.325462  19.614  < 2e-16
## country_codeNZL                         6.278328   0.325462  19.291  < 2e-16
## country_codeOMN                        11.827954   0.325462  36.342  < 2e-16
## country_codePAK                         0.625074   0.325462   1.921 0.054837
## country_codePAN                        -3.274066   0.325462 -10.060  < 2e-16
## country_codePER                        -4.050152   0.325462 -12.444  < 2e-16
## country_codePHL                        -0.067768   0.325462  -0.208 0.835064
## country_codePLW                        11.077620   0.331260  33.441  < 2e-16
## country_codePNG                        -0.357869   0.325462  -1.100 0.271566
## country_codePOL                         3.774521   0.325462  11.597  < 2e-16
## country_codePRK                         1.923428   0.325462   5.910 3.63e-09
## country_codePRT                         0.688551   0.325462   2.116 0.034423
## country_codePRY                        -4.558799   0.325462 -14.007  < 2e-16
## country_codeQAT                        37.561595   0.325462 115.410  < 2e-16
## country_codeROU                         0.072810   0.325462   0.224 0.822990
## country_codeRUS                         7.024388   0.325462  21.583  < 2e-16
## country_codeRWA                        -0.974817   0.325462  -2.995 0.002755
## country_codeSAU                        12.972570   0.325462  39.859  < 2e-16
## country_codeSDN                        -0.714536   0.325462  -2.195 0.028173
## country_codeSEN                        -0.573002   0.325462  -1.761 0.078365
## country_codeSGP                         8.177079   0.325462  25.125  < 2e-16
## country_codeSLB                        -0.397229   0.325462  -1.221 0.222325
## country_codeSLE                        -0.955713   0.325462  -2.936 0.003333
## country_codeSLV                        -4.355922   0.325462 -13.384  < 2e-16
## country_codeSOM                        -0.988032   0.325462  -3.036 0.002410
## country_codeSRB                         2.103883   0.325462   6.464 1.11e-10
## country_codeSSD                        -0.938310   0.325462  -2.883 0.003954
## country_codeSTP                        -0.566654   0.325462  -1.741 0.081726
## country_codeSUR                        -1.365974   0.325462  -4.197 2.75e-05
## country_codeSVK                         2.646808   0.325462   8.132 5.15e-16
## country_codeSVN                         2.873068   0.325462   8.828  < 2e-16
## country_codeSWE                         0.973743   0.325462   2.992 0.002785
## country_codeSWZ                        -0.388129   0.325462  -1.193 0.233097
## country_codeSYC                         3.216208   0.325462   9.882  < 2e-16
## country_codeSYR                         1.679334   0.325462   5.160 2.56e-07
## country_codeTCD                        -0.965699   0.325462  -2.967 0.003019
## country_codeTGO                        -0.770586   0.325462  -2.368 0.017935
## country_codeTHA                         2.062892   0.325462   6.338 2.51e-10
## country_codeTJK                        -3.820133   0.325462 -11.738  < 2e-16
## country_codeTKM                         5.942881   0.325462  18.260  < 2e-16
## country_codeTLS                        -0.874255   0.376991  -2.319 0.020430
## country_codeTON                         0.162107   0.325462   0.498 0.618445
## country_codeTTO                         6.654215   0.325462  20.445  < 2e-16
## country_codeTUN                         1.443936   0.325462   4.437 9.32e-06
## country_codeTUR                        -0.772883   0.325462  -2.375 0.017596
## country_codeTUV                         0.011769   0.325462   0.036 0.971156
## country_codeTZA                        -0.912599   0.325462  -2.804 0.005065
## country_codeUGA                        -0.969482   0.325462  -2.979 0.002907
## country_codeUKR                         2.260593   0.325462   6.946 4.20e-12
## country_codeURY                        -3.567963   0.325462 -10.963  < 2e-16
## country_codeUSA                               NA         NA      NA       NA
## country_codeUZB                               NA         NA      NA       NA
## country_codeVCT                        -3.183533   0.325462  -9.782  < 2e-16
## country_codeVEN                               NA         NA      NA       NA
## country_codeVNM                         0.251083   0.325462   0.771 0.440464
## country_codeVUT                        -0.502339   0.325462  -1.543 0.122775
## country_codeWSM                               NA         NA      NA       NA
## country_codeYEM                               NA         NA      NA       NA
## country_codeZAF                         6.265177   0.325462  19.250  < 2e-16
## country_codeZMB                        -0.798310   0.325462  -2.453 0.014204
## country_codeZWE                               NA         NA      NA       NA
## year:RegionEurope & Central Asia       -0.089103   0.006230 -14.303  < 2e-16
## year:RegionLatin America & Caribbean    0.006163   0.006789   0.908 0.364027
## year:RegionMiddle East & North Africa  -0.017248   0.007770  -2.220 0.026473
## year:RegionNorth America               -0.116375   0.019446  -5.985 2.31e-09
## year:RegionSouth Asia                   0.001070   0.010632   0.101 0.919851
## year:RegionSub-Saharan Africa          -0.018205   0.006285  -2.897 0.003786
##                                          
## (Intercept)                           ***
## year                                  ***
## RegionEurope & Central Asia           ***
## RegionLatin America & Caribbean          
## RegionMiddle East & North Africa      *  
## RegionNorth America                   ***
## RegionSouth Asia                         
## RegionSub-Saharan Africa              ** 
## country_codeAGO                          
## country_codeALB                       ***
## country_codeAND                       ***
## country_codeARE                       ***
## country_codeARG                       ***
## country_codeARM                       ***
## country_codeATG                          
## country_codeAUS                       ***
## country_codeAUT                       ***
## country_codeAZE                          
## country_codeBDI                       ** 
## country_codeBEL                       ***
## country_codeBEN                       *  
## country_codeBFA                       ** 
## country_codeBGD                          
## country_codeBGR                       ***
## country_codeBHR                       ***
## country_codeBHS                       ***
## country_codeBIH                          
## country_codeBLR                       ***
## country_codeBLZ                       ***
## country_codeBOL                       ***
## country_codeBRA                       ***
## country_codeBRB                          
## country_codeBRN                       ***
## country_codeBTN                          
## country_codeBWA                       ***
## country_codeCAF                       ** 
## country_codeCAN                       ***
## country_codeCHE                       ***
## country_codeCHL                       ***
## country_codeCHN                       ***
## country_codeCIV                       *  
## country_codeCMR                       *  
## country_codeCOD                       ** 
## country_codeCOG                          
## country_codeCOL                       ***
## country_codeCOM                       *  
## country_codeCPV                          
## country_codeCRI                       ***
## country_codeCUB                       ***
## country_codeCYP                       ***
## country_codeCZE                       ***
## country_codeDEU                       ***
## country_codeDJI                          
## country_codeDMA                       ***
## country_codeDNK                       ***
## country_codeDOM                       ***
## country_codeDZA                       ***
## country_codeECU                       ***
## country_codeEGY                       ***
## country_codeERI                       *  
## country_codeESP                       ***
## country_codeEST                       ***
## country_codeETH                       ** 
## country_codeFIN                       ***
## country_codeFJI                          
## country_codeFRA                       ***
## country_codeFSM                          
## country_codeGAB                       ***
## country_codeGBR                       ***
## country_codeGEO                       ***
## country_codeGHA                       *  
## country_codeGIN                       ** 
## country_codeGMB                       *  
## country_codeGNB                       ** 
## country_codeGNQ                       ***
## country_codeGRC                       ***
## country_codeGRD                       ***
## country_codeGTM                       ***
## country_codeGUY                       ***
## country_codeHND                       ***
## country_codeHRV                          
## country_codeHTI                       ***
## country_codeHUN                       *  
## country_codeIDN                          
## country_codeIND                       ** 
## country_codeIRL                       ***
## country_codeIRN                       ***
## country_codeIRQ                       ***
## country_codeISL                       ***
## country_codeISR                       ***
## country_codeITA                       ***
## country_codeJAM                       ***
## country_codeJOR                       ***
## country_codeJPN                       ***
## country_codeKAZ                       ***
## country_codeKEN                       *  
## country_codeKGZ                       ***
## country_codeKHM                       *  
## country_codeKIR                          
## country_codeKNA                       .  
## country_codeKOR                       ***
## country_codeKWT                       ***
## country_codeLAO                          
## country_codeLBN                       ***
## country_codeLBR                       ** 
## country_codeLBY                       ***
## country_codeLCA                       ***
## country_codeLIE                       ***
## country_codeLKA                          
## country_codeLSO                       *  
## country_codeLTU                          
## country_codeLUX                       ***
## country_codeLVA                       .  
## country_codeMAR                       .  
## country_codeMDA                       ** 
## country_codeMDG                       ** 
## country_codeMDV                       ***
## country_codeMEX                       ***
## country_codeMHL                       ***
## country_codeMKD                          
## country_codeMLI                       ** 
## country_codeMLT                       ***
## country_codeMMR                       *  
## country_codeMNE                       ***
## country_codeMNG                       ***
## country_codeMOZ                       ** 
## country_codeMRT                          
## country_codeMUS                       ***
## country_codeMWI                       ** 
## country_codeMYS                       ***
## country_codeNAM                          
## country_codeNER                       ** 
## country_codeNGA                          
## country_codeNIC                       ***
## country_codeNLD                       ***
## country_codeNOR                       ***
## country_codeNPL                          
## country_codeNRU                       ***
## country_codeNZL                       ***
## country_codeOMN                       ***
## country_codePAK                       .  
## country_codePAN                       ***
## country_codePER                       ***
## country_codePHL                          
## country_codePLW                       ***
## country_codePNG                          
## country_codePOL                       ***
## country_codePRK                       ***
## country_codePRT                       *  
## country_codePRY                       ***
## country_codeQAT                       ***
## country_codeROU                          
## country_codeRUS                       ***
## country_codeRWA                       ** 
## country_codeSAU                       ***
## country_codeSDN                       *  
## country_codeSEN                       .  
## country_codeSGP                       ***
## country_codeSLB                          
## country_codeSLE                       ** 
## country_codeSLV                       ***
## country_codeSOM                       ** 
## country_codeSRB                       ***
## country_codeSSD                       ** 
## country_codeSTP                       .  
## country_codeSUR                       ***
## country_codeSVK                       ***
## country_codeSVN                       ***
## country_codeSWE                       ** 
## country_codeSWZ                          
## country_codeSYC                       ***
## country_codeSYR                       ***
## country_codeTCD                       ** 
## country_codeTGO                       *  
## country_codeTHA                       ***
## country_codeTJK                       ***
## country_codeTKM                       ***
## country_codeTLS                       *  
## country_codeTON                          
## country_codeTTO                       ***
## country_codeTUN                       ***
## country_codeTUR                       *  
## country_codeTUV                          
## country_codeTZA                       ** 
## country_codeUGA                       ** 
## country_codeUKR                       ***
## country_codeURY                       ***
## country_codeUSA                          
## country_codeUZB                          
## country_codeVCT                       ***
## country_codeVEN                          
## country_codeVNM                          
## country_codeVUT                          
## country_codeWSM                          
## country_codeYEM                          
## country_codeZAF                       ***
## country_codeZMB                       *  
## country_codeZWE                          
## year:RegionEurope & Central Asia      ***
## year:RegionLatin America & Caribbean     
## year:RegionMiddle East & North Africa *  
## year:RegionNorth America              ***
## year:RegionSouth Asia                    
## year:RegionSub-Saharan Africa         ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.261 on 5506 degrees of freedom
## Multiple R-squared:  0.9496, Adjusted R-squared:  0.9478 
## F-statistic: 526.1 on 197 and 5506 DF,  p-value: < 2.2e-16
summary(model2)
## 
## Call:
## lm(formula = value ~ year * Region + country_code, data = df_long)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -19.8681  -0.2507  -0.0051   0.2358  12.6094 
## 
## Coefficients: (6 not defined because of singularities)
##                                         Estimate Std. Error t value Pr(>|t|)
## (Intercept)                           -63.233898   9.959167  -6.349 2.34e-10
## year                                    0.032039   0.004967   6.450 1.21e-10
## RegionEurope & Central Asia           182.062538  12.491963  14.574  < 2e-16
## RegionLatin America & Caribbean        -8.006687  13.613063  -0.588 0.556448
## RegionMiddle East & North Africa       34.389482  15.578158   2.208 0.027317
## RegionNorth America                   250.437018  38.980981   6.425 1.43e-10
## RegionSouth Asia                       -3.016360  21.314495  -0.142 0.887467
## RegionSub-Saharan Africa               36.553223  12.602042   2.901 0.003739
## country_codeAGO                        -0.149129   0.325462  -0.458 0.646821
## country_codeALB                        -3.193489   0.325462  -9.812  < 2e-16
## country_codeAND                         2.336934   0.325462   7.180 7.87e-13
## country_codeARE                        24.251033   0.325462  74.513  < 2e-16
## country_codeARG                        -1.601866   0.325462  -4.922 8.82e-07
## country_codeARM                        -2.625059   0.325462  -8.066 8.87e-16
## country_codeATG                        -0.096989   0.325462  -0.298 0.765711
## country_codeAUS                        15.838322   0.325462  48.664  < 2e-16
## country_codeAUT                         3.547344   0.325462  10.899  < 2e-16
## country_codeAZE                        -0.527146   0.325462  -1.620 0.105357
## country_codeBDI                        -1.014670   0.325462  -3.118 0.001833
## country_codeBEL                         5.689041   0.325462  17.480  < 2e-16
## country_codeBEN                        -0.710719   0.325462  -2.184 0.029024
## country_codeBFA                        -0.934278   0.325462  -2.871 0.004112
## country_codeBGD                         0.152622   0.325462   0.469 0.639132
## country_codeBGR                         1.779374   0.325462   5.467 4.77e-08
## country_codeBHR                        21.677024   0.325462  66.604  < 2e-16
## country_codeBHS                         2.237421   0.325462   6.875 6.90e-12
## country_codeBIH                         0.049109   0.325462   0.151 0.880069
## country_codeBLR                         1.857654   0.325462   5.708 1.20e-08
## country_codeBLZ                        -3.378674   0.325462 -10.381  < 2e-16
## country_codeBOL                        -3.924199   0.325462 -12.057  < 2e-16
## country_codeBRA                        -3.493048   0.325462 -10.733  < 2e-16
## country_codeBRB                        -0.173706   0.325462  -0.534 0.593556
## country_codeBRN                        15.073230   0.325462  46.313  < 2e-16
## country_codeBTN                         0.478625   0.325462   1.471 0.141456
## country_codeBWA                         1.359778   0.325462   4.178 2.99e-05
## country_codeCAF                        -0.998843   0.325462  -3.069 0.002158
## country_codeCAN                        -2.230251   0.325462  -6.853 8.05e-12
## country_codeCHE                         1.304351   0.325462   4.008 6.21e-05
## country_codeCHL                        -1.725420   0.325462  -5.301 1.19e-07
## country_codeCHN                         3.561359   0.325462  10.942  < 2e-16
## country_codeCIV                        -0.719756   0.325462  -2.211 0.027043
## country_codeCMR                        -0.697514   0.325462  -2.143 0.032145
## country_codeCOD                        -1.004572   0.325462  -3.087 0.002035
## country_codeCOG                         0.108490   0.325462   0.333 0.738889
## country_codeCOL                        -3.823909   0.325462 -11.749  < 2e-16
## country_codeCOM                        -0.831300   0.325462  -2.554 0.010669
## country_codeCPV                        -0.311615   0.325462  -0.957 0.338380
## country_codeCRI                        -3.899059   0.325462 -11.980  < 2e-16
## country_codeCUB                        -2.937519   0.325462  -9.026  < 2e-16
## country_codeCYP                         2.474145   0.325462   7.602 3.41e-14
## country_codeCZE                         6.860147   0.325462  21.078  < 2e-16
## country_codeDEU                         5.496587   0.325462  16.889  < 2e-16
## country_codeDJI                        -0.288340   0.325462  -0.886 0.375689
## country_codeDMA                        -3.179410   0.325462  -9.769  < 2e-16
## country_codeDNK                         4.892993   0.325462  15.034  < 2e-16
## country_codeDOM                        -3.358059   0.325462 -10.318  < 2e-16
## country_codeDZA                         2.216244   0.325462   6.810 1.08e-11
## country_codeECU                        -3.272187   0.325462 -10.054  < 2e-16
## country_codeEGY                         1.226015   0.325462   3.767 0.000167
## country_codeERI                        -0.822484   0.331245  -2.483 0.013057
## country_codeESP                         1.853119   0.325462   5.694 1.31e-08
## country_codeEST                         8.481126   0.325462  26.059  < 2e-16
## country_codeETH                        -0.970977   0.325462  -2.983 0.002863
## country_codeFIN                         6.139156   0.325462  18.863  < 2e-16
## country_codeFJI                         0.289341   0.325462   0.889 0.374033
## country_codeFRA                         1.172116   0.325462   3.601 0.000319
## country_codeFSM                         0.270524   0.331260   0.817 0.414163
## country_codeGAB                         2.959318   0.325462   9.093  < 2e-16
## country_codeGBR                         3.717187   0.325462  11.421  < 2e-16
## country_codeGEO                        -2.382585   0.325462  -7.321 2.82e-13
## country_codeGHA                        -0.667153   0.325462  -2.050 0.040425
## country_codeGIN                        -0.846581   0.325462  -2.601 0.009316
## country_codeGMB                        -0.827194   0.325462  -2.542 0.011062
## country_codeGNB                        -0.891169   0.325462  -2.738 0.006198
## country_codeGNQ                         4.988095   0.325462  15.326  < 2e-16
## country_codeGRC                         3.335677   0.325462  10.249  < 2e-16
## country_codeGRD                        -2.856660   0.325462  -8.777  < 2e-16
## country_codeGTM                        -4.538142   0.325462 -13.944  < 2e-16
## country_codeGUY                        -3.039007   0.325462  -9.338  < 2e-16
## country_codeHND                        -4.464766   0.325462 -13.718  < 2e-16
## country_codeHRV                        -0.267895   0.325462  -0.823 0.410473
## country_codeHTI                        -5.135783   0.325462 -15.780  < 2e-16
## country_codeHUN                         0.786905   0.325462   2.418 0.015646
## country_codeIDN                         0.524591   0.325462   1.612 0.107055
## country_codeIND                         1.009405   0.325462   3.101 0.001935
## country_codeIRL                         4.929810   0.325462  15.147  < 2e-16
## country_codeIRN                         5.253277   0.325462  16.141  < 2e-16
## country_codeIRQ                         3.047444   0.325462   9.363  < 2e-16
## country_codeISL                         2.502198   0.325462   7.688 1.76e-14
## country_codeISR                         7.600754   0.325462  23.354  < 2e-16
## country_codeITA                         2.491582   0.325462   7.656 2.26e-14
## country_codeJAM                        -2.058446   0.325462  -6.325 2.74e-10
## country_codeJOR                         2.135598   0.325462   6.562 5.80e-11
## country_codeJPN                         8.236514   0.325462  25.307  < 2e-16
## country_codeKAZ                         7.406422   0.325462  22.757  < 2e-16
## country_codeKEN                        -0.779122   0.325462  -2.394 0.016704
## country_codeKGZ                        -2.812972   0.325462  -8.643  < 2e-16
## country_codeKHM                        -0.671830   0.325462  -2.064 0.039042
## country_codeKIR                        -0.485786   0.325462  -1.493 0.135598
## country_codeKNA                        -0.539886   0.325462  -1.659 0.097207
## country_codeKOR                         8.935886   0.325462  27.456  < 2e-16
## country_codeKWT                        23.112341   0.334467  69.102  < 2e-16
## country_codeLAO                        -0.375489   0.325462  -1.154 0.248668
## country_codeLBN                         3.005570   0.325462   9.235  < 2e-16
## country_codeLBR                        -0.846016   0.325462  -2.599 0.009363
## country_codeLBY                         7.409509   0.325462  22.766  < 2e-16
## country_codeLCA                        -2.516674   0.325462  -7.733 1.24e-14
## country_codeLIE                         1.493511   0.325462   4.589 4.55e-06
## country_codeLKA                         0.511548   0.325462   1.572 0.116064
## country_codeLSO                        -0.807198   0.325462  -2.480 0.013162
## country_codeLTU                        -0.227876   0.325462  -0.700 0.483856
## country_codeLUX                        17.115382   0.325462  52.588  < 2e-16
## country_codeLVA                        -0.545676   0.325462  -1.677 0.093674
## country_codeMAR                         0.574110   0.325462   1.764 0.077790
## country_codeMDA                        -0.849227   0.325462  -2.609 0.009097
## country_codeMDG                        -0.947529   0.325462  -2.911 0.003613
## country_codeMDV                         2.045187   0.325462   6.284 3.55e-10
## country_codeMEX                        -1.554325   0.325462  -4.776 1.84e-06
## country_codeMHL                         1.308436   0.331260   3.950 7.92e-05
## country_codeMKD                        -0.159153   0.325462  -0.489 0.624856
## country_codeMLI                        -0.923828   0.331227  -2.789 0.005303
## country_codeMLT                         4.977278   0.325462  15.293  < 2e-16
## country_codeMMR                        -0.751099   0.325462  -2.308 0.021048
## country_codeMNE                        -1.288668   0.325462  -3.960 7.61e-05
## country_codeMNG                         4.077466   0.325462  12.528  < 2e-16
## country_codeMOZ                        -0.928235   0.325462  -2.852 0.004360
## country_codeMRT                        -0.443590   0.325462  -1.363 0.172952
## country_codeMUS                         1.257699   0.325462   3.864 0.000113
## country_codeMWI                        -0.983667   0.325462  -3.022 0.002520
## country_codeMYS                         4.998246   0.325462  15.357  < 2e-16
## country_codeNAM                         0.282860   0.328261   0.862 0.388894
## country_codeNER                        -0.977335   0.325462  -3.003 0.002686
## country_codeNGA                        -0.354572   0.325462  -1.089 0.276006
## country_codeNIC                        -4.611968   0.325462 -14.171  < 2e-16
## country_codeNLD                         5.509005   0.325462  16.927  < 2e-16
## country_codeNOR                         3.267648   0.325462  10.040  < 2e-16
## country_codeNPL                         0.057174   0.325462   0.176 0.860559
## country_codeNRU                         6.383634   0.325462  19.614  < 2e-16
## country_codeNZL                         6.278328   0.325462  19.291  < 2e-16
## country_codeOMN                        11.827954   0.325462  36.342  < 2e-16
## country_codePAK                         0.625074   0.325462   1.921 0.054837
## country_codePAN                        -3.274066   0.325462 -10.060  < 2e-16
## country_codePER                        -4.050152   0.325462 -12.444  < 2e-16
## country_codePHL                        -0.067768   0.325462  -0.208 0.835064
## country_codePLW                        11.077620   0.331260  33.441  < 2e-16
## country_codePNG                        -0.357869   0.325462  -1.100 0.271566
## country_codePOL                         3.774521   0.325462  11.597  < 2e-16
## country_codePRK                         1.923428   0.325462   5.910 3.63e-09
## country_codePRT                         0.688551   0.325462   2.116 0.034423
## country_codePRY                        -4.558799   0.325462 -14.007  < 2e-16
## country_codeQAT                        37.561595   0.325462 115.410  < 2e-16
## country_codeROU                         0.072810   0.325462   0.224 0.822990
## country_codeRUS                         7.024388   0.325462  21.583  < 2e-16
## country_codeRWA                        -0.974817   0.325462  -2.995 0.002755
## country_codeSAU                        12.972570   0.325462  39.859  < 2e-16
## country_codeSDN                        -0.714536   0.325462  -2.195 0.028173
## country_codeSEN                        -0.573002   0.325462  -1.761 0.078365
## country_codeSGP                         8.177079   0.325462  25.125  < 2e-16
## country_codeSLB                        -0.397229   0.325462  -1.221 0.222325
## country_codeSLE                        -0.955713   0.325462  -2.936 0.003333
## country_codeSLV                        -4.355922   0.325462 -13.384  < 2e-16
## country_codeSOM                        -0.988032   0.325462  -3.036 0.002410
## country_codeSRB                         2.103883   0.325462   6.464 1.11e-10
## country_codeSSD                        -0.938310   0.325462  -2.883 0.003954
## country_codeSTP                        -0.566654   0.325462  -1.741 0.081726
## country_codeSUR                        -1.365974   0.325462  -4.197 2.75e-05
## country_codeSVK                         2.646808   0.325462   8.132 5.15e-16
## country_codeSVN                         2.873068   0.325462   8.828  < 2e-16
## country_codeSWE                         0.973743   0.325462   2.992 0.002785
## country_codeSWZ                        -0.388129   0.325462  -1.193 0.233097
## country_codeSYC                         3.216208   0.325462   9.882  < 2e-16
## country_codeSYR                         1.679334   0.325462   5.160 2.56e-07
## country_codeTCD                        -0.965699   0.325462  -2.967 0.003019
## country_codeTGO                        -0.770586   0.325462  -2.368 0.017935
## country_codeTHA                         2.062892   0.325462   6.338 2.51e-10
## country_codeTJK                        -3.820133   0.325462 -11.738  < 2e-16
## country_codeTKM                         5.942881   0.325462  18.260  < 2e-16
## country_codeTLS                        -0.874255   0.376991  -2.319 0.020430
## country_codeTON                         0.162107   0.325462   0.498 0.618445
## country_codeTTO                         6.654215   0.325462  20.445  < 2e-16
## country_codeTUN                         1.443936   0.325462   4.437 9.32e-06
## country_codeTUR                        -0.772883   0.325462  -2.375 0.017596
## country_codeTUV                         0.011769   0.325462   0.036 0.971156
## country_codeTZA                        -0.912599   0.325462  -2.804 0.005065
## country_codeUGA                        -0.969482   0.325462  -2.979 0.002907
## country_codeUKR                         2.260593   0.325462   6.946 4.20e-12
## country_codeURY                        -3.567963   0.325462 -10.963  < 2e-16
## country_codeUSA                               NA         NA      NA       NA
## country_codeUZB                               NA         NA      NA       NA
## country_codeVCT                        -3.183533   0.325462  -9.782  < 2e-16
## country_codeVEN                               NA         NA      NA       NA
## country_codeVNM                         0.251083   0.325462   0.771 0.440464
## country_codeVUT                        -0.502339   0.325462  -1.543 0.122775
## country_codeWSM                               NA         NA      NA       NA
## country_codeYEM                               NA         NA      NA       NA
## country_codeZAF                         6.265177   0.325462  19.250  < 2e-16
## country_codeZMB                        -0.798310   0.325462  -2.453 0.014204
## country_codeZWE                               NA         NA      NA       NA
## year:RegionEurope & Central Asia       -0.089103   0.006230 -14.303  < 2e-16
## year:RegionLatin America & Caribbean    0.006163   0.006789   0.908 0.364027
## year:RegionMiddle East & North Africa  -0.017248   0.007770  -2.220 0.026473
## year:RegionNorth America               -0.116375   0.019446  -5.985 2.31e-09
## year:RegionSouth Asia                   0.001070   0.010632   0.101 0.919851
## year:RegionSub-Saharan Africa          -0.018205   0.006285  -2.897 0.003786
##                                          
## (Intercept)                           ***
## year                                  ***
## RegionEurope & Central Asia           ***
## RegionLatin America & Caribbean          
## RegionMiddle East & North Africa      *  
## RegionNorth America                   ***
## RegionSouth Asia                         
## RegionSub-Saharan Africa              ** 
## country_codeAGO                          
## country_codeALB                       ***
## country_codeAND                       ***
## country_codeARE                       ***
## country_codeARG                       ***
## country_codeARM                       ***
## country_codeATG                          
## country_codeAUS                       ***
## country_codeAUT                       ***
## country_codeAZE                          
## country_codeBDI                       ** 
## country_codeBEL                       ***
## country_codeBEN                       *  
## country_codeBFA                       ** 
## country_codeBGD                          
## country_codeBGR                       ***
## country_codeBHR                       ***
## country_codeBHS                       ***
## country_codeBIH                          
## country_codeBLR                       ***
## country_codeBLZ                       ***
## country_codeBOL                       ***
## country_codeBRA                       ***
## country_codeBRB                          
## country_codeBRN                       ***
## country_codeBTN                          
## country_codeBWA                       ***
## country_codeCAF                       ** 
## country_codeCAN                       ***
## country_codeCHE                       ***
## country_codeCHL                       ***
## country_codeCHN                       ***
## country_codeCIV                       *  
## country_codeCMR                       *  
## country_codeCOD                       ** 
## country_codeCOG                          
## country_codeCOL                       ***
## country_codeCOM                       *  
## country_codeCPV                          
## country_codeCRI                       ***
## country_codeCUB                       ***
## country_codeCYP                       ***
## country_codeCZE                       ***
## country_codeDEU                       ***
## country_codeDJI                          
## country_codeDMA                       ***
## country_codeDNK                       ***
## country_codeDOM                       ***
## country_codeDZA                       ***
## country_codeECU                       ***
## country_codeEGY                       ***
## country_codeERI                       *  
## country_codeESP                       ***
## country_codeEST                       ***
## country_codeETH                       ** 
## country_codeFIN                       ***
## country_codeFJI                          
## country_codeFRA                       ***
## country_codeFSM                          
## country_codeGAB                       ***
## country_codeGBR                       ***
## country_codeGEO                       ***
## country_codeGHA                       *  
## country_codeGIN                       ** 
## country_codeGMB                       *  
## country_codeGNB                       ** 
## country_codeGNQ                       ***
## country_codeGRC                       ***
## country_codeGRD                       ***
## country_codeGTM                       ***
## country_codeGUY                       ***
## country_codeHND                       ***
## country_codeHRV                          
## country_codeHTI                       ***
## country_codeHUN                       *  
## country_codeIDN                          
## country_codeIND                       ** 
## country_codeIRL                       ***
## country_codeIRN                       ***
## country_codeIRQ                       ***
## country_codeISL                       ***
## country_codeISR                       ***
## country_codeITA                       ***
## country_codeJAM                       ***
## country_codeJOR                       ***
## country_codeJPN                       ***
## country_codeKAZ                       ***
## country_codeKEN                       *  
## country_codeKGZ                       ***
## country_codeKHM                       *  
## country_codeKIR                          
## country_codeKNA                       .  
## country_codeKOR                       ***
## country_codeKWT                       ***
## country_codeLAO                          
## country_codeLBN                       ***
## country_codeLBR                       ** 
## country_codeLBY                       ***
## country_codeLCA                       ***
## country_codeLIE                       ***
## country_codeLKA                          
## country_codeLSO                       *  
## country_codeLTU                          
## country_codeLUX                       ***
## country_codeLVA                       .  
## country_codeMAR                       .  
## country_codeMDA                       ** 
## country_codeMDG                       ** 
## country_codeMDV                       ***
## country_codeMEX                       ***
## country_codeMHL                       ***
## country_codeMKD                          
## country_codeMLI                       ** 
## country_codeMLT                       ***
## country_codeMMR                       *  
## country_codeMNE                       ***
## country_codeMNG                       ***
## country_codeMOZ                       ** 
## country_codeMRT                          
## country_codeMUS                       ***
## country_codeMWI                       ** 
## country_codeMYS                       ***
## country_codeNAM                          
## country_codeNER                       ** 
## country_codeNGA                          
## country_codeNIC                       ***
## country_codeNLD                       ***
## country_codeNOR                       ***
## country_codeNPL                          
## country_codeNRU                       ***
## country_codeNZL                       ***
## country_codeOMN                       ***
## country_codePAK                       .  
## country_codePAN                       ***
## country_codePER                       ***
## country_codePHL                          
## country_codePLW                       ***
## country_codePNG                          
## country_codePOL                       ***
## country_codePRK                       ***
## country_codePRT                       *  
## country_codePRY                       ***
## country_codeQAT                       ***
## country_codeROU                          
## country_codeRUS                       ***
## country_codeRWA                       ** 
## country_codeSAU                       ***
## country_codeSDN                       *  
## country_codeSEN                       .  
## country_codeSGP                       ***
## country_codeSLB                          
## country_codeSLE                       ** 
## country_codeSLV                       ***
## country_codeSOM                       ** 
## country_codeSRB                       ***
## country_codeSSD                       ** 
## country_codeSTP                       .  
## country_codeSUR                       ***
## country_codeSVK                       ***
## country_codeSVN                       ***
## country_codeSWE                       ** 
## country_codeSWZ                          
## country_codeSYC                       ***
## country_codeSYR                       ***
## country_codeTCD                       ** 
## country_codeTGO                       *  
## country_codeTHA                       ***
## country_codeTJK                       ***
## country_codeTKM                       ***
## country_codeTLS                       *  
## country_codeTON                          
## country_codeTTO                       ***
## country_codeTUN                       ***
## country_codeTUR                       *  
## country_codeTUV                          
## country_codeTZA                       ** 
## country_codeUGA                       ** 
## country_codeUKR                       ***
## country_codeURY                       ***
## country_codeUSA                          
## country_codeUZB                          
## country_codeVCT                       ***
## country_codeVEN                          
## country_codeVNM                          
## country_codeVUT                          
## country_codeWSM                          
## country_codeYEM                          
## country_codeZAF                       ***
## country_codeZMB                       *  
## country_codeZWE                          
## year:RegionEurope & Central Asia      ***
## year:RegionLatin America & Caribbean     
## year:RegionMiddle East & North Africa *  
## year:RegionNorth America              ***
## year:RegionSouth Asia                    
## year:RegionSub-Saharan Africa         ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.261 on 5506 degrees of freedom
## Multiple R-squared:  0.9496, Adjusted R-squared:  0.9478 
## F-statistic: 526.1 on 197 and 5506 DF,  p-value: < 2.2e-16
ggplot(df_long, aes(year, value, color = Region)) +
  geom_line(stat = "summary", fun = mean)

model <- lm(value ~ year * Region, data = df_long)
par(mfrow = c(2, 2))
plot(model)

ggplot(data.frame(residuals = resid(model)), aes(x = residuals)) +
  geom_histogram(bins = 30) +
  labs(title = "Residual Distribution")

ggplot(data.frame(
  fitted = fitted(model),
  resid = resid(model)
), aes(x = fitted, y = resid)) +
  geom_point(alpha = 0.4) +
  geom_hline(yintercept = 0, color = "red") +
  labs(title = "Residuals vs Fitted Values")

plot(model, which = 5)

model <- lm(value ~ year * Region, data = df_long)
library(lmtest)
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
bptest(model)
## 
##  studentized Breusch-Pagan test
## 
## data:  model
## BP = 776.75, df = 13, p-value < 2.2e-16
library(car)
## Loading required package: carData
## 
## Attaching package: 'car'
## The following object is masked from 'package:dplyr':
## 
##     recode
## The following object is masked from 'package:purrr':
## 
##     some
vif(model)
## there are higher-order terms (interactions) in this model
## consider setting type = 'predictor'; see ?vif
##                     GVIF Df GVIF^(1/(2*Df))
## year        6.543057e+00  1         2.55794
## Region      2.425154e+28  6       231.95030
## year:Region 2.424993e+28  6       231.94902
model1 <- lm(value ~ year + Region, data = df_long)
model2 <- lm(value ~ year * Region, data = df_long)

AIC(model1, model2)
##        df      AIC
## model1  9 33450.89
## model2 15 33432.67
summary(model1)$adj.r.squared
## [1] 0.3228851
summary(model2)$adj.r.squared
## [1] 0.3257531

##The regression analysis shows a strong relationship between the indicator value, time, and regional classification. The Breusch–Pagan test indicates heteroskedasticity, suggesting non-constant error variance. However, coefficient estimates remain valid. Multicollinearity is high for region and interaction terms due to model specification involving interaction effects. Despite this, the model remains useful for capturing heterogeneous regional time trends. Model comparison using AIC will determine whether the interaction specification provides a better fit than the simpler model.

#HW: Read about variable selection method

library(MASS)
## 
## Attaching package: 'MASS'
## The following object is masked from 'package:dplyr':
## 
##     select
df_long <- df_long %>%
  filter(!is.na(value)) %>%
  mutate(
    Region = as.factor(Region),
    country_code = as.factor(country_code)
  )
full_model <- lm(value ~ year + Region + country_code, data = df_long)

summary(full_model)
## 
## Call:
## lm(formula = value ~ year + Region + country_code, data = df_long)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -20.0575  -0.2872  -0.0097   0.2343  12.5902 
## 
## Coefficients: (6 not defined because of singularities)
##                                   Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                      -2.978134   4.015321  -0.742 0.458305    
## year                              0.001979   0.002000   0.990 0.322381    
## RegionEurope & Central Asia       3.455601   0.336623  10.265  < 2e-16 ***
## RegionLatin America & Caribbean   4.347631   0.336623  12.915  < 2e-16 ***
## RegionMiddle East & North Africa -0.183460   0.336623  -0.545 0.585774    
## RegionNorth America              17.162696   0.336623  50.985  < 2e-16 ***
## RegionSouth Asia                 -0.871810   0.336623  -2.590 0.009627 ** 
## RegionSub-Saharan Africa          0.060905   0.336623   0.181 0.856429    
## country_codeAGO                  -0.149129   0.336623  -0.443 0.657773    
## country_codeALB                  -3.193489   0.336623  -9.487  < 2e-16 ***
## country_codeAND                   2.336934   0.336623   6.942 4.30e-12 ***
## country_codeARE                  24.251033   0.336623  72.042  < 2e-16 ***
## country_codeARG                  -1.601866   0.336623  -4.759 2.00e-06 ***
## country_codeARM                  -2.625059   0.336623  -7.798 7.46e-15 ***
## country_codeATG                  -0.096989   0.336623  -0.288 0.773263    
## country_codeAUS                  15.838322   0.336623  47.051  < 2e-16 ***
## country_codeAUT                   3.547344   0.336623  10.538  < 2e-16 ***
## country_codeAZE                  -0.527146   0.336623  -1.566 0.117410    
## country_codeBDI                  -1.014670   0.336623  -3.014 0.002588 ** 
## country_codeBEL                   5.689041   0.336623  16.900  < 2e-16 ***
## country_codeBEN                  -0.710719   0.336623  -2.111 0.034790 *  
## country_codeBFA                  -0.934278   0.336623  -2.775 0.005531 ** 
## country_codeBGD                   0.152622   0.336623   0.453 0.650286    
## country_codeBGR                   1.779374   0.336623   5.286 1.30e-07 ***
## country_codeBHR                  21.677024   0.336623  64.395  < 2e-16 ***
## country_codeBHS                   2.237421   0.336623   6.647 3.29e-11 ***
## country_codeBIH                   0.049109   0.336623   0.146 0.884017    
## country_codeBLR                   1.857654   0.336623   5.518 3.58e-08 ***
## country_codeBLZ                  -3.378674   0.336623 -10.037  < 2e-16 ***
## country_codeBOL                  -3.924199   0.336623 -11.658  < 2e-16 ***
## country_codeBRA                  -3.493048   0.336623 -10.377  < 2e-16 ***
## country_codeBRB                  -0.173706   0.336623  -0.516 0.605859    
## country_codeBRN                  15.073230   0.336623  44.778  < 2e-16 ***
## country_codeBTN                   0.478625   0.336623   1.422 0.155129    
## country_codeBWA                   1.359778   0.336623   4.039 5.43e-05 ***
## country_codeCAF                  -0.998843   0.336623  -2.967 0.003018 ** 
## country_codeCAN                  -2.230251   0.336623  -6.625 3.79e-11 ***
## country_codeCHE                   1.304351   0.336623   3.875 0.000108 ***
## country_codeCHL                  -1.725420   0.336623  -5.126 3.07e-07 ***
## country_codeCHN                   3.561359   0.336623  10.580  < 2e-16 ***
## country_codeCIV                  -0.719756   0.336623  -2.138 0.032547 *  
## country_codeCMR                  -0.697514   0.336623  -2.072 0.038303 *  
## country_codeCOD                  -1.004572   0.336623  -2.984 0.002855 ** 
## country_codeCOG                   0.108490   0.336623   0.322 0.747246    
## country_codeCOL                  -3.823909   0.336623 -11.360  < 2e-16 ***
## country_codeCOM                  -0.831300   0.336623  -2.470 0.013559 *  
## country_codeCPV                  -0.311615   0.336623  -0.926 0.354638    
## country_codeCRI                  -3.899059   0.336623 -11.583  < 2e-16 ***
## country_codeCUB                  -2.937519   0.336623  -8.726  < 2e-16 ***
## country_codeCYP                   2.474145   0.336623   7.350 2.27e-13 ***
## country_codeCZE                   6.860147   0.336623  20.379  < 2e-16 ***
## country_codeDEU                   5.496587   0.336623  16.329  < 2e-16 ***
## country_codeDJI                  -0.288340   0.336623  -0.857 0.391723    
## country_codeDMA                  -3.179410   0.336623  -9.445  < 2e-16 ***
## country_codeDNK                   4.892993   0.336623  14.536  < 2e-16 ***
## country_codeDOM                  -3.358059   0.336623  -9.976  < 2e-16 ***
## country_codeDZA                   2.216244   0.336623   6.584 5.01e-11 ***
## country_codeECU                  -3.272187   0.336623  -9.721  < 2e-16 ***
## country_codeEGY                   1.226015   0.336623   3.642 0.000273 ***
## country_codeERI                  -0.810629   0.342588  -2.366 0.018006 *  
## country_codeESP                   1.853119   0.336623   5.505 3.86e-08 ***
## country_codeEST                   8.481126   0.336623  25.195  < 2e-16 ***
## country_codeETH                  -0.970977   0.336623  -2.884 0.003936 ** 
## country_codeFIN                   6.139156   0.336623  18.237  < 2e-16 ***
## country_codeFJI                   0.289341   0.336623   0.860 0.390081    
## country_codeFRA                   1.172116   0.336623   3.482 0.000502 ***
## country_codeFSM                   0.300584   0.342588   0.877 0.380312    
## country_codeGAB                   2.959318   0.336623   8.791  < 2e-16 ***
## country_codeGBR                   3.717187   0.336623  11.043  < 2e-16 ***
## country_codeGEO                  -2.382585   0.336623  -7.078 1.65e-12 ***
## country_codeGHA                  -0.667153   0.336623  -1.982 0.047540 *  
## country_codeGIN                  -0.846581   0.336623  -2.515 0.011934 *  
## country_codeGMB                  -0.827194   0.336623  -2.457 0.014028 *  
## country_codeGNB                  -0.891169   0.336623  -2.647 0.008135 ** 
## country_codeGNQ                   4.988095   0.336623  14.818  < 2e-16 ***
## country_codeGRC                   3.335677   0.336623   9.909  < 2e-16 ***
## country_codeGRD                  -2.856660   0.336623  -8.486  < 2e-16 ***
## country_codeGTM                  -4.538142   0.336623 -13.481  < 2e-16 ***
## country_codeGUY                  -3.039007   0.336623  -9.028  < 2e-16 ***
## country_codeHND                  -4.464766   0.336623 -13.263  < 2e-16 ***
## country_codeHRV                  -0.267895   0.336623  -0.796 0.426165    
## country_codeHTI                  -5.135783   0.336623 -15.257  < 2e-16 ***
## country_codeHUN                   0.786905   0.336623   2.338 0.019441 *  
## country_codeIDN                   0.524591   0.336623   1.558 0.119198    
## country_codeIND                   1.009405   0.336623   2.999 0.002724 ** 
## country_codeIRL                   4.929810   0.336623  14.645  < 2e-16 ***
## country_codeIRN                   5.253277   0.336623  15.606  < 2e-16 ***
## country_codeIRQ                   3.047444   0.336623   9.053  < 2e-16 ***
## country_codeISL                   2.502198   0.336623   7.433 1.22e-13 ***
## country_codeISR                   7.600754   0.336623  22.579  < 2e-16 ***
## country_codeITA                   2.491582   0.336623   7.402 1.55e-13 ***
## country_codeJAM                  -2.058446   0.336623  -6.115 1.03e-09 ***
## country_codeJOR                   2.135598   0.336623   6.344 2.41e-10 ***
## country_codeJPN                   8.236514   0.336623  24.468  < 2e-16 ***
## country_codeKAZ                   7.406422   0.336623  22.002  < 2e-16 ***
## country_codeKEN                  -0.779122   0.336623  -2.315 0.020676 *  
## country_codeKGZ                  -2.812972   0.336623  -8.356  < 2e-16 ***
## country_codeKHM                  -0.671830   0.336623  -1.996 0.046006 *  
## country_codeKIR                  -0.485786   0.336623  -1.443 0.149045    
## country_codeKNA                  -0.539886   0.336623  -1.604 0.108809    
## country_codeKOR                   8.935886   0.336623  26.546  < 2e-16 ***
## country_codeKWT                  23.128712   0.345857  66.874  < 2e-16 ***
## country_codeLAO                  -0.375489   0.336623  -1.115 0.264703    
## country_codeLBN                   3.005570   0.336623   8.929  < 2e-16 ***
## country_codeLBR                  -0.846016   0.336623  -2.513 0.011991 *  
## country_codeLBY                   7.409509   0.336623  22.011  < 2e-16 ***
## country_codeLCA                  -2.516674   0.336623  -7.476 8.85e-14 ***
## country_codeLIE                   1.493511   0.336623   4.437 9.31e-06 ***
## country_codeLKA                   0.511548   0.336623   1.520 0.128658    
## country_codeLSO                  -0.807198   0.336623  -2.398 0.016521 *  
## country_codeLTU                  -0.227876   0.336623  -0.677 0.498469    
## country_codeLUX                  17.115382   0.336623  50.844  < 2e-16 ***
## country_codeLVA                  -0.545676   0.336623  -1.621 0.105069    
## country_codeMAR                   0.574110   0.336623   1.705 0.088158 .  
## country_codeMDA                  -0.849227   0.336623  -2.523 0.011671 *  
## country_codeMDG                  -0.947529   0.336623  -2.815 0.004898 ** 
## country_codeMDV                   2.045187   0.336623   6.076 1.32e-09 ***
## country_codeMEX                  -1.554325   0.336623  -4.617 3.97e-06 ***
## country_codeMHL                   1.338496   0.342588   3.907 9.46e-05 ***
## country_codeMKD                  -0.159153   0.336623  -0.473 0.636380    
## country_codeMLI                  -0.918747   0.342583  -2.682 0.007344 ** 
## country_codeMLT                   4.977278   0.336623  14.786  < 2e-16 ***
## country_codeMMR                  -0.751099   0.336623  -2.231 0.025703 *  
## country_codeMNE                  -1.288668   0.336623  -3.828 0.000131 ***
## country_codeMNG                   4.077466   0.336623  12.113  < 2e-16 ***
## country_codeMOZ                  -0.928235   0.336623  -2.757 0.005844 ** 
## country_codeMRT                  -0.443590   0.336623  -1.318 0.187638    
## country_codeMUS                   1.257699   0.336623   3.736 0.000189 ***
## country_codeMWI                  -0.983667   0.336623  -2.922 0.003490 ** 
## country_codeMYS                   4.998246   0.336623  14.848  < 2e-16 ***
## country_codeNAM                   0.288788   0.339514   0.851 0.395034    
## country_codeNER                  -0.977335   0.336623  -2.903 0.003707 ** 
## country_codeNGA                  -0.354572   0.336623  -1.053 0.292241    
## country_codeNIC                  -4.611968   0.336623 -13.701  < 2e-16 ***
## country_codeNLD                   5.509005   0.336623  16.365  < 2e-16 ***
## country_codeNOR                   3.267648   0.336623   9.707  < 2e-16 ***
## country_codeNPL                   0.057174   0.336623   0.170 0.865138    
## country_codeNRU                   6.383634   0.336623  18.964  < 2e-16 ***
## country_codeNZL                   6.278328   0.336623  18.651  < 2e-16 ***
## country_codeOMN                  11.827954   0.336623  35.137  < 2e-16 ***
## country_codePAK                   0.625074   0.336623   1.857 0.063380 .  
## country_codePAN                  -3.274066   0.336623  -9.726  < 2e-16 ***
## country_codePER                  -4.050152   0.336623 -12.032  < 2e-16 ***
## country_codePHL                  -0.067768   0.336623  -0.201 0.840458    
## country_codePLW                  11.107680   0.342588  32.423  < 2e-16 ***
## country_codePNG                  -0.357869   0.336623  -1.063 0.287777    
## country_codePOL                   3.774521   0.336623  11.213  < 2e-16 ***
## country_codePRK                   1.923428   0.336623   5.714 1.16e-08 ***
## country_codePRT                   0.688551   0.336623   2.045 0.040857 *  
## country_codePRY                  -4.558799   0.336623 -13.543  < 2e-16 ***
## country_codeQAT                  37.561595   0.336623 111.583  < 2e-16 ***
## country_codeROU                   0.072810   0.336623   0.216 0.828766    
## country_codeRUS                   7.024388   0.336623  20.867  < 2e-16 ***
## country_codeRWA                  -0.974817   0.336623  -2.896 0.003796 ** 
## country_codeSAU                  12.972570   0.336623  38.537  < 2e-16 ***
## country_codeSDN                  -0.714536   0.336623  -2.123 0.033827 *  
## country_codeSEN                  -0.573002   0.336623  -1.702 0.088774 .  
## country_codeSGP                   8.177079   0.336623  24.291  < 2e-16 ***
## country_codeSLB                  -0.397229   0.336623  -1.180 0.238036    
## country_codeSLE                  -0.955713   0.336623  -2.839 0.004540 ** 
## country_codeSLV                  -4.355922   0.336623 -12.940  < 2e-16 ***
## country_codeSOM                  -0.988032   0.336623  -2.935 0.003348 ** 
## country_codeSRB                   2.103883   0.336623   6.250 4.41e-10 ***
## country_codeSSD                  -0.938310   0.336623  -2.787 0.005331 ** 
## country_codeSTP                  -0.566654   0.336623  -1.683 0.092365 .  
## country_codeSUR                  -1.365974   0.336623  -4.058 5.02e-05 ***
## country_codeSVK                   2.646808   0.336623   7.863 4.49e-15 ***
## country_codeSVN                   2.873068   0.336623   8.535  < 2e-16 ***
## country_codeSWE                   0.973743   0.336623   2.893 0.003835 ** 
## country_codeSWZ                  -0.388129   0.336623  -1.153 0.248958    
## country_codeSYC                   3.216208   0.336623   9.554  < 2e-16 ***
## country_codeSYR                   1.679334   0.336623   4.989 6.26e-07 ***
## country_codeTCD                  -0.965699   0.336623  -2.869 0.004136 ** 
## country_codeTGO                  -0.770586   0.336623  -2.289 0.022108 *  
## country_codeTHA                   2.062892   0.336623   6.128 9.50e-10 ***
## country_codeTJK                  -3.820133   0.336623 -11.348  < 2e-16 ***
## country_codeTKM                   5.942881   0.336623  17.654  < 2e-16 ***
## country_codeTLS                  -0.693893   0.388884  -1.784 0.074427 .  
## country_codeTON                   0.162107   0.336623   0.482 0.630132    
## country_codeTTO                   6.654215   0.336623  19.768  < 2e-16 ***
## country_codeTUN                   1.443936   0.336623   4.289 1.82e-05 ***
## country_codeTUR                  -0.772883   0.336623  -2.296 0.021714 *  
## country_codeTUV                   0.011769   0.336623   0.035 0.972112    
## country_codeTZA                  -0.912599   0.336623  -2.711 0.006728 ** 
## country_codeUGA                  -0.969482   0.336623  -2.880 0.003992 ** 
## country_codeUKR                   2.260593   0.336623   6.715 2.06e-11 ***
## country_codeURY                  -3.567963   0.336623 -10.599  < 2e-16 ***
## country_codeUSA                         NA         NA      NA       NA    
## country_codeUZB                         NA         NA      NA       NA    
## country_codeVCT                  -3.183533   0.336623  -9.457  < 2e-16 ***
## country_codeVEN                         NA         NA      NA       NA    
## country_codeVNM                   0.251083   0.336623   0.746 0.455768    
## country_codeVUT                  -0.502339   0.336623  -1.492 0.135681    
## country_codeWSM                         NA         NA      NA       NA    
## country_codeYEM                         NA         NA      NA       NA    
## country_codeZAF                   6.265177   0.336623  18.612  < 2e-16 ***
## country_codeZMB                  -0.798310   0.336623  -2.372 0.017749 *  
## country_codeZWE                         NA         NA      NA       NA    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.304 on 5512 degrees of freedom
## Multiple R-squared:  0.946,  Adjusted R-squared:  0.9441 
## F-statistic: 505.3 on 191 and 5512 DF,  p-value: < 2.2e-16
null_model <- lm(value ~ 1, data = df_long)

forward_model <- step(null_model,
                      scope = list(lower = null_model,
                                   upper = full_model),
                      direction = "forward")
## Start:  AIC=19478.72
## value ~ 1
## 
##                 Df Sum of Sq    RSS     AIC
## + country_code 190    164053   9371  3213.5
## + Region         6     56138 117286 17259.8
## <none>                       173424 19478.7
## + year           1         2 173422 19480.6
## 
## Step:  AIC=3213.51
## value ~ country_code
## 
##        Df Sum of Sq    RSS    AIC
## <none>              9370.6 3213.5
## + year  1    1.6648 9368.9 3214.5
summary(forward_model)
## 
## Call:
## lm(formula = value ~ country_code, data = df_long)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -20.0867  -0.2911  -0.0096   0.2372  12.5872 
## 
## Coefficients:
##                  Estimate Std. Error t value Pr(>|t|)    
## (Intercept)      0.116895   0.238028   0.491 0.623377    
## country_codeAGO  0.783586   0.336623   2.328 0.019959 *  
## country_codeALB  1.133921   0.336623   3.369 0.000761 ***
## country_codeAND  6.664344   0.336623  19.798  < 2e-16 ***
## country_codeARE 24.939382   0.336623  74.087  < 2e-16 ***
## country_codeARG  3.617575   0.336623  10.747  < 2e-16 ***
## country_codeARM  1.702351   0.336623   5.057 4.39e-07 ***
## country_codeATG  5.122452   0.336623  15.217  < 2e-16 ***
## country_codeAUS 16.710132   0.336623  49.641  < 2e-16 ***
## country_codeAUT  7.874754   0.336623  23.393  < 2e-16 ***
## country_codeAZE  3.800264   0.336623  11.289  < 2e-16 ***
## country_codeBDI -0.081955   0.336623  -0.243 0.807656    
## country_codeBEL 10.016451   0.336623  29.756  < 2e-16 ***
## country_codeBEN  0.221996   0.336623   0.659 0.509616    
## country_codeBFA -0.001563   0.336623  -0.005 0.996295    
## country_codeBGD  0.152622   0.336623   0.453 0.650285    
## country_codeBGR  6.106784   0.336623  18.141  < 2e-16 ***
## country_codeBHR 22.365373   0.336623  66.440  < 2e-16 ***
## country_codeBHS  7.456861   0.336623  22.152  < 2e-16 ***
## country_codeBIH  4.376519   0.336623  13.001  < 2e-16 ***
## country_codeBLR  6.185064   0.336623  18.374  < 2e-16 ***
## country_codeBLZ  1.840766   0.336623   5.468 4.74e-08 ***
## country_codeBOL  1.295242   0.336623   3.848 0.000121 ***
## country_codeBRA  1.726393   0.336623   5.129 3.02e-07 ***
## country_codeBRB  5.045735   0.336623  14.989  < 2e-16 ***
## country_codeBRN 15.945040   0.336623  47.368  < 2e-16 ***
## country_codeBTN  0.478625   0.336623   1.422 0.155128    
## country_codeBWA  2.292493   0.336623   6.810 1.08e-11 ***
## country_codeCAF -0.066128   0.336623  -0.196 0.844268    
## country_codeCAN 15.804255   0.336623  46.949  < 2e-16 ***
## country_codeCHE  5.631761   0.336623  16.730  < 2e-16 ***
## country_codeCHL  3.494021   0.336623  10.380  < 2e-16 ***
## country_codeCHN  4.433169   0.336623  13.170  < 2e-16 ***
## country_codeCIV  0.212959   0.336623   0.633 0.526999    
## country_codeCMR  0.235201   0.336623   0.699 0.484764    
## country_codeCOD -0.071857   0.336623  -0.213 0.830973    
## country_codeCOG  1.041205   0.336623   3.093 0.001991 ** 
## country_codeCOL  1.395531   0.336623   4.146 3.44e-05 ***
## country_codeCOM  0.101415   0.336623   0.301 0.763219    
## country_codeCPV  0.621100   0.336623   1.845 0.065078 .  
## country_codeCRI  1.320382   0.336623   3.922 8.87e-05 ***
## country_codeCUB  2.281922   0.336623   6.779 1.34e-11 ***
## country_codeCYP  6.801556   0.336623  20.205  < 2e-16 ***
## country_codeCZE 11.187557   0.336623  33.235  < 2e-16 ***
## country_codeDEU  9.823997   0.336623  29.184  < 2e-16 ***
## country_codeDJI  0.400010   0.336623   1.188 0.234766    
## country_codeDMA  2.040031   0.336623   6.060 1.45e-09 ***
## country_codeDNK  9.220403   0.336623  27.391  < 2e-16 ***
## country_codeDOM  1.861382   0.336623   5.530 3.36e-08 ***
## country_codeDZA  2.904593   0.336623   8.629  < 2e-16 ***
## country_codeECU  1.947254   0.336623   5.785 7.67e-09 ***
## country_codeEGY  1.914364   0.336623   5.687 1.36e-08 ***
## country_codeERI  0.124065   0.342581   0.362 0.717256    
## country_codeESP  6.180530   0.336623  18.360  < 2e-16 ***
## country_codeEST 12.808536   0.336623  38.050  < 2e-16 ***
## country_codeETH -0.038262   0.336623  -0.114 0.909509    
## country_codeFIN 10.466566   0.336623  31.093  < 2e-16 ***
## country_codeFJI  1.161150   0.336623   3.449 0.000566 ***
## country_codeFRA  5.499527   0.336623  16.337  < 2e-16 ***
## country_codeFSM  1.174372   0.342581   3.428 0.000612 ***
## country_codeGAB  3.892033   0.336623  11.562  < 2e-16 ***
## country_codeGBR  8.044597   0.336623  23.898  < 2e-16 ***
## country_codeGEO  1.944825   0.336623   5.777 8.00e-09 ***
## country_codeGHA  0.265562   0.336623   0.789 0.430205    
## country_codeGIN  0.086134   0.336623   0.256 0.798056    
## country_codeGMB  0.105521   0.336623   0.313 0.753935    
## country_codeGNB  0.041546   0.336623   0.123 0.901778    
## country_codeGNQ  5.920810   0.336623  17.589  < 2e-16 ***
## country_codeGRC  7.663088   0.336623  22.765  < 2e-16 ***
## country_codeGRD  2.362781   0.336623   7.019 2.50e-12 ***
## country_codeGTM  0.681299   0.336623   2.024 0.043026 *  
## country_codeGUY  2.180433   0.336623   6.477 1.01e-10 ***
## country_codeHND  0.754675   0.336623   2.242 0.025007 *  
## country_codeHRV  4.059515   0.336623  12.060  < 2e-16 ***
## country_codeHTI  0.083657   0.336623   0.249 0.803742    
## country_codeHUN  5.114315   0.336623  15.193  < 2e-16 ***
## country_codeIDN  1.396401   0.336623   4.148 3.40e-05 ***
## country_codeIND  1.009405   0.336623   2.999 0.002724 ** 
## country_codeIRL  9.257220   0.336623  27.500  < 2e-16 ***
## country_codeIRN  5.941626   0.336623  17.651  < 2e-16 ***
## country_codeIRQ  3.735793   0.336623  11.098  < 2e-16 ***
## country_codeISL  6.829608   0.336623  20.289  < 2e-16 ***
## country_codeISR  8.289103   0.336623  24.624  < 2e-16 ***
## country_codeITA  6.818992   0.336623  20.257  < 2e-16 ***
## country_codeJAM  3.160994   0.336623   9.390  < 2e-16 ***
## country_codeJOR  2.823947   0.336623   8.389  < 2e-16 ***
## country_codeJPN  9.108324   0.336623  27.058  < 2e-16 ***
## country_codeKAZ 11.733833   0.336623  34.858  < 2e-16 ***
## country_codeKEN  0.153593   0.336623   0.456 0.648210    
## country_codeKGZ  1.514438   0.336623   4.499 6.97e-06 ***
## country_codeKHM  0.199980   0.336623   0.594 0.552486    
## country_codeKIR  0.386023   0.336623   1.147 0.251533    
## country_codeKNA  4.679554   0.336623  13.901  < 2e-16 ***
## country_codeKOR  9.807696   0.336623  29.136  < 2e-16 ***
## country_codeKWT 23.819590   0.345847  68.873  < 2e-16 ***
## country_codeLAO  0.496320   0.336623   1.474 0.140428    
## country_codeLBN  3.693919   0.336623  10.973  < 2e-16 ***
## country_codeLBR  0.086699   0.336623   0.258 0.796761    
## country_codeLBY  8.097859   0.336623  24.056  < 2e-16 ***
## country_codeLCA  2.702766   0.336623   8.029 1.19e-15 ***
## country_codeLIE  5.820922   0.336623  17.292  < 2e-16 ***
## country_codeLKA  0.511548   0.336623   1.520 0.128657    
## country_codeLSO  0.125517   0.336623   0.373 0.709258    
## country_codeLTU  4.099534   0.336623  12.178  < 2e-16 ***
## country_codeLUX 21.442792   0.336623  63.700  < 2e-16 ***
## country_codeLVA  3.781735   0.336623  11.234  < 2e-16 ***
## country_codeMAR  1.262459   0.336623   3.750 0.000178 ***
## country_codeMDA  3.478183   0.336623  10.333  < 2e-16 ***
## country_codeMDG -0.014814   0.336623  -0.044 0.964899    
## country_codeMDV  2.045187   0.336623   6.076 1.32e-09 ***
## country_codeMEX  3.665115   0.336623  10.888  < 2e-16 ***
## country_codeMHL  2.212284   0.342581   6.458 1.15e-10 ***
## country_codeMKD  4.168257   0.336623  12.383  < 2e-16 ***
## country_codeMLI  0.014816   0.342581   0.043 0.965505    
## country_codeMLT  5.665627   0.336623  16.831  < 2e-16 ***
## country_codeMMR  0.120711   0.336623   0.359 0.719912    
## country_codeMNE  3.038743   0.336623   9.027  < 2e-16 ***
## country_codeMNG  4.949275   0.336623  14.703  < 2e-16 ***
## country_codeMOZ  0.004480   0.336623   0.013 0.989381    
## country_codeMRT  0.489125   0.336623   1.453 0.146271    
## country_codeMUS  2.190414   0.336623   6.507 8.34e-11 ***
## country_codeMWI -0.050952   0.336623  -0.151 0.879695    
## country_codeMYS  5.870056   0.336623  17.438  < 2e-16 ***
## country_codeNAM  1.222492   0.339512   3.601 0.000320 ***
## country_codeNER -0.044620   0.336623  -0.133 0.894554    
## country_codeNGA  0.578143   0.336623   1.717 0.085948 .  
## country_codeNIC  0.607472   0.336623   1.805 0.071191 .  
## country_codeNLD  9.836416   0.336623  29.221  < 2e-16 ***
## country_codeNOR  7.595058   0.336623  22.563  < 2e-16 ***
## country_codeNPL  0.057174   0.336623   0.170 0.865137    
## country_codeNRU  7.255444   0.336623  21.554  < 2e-16 ***
## country_codeNZL  7.150138   0.336623  21.241  < 2e-16 ***
## country_codeOMN 12.516303   0.336623  37.182  < 2e-16 ***
## country_codePAK  0.625074   0.336623   1.857 0.063379 .  
## country_codePAN  1.945375   0.336623   5.779 7.92e-09 ***
## country_codePER  1.169289   0.336623   3.474 0.000517 ***
## country_codePHL  0.804042   0.336623   2.389 0.016948 *  
## country_codePLW 11.981469   0.342581  34.974  < 2e-16 ***
## country_codePNG  0.513941   0.336623   1.527 0.126879    
## country_codePOL  8.101931   0.336623  24.068  < 2e-16 ***
## country_codePRK  2.795238   0.336623   8.304  < 2e-16 ***
## country_codePRT  5.015961   0.336623  14.901  < 2e-16 ***
## country_codePRY  0.660641   0.336623   1.963 0.049748 *  
## country_codeQAT 38.249945   0.336623 113.628  < 2e-16 ***
## country_codeROU  4.400220   0.336623  13.072  < 2e-16 ***
## country_codeRUS 11.351798   0.336623  33.723  < 2e-16 ***
## country_codeRWA -0.042102   0.336623  -0.125 0.900471    
## country_codeSAU 13.660919   0.336623  40.582  < 2e-16 ***
## country_codeSDN  0.218179   0.336623   0.648 0.516921    
## country_codeSEN  0.359713   0.336623   1.069 0.285299    
## country_codeSGP  9.048889   0.336623  26.881  < 2e-16 ***
## country_codeSLB  0.474581   0.336623   1.410 0.158646    
## country_codeSLE -0.022998   0.336623  -0.068 0.945534    
## country_codeSLV  0.863518   0.336623   2.565 0.010337 *  
## country_codeSOM -0.055317   0.336623  -0.164 0.869477    
## country_codeSRB  6.431293   0.336623  19.105  < 2e-16 ***
## country_codeSSD -0.005595   0.336623  -0.017 0.986740    
## country_codeSTP  0.366061   0.336623   1.087 0.276884    
## country_codeSUR  3.853467   0.336623  11.447  < 2e-16 ***
## country_codeSVK  6.974218   0.336623  20.718  < 2e-16 ***
## country_codeSVN  7.200479   0.336623  21.390  < 2e-16 ***
## country_codeSWE  5.301153   0.336623  15.748  < 2e-16 ***
## country_codeSWZ  0.544586   0.336623   1.618 0.105765    
## country_codeSYC  4.148923   0.336623  12.325  < 2e-16 ***
## country_codeSYR  2.367683   0.336623   7.034 2.26e-12 ***
## country_codeTCD -0.032984   0.336623  -0.098 0.921948    
## country_codeTGO  0.162129   0.336623   0.482 0.630085    
## country_codeTHA  2.934701   0.336623   8.718  < 2e-16 ***
## country_codeTJK  0.507277   0.336623   1.507 0.131878    
## country_codeTKM 10.270291   0.336623  30.510  < 2e-16 ***
## country_codeTLS  0.189790   0.388699   0.488 0.625377    
## country_codeTON  1.033917   0.336623   3.071 0.002141 ** 
## country_codeTTO 11.873655   0.336623  35.273  < 2e-16 ***
## country_codeTUN  2.132285   0.336623   6.334 2.57e-10 ***
## country_codeTUR  3.554528   0.336623  10.559  < 2e-16 ***
## country_codeTUV  0.883579   0.336623   2.625 0.008693 ** 
## country_codeTZA  0.020116   0.336623   0.060 0.952351    
## country_codeUGA -0.036767   0.336623  -0.109 0.913030    
## country_codeUKR  6.588003   0.336623  19.571  < 2e-16 ***
## country_codeURY  1.651478   0.336623   4.906 9.56e-07 ***
## country_codeUSA 18.034505   0.336623  53.575  < 2e-16 ***
## country_codeUZB  4.327410   0.336623  12.855  < 2e-16 ***
## country_codeVCT  2.035908   0.336623   6.048 1.56e-09 ***
## country_codeVEN  5.219441   0.336623  15.505  < 2e-16 ***
## country_codeVNM  1.122892   0.336623   3.336 0.000856 ***
## country_codeVUT  0.369471   0.336623   1.098 0.272436    
## country_codeWSM  0.871810   0.336623   2.590 0.009626 ** 
## country_codeYEM  0.688349   0.336623   2.045 0.040915 *  
## country_codeZAF  7.197892   0.336623  21.383  < 2e-16 ***
## country_codeZMB  0.134405   0.336623   0.399 0.689705    
## country_codeZWE  0.932715   0.336623   2.771 0.005611 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.304 on 5513 degrees of freedom
## Multiple R-squared:  0.946,  Adjusted R-squared:  0.9441 
## F-statistic:   508 on 190 and 5513 DF,  p-value: < 2.2e-16
backward_model <- step(full_model,
                       direction = "backward")
## Start:  AIC=3214.49
## value ~ year + Region + country_code
## 
## 
## Step:  AIC=3214.49
## value ~ year + country_code
## 
##                 Df Sum of Sq    RSS     AIC
## - year           1         2   9371  3213.5
## <none>                         9369  3214.5
## - country_code 190    164053 173422 19480.6
## 
## Step:  AIC=3213.51
## value ~ country_code
## 
##                 Df Sum of Sq    RSS     AIC
## <none>                         9371  3213.5
## - country_code 190    164053 173424 19478.7
summary(backward_model)
## 
## Call:
## lm(formula = value ~ country_code, data = df_long)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -20.0867  -0.2911  -0.0096   0.2372  12.5872 
## 
## Coefficients:
##                  Estimate Std. Error t value Pr(>|t|)    
## (Intercept)      0.116895   0.238028   0.491 0.623377    
## country_codeAGO  0.783586   0.336623   2.328 0.019959 *  
## country_codeALB  1.133921   0.336623   3.369 0.000761 ***
## country_codeAND  6.664344   0.336623  19.798  < 2e-16 ***
## country_codeARE 24.939382   0.336623  74.087  < 2e-16 ***
## country_codeARG  3.617575   0.336623  10.747  < 2e-16 ***
## country_codeARM  1.702351   0.336623   5.057 4.39e-07 ***
## country_codeATG  5.122452   0.336623  15.217  < 2e-16 ***
## country_codeAUS 16.710132   0.336623  49.641  < 2e-16 ***
## country_codeAUT  7.874754   0.336623  23.393  < 2e-16 ***
## country_codeAZE  3.800264   0.336623  11.289  < 2e-16 ***
## country_codeBDI -0.081955   0.336623  -0.243 0.807656    
## country_codeBEL 10.016451   0.336623  29.756  < 2e-16 ***
## country_codeBEN  0.221996   0.336623   0.659 0.509616    
## country_codeBFA -0.001563   0.336623  -0.005 0.996295    
## country_codeBGD  0.152622   0.336623   0.453 0.650285    
## country_codeBGR  6.106784   0.336623  18.141  < 2e-16 ***
## country_codeBHR 22.365373   0.336623  66.440  < 2e-16 ***
## country_codeBHS  7.456861   0.336623  22.152  < 2e-16 ***
## country_codeBIH  4.376519   0.336623  13.001  < 2e-16 ***
## country_codeBLR  6.185064   0.336623  18.374  < 2e-16 ***
## country_codeBLZ  1.840766   0.336623   5.468 4.74e-08 ***
## country_codeBOL  1.295242   0.336623   3.848 0.000121 ***
## country_codeBRA  1.726393   0.336623   5.129 3.02e-07 ***
## country_codeBRB  5.045735   0.336623  14.989  < 2e-16 ***
## country_codeBRN 15.945040   0.336623  47.368  < 2e-16 ***
## country_codeBTN  0.478625   0.336623   1.422 0.155128    
## country_codeBWA  2.292493   0.336623   6.810 1.08e-11 ***
## country_codeCAF -0.066128   0.336623  -0.196 0.844268    
## country_codeCAN 15.804255   0.336623  46.949  < 2e-16 ***
## country_codeCHE  5.631761   0.336623  16.730  < 2e-16 ***
## country_codeCHL  3.494021   0.336623  10.380  < 2e-16 ***
## country_codeCHN  4.433169   0.336623  13.170  < 2e-16 ***
## country_codeCIV  0.212959   0.336623   0.633 0.526999    
## country_codeCMR  0.235201   0.336623   0.699 0.484764    
## country_codeCOD -0.071857   0.336623  -0.213 0.830973    
## country_codeCOG  1.041205   0.336623   3.093 0.001991 ** 
## country_codeCOL  1.395531   0.336623   4.146 3.44e-05 ***
## country_codeCOM  0.101415   0.336623   0.301 0.763219    
## country_codeCPV  0.621100   0.336623   1.845 0.065078 .  
## country_codeCRI  1.320382   0.336623   3.922 8.87e-05 ***
## country_codeCUB  2.281922   0.336623   6.779 1.34e-11 ***
## country_codeCYP  6.801556   0.336623  20.205  < 2e-16 ***
## country_codeCZE 11.187557   0.336623  33.235  < 2e-16 ***
## country_codeDEU  9.823997   0.336623  29.184  < 2e-16 ***
## country_codeDJI  0.400010   0.336623   1.188 0.234766    
## country_codeDMA  2.040031   0.336623   6.060 1.45e-09 ***
## country_codeDNK  9.220403   0.336623  27.391  < 2e-16 ***
## country_codeDOM  1.861382   0.336623   5.530 3.36e-08 ***
## country_codeDZA  2.904593   0.336623   8.629  < 2e-16 ***
## country_codeECU  1.947254   0.336623   5.785 7.67e-09 ***
## country_codeEGY  1.914364   0.336623   5.687 1.36e-08 ***
## country_codeERI  0.124065   0.342581   0.362 0.717256    
## country_codeESP  6.180530   0.336623  18.360  < 2e-16 ***
## country_codeEST 12.808536   0.336623  38.050  < 2e-16 ***
## country_codeETH -0.038262   0.336623  -0.114 0.909509    
## country_codeFIN 10.466566   0.336623  31.093  < 2e-16 ***
## country_codeFJI  1.161150   0.336623   3.449 0.000566 ***
## country_codeFRA  5.499527   0.336623  16.337  < 2e-16 ***
## country_codeFSM  1.174372   0.342581   3.428 0.000612 ***
## country_codeGAB  3.892033   0.336623  11.562  < 2e-16 ***
## country_codeGBR  8.044597   0.336623  23.898  < 2e-16 ***
## country_codeGEO  1.944825   0.336623   5.777 8.00e-09 ***
## country_codeGHA  0.265562   0.336623   0.789 0.430205    
## country_codeGIN  0.086134   0.336623   0.256 0.798056    
## country_codeGMB  0.105521   0.336623   0.313 0.753935    
## country_codeGNB  0.041546   0.336623   0.123 0.901778    
## country_codeGNQ  5.920810   0.336623  17.589  < 2e-16 ***
## country_codeGRC  7.663088   0.336623  22.765  < 2e-16 ***
## country_codeGRD  2.362781   0.336623   7.019 2.50e-12 ***
## country_codeGTM  0.681299   0.336623   2.024 0.043026 *  
## country_codeGUY  2.180433   0.336623   6.477 1.01e-10 ***
## country_codeHND  0.754675   0.336623   2.242 0.025007 *  
## country_codeHRV  4.059515   0.336623  12.060  < 2e-16 ***
## country_codeHTI  0.083657   0.336623   0.249 0.803742    
## country_codeHUN  5.114315   0.336623  15.193  < 2e-16 ***
## country_codeIDN  1.396401   0.336623   4.148 3.40e-05 ***
## country_codeIND  1.009405   0.336623   2.999 0.002724 ** 
## country_codeIRL  9.257220   0.336623  27.500  < 2e-16 ***
## country_codeIRN  5.941626   0.336623  17.651  < 2e-16 ***
## country_codeIRQ  3.735793   0.336623  11.098  < 2e-16 ***
## country_codeISL  6.829608   0.336623  20.289  < 2e-16 ***
## country_codeISR  8.289103   0.336623  24.624  < 2e-16 ***
## country_codeITA  6.818992   0.336623  20.257  < 2e-16 ***
## country_codeJAM  3.160994   0.336623   9.390  < 2e-16 ***
## country_codeJOR  2.823947   0.336623   8.389  < 2e-16 ***
## country_codeJPN  9.108324   0.336623  27.058  < 2e-16 ***
## country_codeKAZ 11.733833   0.336623  34.858  < 2e-16 ***
## country_codeKEN  0.153593   0.336623   0.456 0.648210    
## country_codeKGZ  1.514438   0.336623   4.499 6.97e-06 ***
## country_codeKHM  0.199980   0.336623   0.594 0.552486    
## country_codeKIR  0.386023   0.336623   1.147 0.251533    
## country_codeKNA  4.679554   0.336623  13.901  < 2e-16 ***
## country_codeKOR  9.807696   0.336623  29.136  < 2e-16 ***
## country_codeKWT 23.819590   0.345847  68.873  < 2e-16 ***
## country_codeLAO  0.496320   0.336623   1.474 0.140428    
## country_codeLBN  3.693919   0.336623  10.973  < 2e-16 ***
## country_codeLBR  0.086699   0.336623   0.258 0.796761    
## country_codeLBY  8.097859   0.336623  24.056  < 2e-16 ***
## country_codeLCA  2.702766   0.336623   8.029 1.19e-15 ***
## country_codeLIE  5.820922   0.336623  17.292  < 2e-16 ***
## country_codeLKA  0.511548   0.336623   1.520 0.128657    
## country_codeLSO  0.125517   0.336623   0.373 0.709258    
## country_codeLTU  4.099534   0.336623  12.178  < 2e-16 ***
## country_codeLUX 21.442792   0.336623  63.700  < 2e-16 ***
## country_codeLVA  3.781735   0.336623  11.234  < 2e-16 ***
## country_codeMAR  1.262459   0.336623   3.750 0.000178 ***
## country_codeMDA  3.478183   0.336623  10.333  < 2e-16 ***
## country_codeMDG -0.014814   0.336623  -0.044 0.964899    
## country_codeMDV  2.045187   0.336623   6.076 1.32e-09 ***
## country_codeMEX  3.665115   0.336623  10.888  < 2e-16 ***
## country_codeMHL  2.212284   0.342581   6.458 1.15e-10 ***
## country_codeMKD  4.168257   0.336623  12.383  < 2e-16 ***
## country_codeMLI  0.014816   0.342581   0.043 0.965505    
## country_codeMLT  5.665627   0.336623  16.831  < 2e-16 ***
## country_codeMMR  0.120711   0.336623   0.359 0.719912    
## country_codeMNE  3.038743   0.336623   9.027  < 2e-16 ***
## country_codeMNG  4.949275   0.336623  14.703  < 2e-16 ***
## country_codeMOZ  0.004480   0.336623   0.013 0.989381    
## country_codeMRT  0.489125   0.336623   1.453 0.146271    
## country_codeMUS  2.190414   0.336623   6.507 8.34e-11 ***
## country_codeMWI -0.050952   0.336623  -0.151 0.879695    
## country_codeMYS  5.870056   0.336623  17.438  < 2e-16 ***
## country_codeNAM  1.222492   0.339512   3.601 0.000320 ***
## country_codeNER -0.044620   0.336623  -0.133 0.894554    
## country_codeNGA  0.578143   0.336623   1.717 0.085948 .  
## country_codeNIC  0.607472   0.336623   1.805 0.071191 .  
## country_codeNLD  9.836416   0.336623  29.221  < 2e-16 ***
## country_codeNOR  7.595058   0.336623  22.563  < 2e-16 ***
## country_codeNPL  0.057174   0.336623   0.170 0.865137    
## country_codeNRU  7.255444   0.336623  21.554  < 2e-16 ***
## country_codeNZL  7.150138   0.336623  21.241  < 2e-16 ***
## country_codeOMN 12.516303   0.336623  37.182  < 2e-16 ***
## country_codePAK  0.625074   0.336623   1.857 0.063379 .  
## country_codePAN  1.945375   0.336623   5.779 7.92e-09 ***
## country_codePER  1.169289   0.336623   3.474 0.000517 ***
## country_codePHL  0.804042   0.336623   2.389 0.016948 *  
## country_codePLW 11.981469   0.342581  34.974  < 2e-16 ***
## country_codePNG  0.513941   0.336623   1.527 0.126879    
## country_codePOL  8.101931   0.336623  24.068  < 2e-16 ***
## country_codePRK  2.795238   0.336623   8.304  < 2e-16 ***
## country_codePRT  5.015961   0.336623  14.901  < 2e-16 ***
## country_codePRY  0.660641   0.336623   1.963 0.049748 *  
## country_codeQAT 38.249945   0.336623 113.628  < 2e-16 ***
## country_codeROU  4.400220   0.336623  13.072  < 2e-16 ***
## country_codeRUS 11.351798   0.336623  33.723  < 2e-16 ***
## country_codeRWA -0.042102   0.336623  -0.125 0.900471    
## country_codeSAU 13.660919   0.336623  40.582  < 2e-16 ***
## country_codeSDN  0.218179   0.336623   0.648 0.516921    
## country_codeSEN  0.359713   0.336623   1.069 0.285299    
## country_codeSGP  9.048889   0.336623  26.881  < 2e-16 ***
## country_codeSLB  0.474581   0.336623   1.410 0.158646    
## country_codeSLE -0.022998   0.336623  -0.068 0.945534    
## country_codeSLV  0.863518   0.336623   2.565 0.010337 *  
## country_codeSOM -0.055317   0.336623  -0.164 0.869477    
## country_codeSRB  6.431293   0.336623  19.105  < 2e-16 ***
## country_codeSSD -0.005595   0.336623  -0.017 0.986740    
## country_codeSTP  0.366061   0.336623   1.087 0.276884    
## country_codeSUR  3.853467   0.336623  11.447  < 2e-16 ***
## country_codeSVK  6.974218   0.336623  20.718  < 2e-16 ***
## country_codeSVN  7.200479   0.336623  21.390  < 2e-16 ***
## country_codeSWE  5.301153   0.336623  15.748  < 2e-16 ***
## country_codeSWZ  0.544586   0.336623   1.618 0.105765    
## country_codeSYC  4.148923   0.336623  12.325  < 2e-16 ***
## country_codeSYR  2.367683   0.336623   7.034 2.26e-12 ***
## country_codeTCD -0.032984   0.336623  -0.098 0.921948    
## country_codeTGO  0.162129   0.336623   0.482 0.630085    
## country_codeTHA  2.934701   0.336623   8.718  < 2e-16 ***
## country_codeTJK  0.507277   0.336623   1.507 0.131878    
## country_codeTKM 10.270291   0.336623  30.510  < 2e-16 ***
## country_codeTLS  0.189790   0.388699   0.488 0.625377    
## country_codeTON  1.033917   0.336623   3.071 0.002141 ** 
## country_codeTTO 11.873655   0.336623  35.273  < 2e-16 ***
## country_codeTUN  2.132285   0.336623   6.334 2.57e-10 ***
## country_codeTUR  3.554528   0.336623  10.559  < 2e-16 ***
## country_codeTUV  0.883579   0.336623   2.625 0.008693 ** 
## country_codeTZA  0.020116   0.336623   0.060 0.952351    
## country_codeUGA -0.036767   0.336623  -0.109 0.913030    
## country_codeUKR  6.588003   0.336623  19.571  < 2e-16 ***
## country_codeURY  1.651478   0.336623   4.906 9.56e-07 ***
## country_codeUSA 18.034505   0.336623  53.575  < 2e-16 ***
## country_codeUZB  4.327410   0.336623  12.855  < 2e-16 ***
## country_codeVCT  2.035908   0.336623   6.048 1.56e-09 ***
## country_codeVEN  5.219441   0.336623  15.505  < 2e-16 ***
## country_codeVNM  1.122892   0.336623   3.336 0.000856 ***
## country_codeVUT  0.369471   0.336623   1.098 0.272436    
## country_codeWSM  0.871810   0.336623   2.590 0.009626 ** 
## country_codeYEM  0.688349   0.336623   2.045 0.040915 *  
## country_codeZAF  7.197892   0.336623  21.383  < 2e-16 ***
## country_codeZMB  0.134405   0.336623   0.399 0.689705    
## country_codeZWE  0.932715   0.336623   2.771 0.005611 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.304 on 5513 degrees of freedom
## Multiple R-squared:  0.946,  Adjusted R-squared:  0.9441 
## F-statistic:   508 on 190 and 5513 DF,  p-value: < 2.2e-16
step_model <- stepAIC(full_model, direction = "both")
## Start:  AIC=3214.49
## value ~ year + Region + country_code
## 
## 
## Step:  AIC=3214.49
## value ~ year + country_code
## 
##                 Df Sum of Sq    RSS     AIC
## - year           1         2   9371  3213.5
## <none>                         9369  3214.5
## - country_code 190    164053 173422 19480.6
## 
## Step:  AIC=3213.51
## value ~ country_code
## 
##                 Df Sum of Sq    RSS     AIC
## <none>                         9371  3213.5
## + year           1         2   9369  3214.5
## - country_code 190    164053 173424 19478.7
summary(step_model)
## 
## Call:
## lm(formula = value ~ country_code, data = df_long)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -20.0867  -0.2911  -0.0096   0.2372  12.5872 
## 
## Coefficients:
##                  Estimate Std. Error t value Pr(>|t|)    
## (Intercept)      0.116895   0.238028   0.491 0.623377    
## country_codeAGO  0.783586   0.336623   2.328 0.019959 *  
## country_codeALB  1.133921   0.336623   3.369 0.000761 ***
## country_codeAND  6.664344   0.336623  19.798  < 2e-16 ***
## country_codeARE 24.939382   0.336623  74.087  < 2e-16 ***
## country_codeARG  3.617575   0.336623  10.747  < 2e-16 ***
## country_codeARM  1.702351   0.336623   5.057 4.39e-07 ***
## country_codeATG  5.122452   0.336623  15.217  < 2e-16 ***
## country_codeAUS 16.710132   0.336623  49.641  < 2e-16 ***
## country_codeAUT  7.874754   0.336623  23.393  < 2e-16 ***
## country_codeAZE  3.800264   0.336623  11.289  < 2e-16 ***
## country_codeBDI -0.081955   0.336623  -0.243 0.807656    
## country_codeBEL 10.016451   0.336623  29.756  < 2e-16 ***
## country_codeBEN  0.221996   0.336623   0.659 0.509616    
## country_codeBFA -0.001563   0.336623  -0.005 0.996295    
## country_codeBGD  0.152622   0.336623   0.453 0.650285    
## country_codeBGR  6.106784   0.336623  18.141  < 2e-16 ***
## country_codeBHR 22.365373   0.336623  66.440  < 2e-16 ***
## country_codeBHS  7.456861   0.336623  22.152  < 2e-16 ***
## country_codeBIH  4.376519   0.336623  13.001  < 2e-16 ***
## country_codeBLR  6.185064   0.336623  18.374  < 2e-16 ***
## country_codeBLZ  1.840766   0.336623   5.468 4.74e-08 ***
## country_codeBOL  1.295242   0.336623   3.848 0.000121 ***
## country_codeBRA  1.726393   0.336623   5.129 3.02e-07 ***
## country_codeBRB  5.045735   0.336623  14.989  < 2e-16 ***
## country_codeBRN 15.945040   0.336623  47.368  < 2e-16 ***
## country_codeBTN  0.478625   0.336623   1.422 0.155128    
## country_codeBWA  2.292493   0.336623   6.810 1.08e-11 ***
## country_codeCAF -0.066128   0.336623  -0.196 0.844268    
## country_codeCAN 15.804255   0.336623  46.949  < 2e-16 ***
## country_codeCHE  5.631761   0.336623  16.730  < 2e-16 ***
## country_codeCHL  3.494021   0.336623  10.380  < 2e-16 ***
## country_codeCHN  4.433169   0.336623  13.170  < 2e-16 ***
## country_codeCIV  0.212959   0.336623   0.633 0.526999    
## country_codeCMR  0.235201   0.336623   0.699 0.484764    
## country_codeCOD -0.071857   0.336623  -0.213 0.830973    
## country_codeCOG  1.041205   0.336623   3.093 0.001991 ** 
## country_codeCOL  1.395531   0.336623   4.146 3.44e-05 ***
## country_codeCOM  0.101415   0.336623   0.301 0.763219    
## country_codeCPV  0.621100   0.336623   1.845 0.065078 .  
## country_codeCRI  1.320382   0.336623   3.922 8.87e-05 ***
## country_codeCUB  2.281922   0.336623   6.779 1.34e-11 ***
## country_codeCYP  6.801556   0.336623  20.205  < 2e-16 ***
## country_codeCZE 11.187557   0.336623  33.235  < 2e-16 ***
## country_codeDEU  9.823997   0.336623  29.184  < 2e-16 ***
## country_codeDJI  0.400010   0.336623   1.188 0.234766    
## country_codeDMA  2.040031   0.336623   6.060 1.45e-09 ***
## country_codeDNK  9.220403   0.336623  27.391  < 2e-16 ***
## country_codeDOM  1.861382   0.336623   5.530 3.36e-08 ***
## country_codeDZA  2.904593   0.336623   8.629  < 2e-16 ***
## country_codeECU  1.947254   0.336623   5.785 7.67e-09 ***
## country_codeEGY  1.914364   0.336623   5.687 1.36e-08 ***
## country_codeERI  0.124065   0.342581   0.362 0.717256    
## country_codeESP  6.180530   0.336623  18.360  < 2e-16 ***
## country_codeEST 12.808536   0.336623  38.050  < 2e-16 ***
## country_codeETH -0.038262   0.336623  -0.114 0.909509    
## country_codeFIN 10.466566   0.336623  31.093  < 2e-16 ***
## country_codeFJI  1.161150   0.336623   3.449 0.000566 ***
## country_codeFRA  5.499527   0.336623  16.337  < 2e-16 ***
## country_codeFSM  1.174372   0.342581   3.428 0.000612 ***
## country_codeGAB  3.892033   0.336623  11.562  < 2e-16 ***
## country_codeGBR  8.044597   0.336623  23.898  < 2e-16 ***
## country_codeGEO  1.944825   0.336623   5.777 8.00e-09 ***
## country_codeGHA  0.265562   0.336623   0.789 0.430205    
## country_codeGIN  0.086134   0.336623   0.256 0.798056    
## country_codeGMB  0.105521   0.336623   0.313 0.753935    
## country_codeGNB  0.041546   0.336623   0.123 0.901778    
## country_codeGNQ  5.920810   0.336623  17.589  < 2e-16 ***
## country_codeGRC  7.663088   0.336623  22.765  < 2e-16 ***
## country_codeGRD  2.362781   0.336623   7.019 2.50e-12 ***
## country_codeGTM  0.681299   0.336623   2.024 0.043026 *  
## country_codeGUY  2.180433   0.336623   6.477 1.01e-10 ***
## country_codeHND  0.754675   0.336623   2.242 0.025007 *  
## country_codeHRV  4.059515   0.336623  12.060  < 2e-16 ***
## country_codeHTI  0.083657   0.336623   0.249 0.803742    
## country_codeHUN  5.114315   0.336623  15.193  < 2e-16 ***
## country_codeIDN  1.396401   0.336623   4.148 3.40e-05 ***
## country_codeIND  1.009405   0.336623   2.999 0.002724 ** 
## country_codeIRL  9.257220   0.336623  27.500  < 2e-16 ***
## country_codeIRN  5.941626   0.336623  17.651  < 2e-16 ***
## country_codeIRQ  3.735793   0.336623  11.098  < 2e-16 ***
## country_codeISL  6.829608   0.336623  20.289  < 2e-16 ***
## country_codeISR  8.289103   0.336623  24.624  < 2e-16 ***
## country_codeITA  6.818992   0.336623  20.257  < 2e-16 ***
## country_codeJAM  3.160994   0.336623   9.390  < 2e-16 ***
## country_codeJOR  2.823947   0.336623   8.389  < 2e-16 ***
## country_codeJPN  9.108324   0.336623  27.058  < 2e-16 ***
## country_codeKAZ 11.733833   0.336623  34.858  < 2e-16 ***
## country_codeKEN  0.153593   0.336623   0.456 0.648210    
## country_codeKGZ  1.514438   0.336623   4.499 6.97e-06 ***
## country_codeKHM  0.199980   0.336623   0.594 0.552486    
## country_codeKIR  0.386023   0.336623   1.147 0.251533    
## country_codeKNA  4.679554   0.336623  13.901  < 2e-16 ***
## country_codeKOR  9.807696   0.336623  29.136  < 2e-16 ***
## country_codeKWT 23.819590   0.345847  68.873  < 2e-16 ***
## country_codeLAO  0.496320   0.336623   1.474 0.140428    
## country_codeLBN  3.693919   0.336623  10.973  < 2e-16 ***
## country_codeLBR  0.086699   0.336623   0.258 0.796761    
## country_codeLBY  8.097859   0.336623  24.056  < 2e-16 ***
## country_codeLCA  2.702766   0.336623   8.029 1.19e-15 ***
## country_codeLIE  5.820922   0.336623  17.292  < 2e-16 ***
## country_codeLKA  0.511548   0.336623   1.520 0.128657    
## country_codeLSO  0.125517   0.336623   0.373 0.709258    
## country_codeLTU  4.099534   0.336623  12.178  < 2e-16 ***
## country_codeLUX 21.442792   0.336623  63.700  < 2e-16 ***
## country_codeLVA  3.781735   0.336623  11.234  < 2e-16 ***
## country_codeMAR  1.262459   0.336623   3.750 0.000178 ***
## country_codeMDA  3.478183   0.336623  10.333  < 2e-16 ***
## country_codeMDG -0.014814   0.336623  -0.044 0.964899    
## country_codeMDV  2.045187   0.336623   6.076 1.32e-09 ***
## country_codeMEX  3.665115   0.336623  10.888  < 2e-16 ***
## country_codeMHL  2.212284   0.342581   6.458 1.15e-10 ***
## country_codeMKD  4.168257   0.336623  12.383  < 2e-16 ***
## country_codeMLI  0.014816   0.342581   0.043 0.965505    
## country_codeMLT  5.665627   0.336623  16.831  < 2e-16 ***
## country_codeMMR  0.120711   0.336623   0.359 0.719912    
## country_codeMNE  3.038743   0.336623   9.027  < 2e-16 ***
## country_codeMNG  4.949275   0.336623  14.703  < 2e-16 ***
## country_codeMOZ  0.004480   0.336623   0.013 0.989381    
## country_codeMRT  0.489125   0.336623   1.453 0.146271    
## country_codeMUS  2.190414   0.336623   6.507 8.34e-11 ***
## country_codeMWI -0.050952   0.336623  -0.151 0.879695    
## country_codeMYS  5.870056   0.336623  17.438  < 2e-16 ***
## country_codeNAM  1.222492   0.339512   3.601 0.000320 ***
## country_codeNER -0.044620   0.336623  -0.133 0.894554    
## country_codeNGA  0.578143   0.336623   1.717 0.085948 .  
## country_codeNIC  0.607472   0.336623   1.805 0.071191 .  
## country_codeNLD  9.836416   0.336623  29.221  < 2e-16 ***
## country_codeNOR  7.595058   0.336623  22.563  < 2e-16 ***
## country_codeNPL  0.057174   0.336623   0.170 0.865137    
## country_codeNRU  7.255444   0.336623  21.554  < 2e-16 ***
## country_codeNZL  7.150138   0.336623  21.241  < 2e-16 ***
## country_codeOMN 12.516303   0.336623  37.182  < 2e-16 ***
## country_codePAK  0.625074   0.336623   1.857 0.063379 .  
## country_codePAN  1.945375   0.336623   5.779 7.92e-09 ***
## country_codePER  1.169289   0.336623   3.474 0.000517 ***
## country_codePHL  0.804042   0.336623   2.389 0.016948 *  
## country_codePLW 11.981469   0.342581  34.974  < 2e-16 ***
## country_codePNG  0.513941   0.336623   1.527 0.126879    
## country_codePOL  8.101931   0.336623  24.068  < 2e-16 ***
## country_codePRK  2.795238   0.336623   8.304  < 2e-16 ***
## country_codePRT  5.015961   0.336623  14.901  < 2e-16 ***
## country_codePRY  0.660641   0.336623   1.963 0.049748 *  
## country_codeQAT 38.249945   0.336623 113.628  < 2e-16 ***
## country_codeROU  4.400220   0.336623  13.072  < 2e-16 ***
## country_codeRUS 11.351798   0.336623  33.723  < 2e-16 ***
## country_codeRWA -0.042102   0.336623  -0.125 0.900471    
## country_codeSAU 13.660919   0.336623  40.582  < 2e-16 ***
## country_codeSDN  0.218179   0.336623   0.648 0.516921    
## country_codeSEN  0.359713   0.336623   1.069 0.285299    
## country_codeSGP  9.048889   0.336623  26.881  < 2e-16 ***
## country_codeSLB  0.474581   0.336623   1.410 0.158646    
## country_codeSLE -0.022998   0.336623  -0.068 0.945534    
## country_codeSLV  0.863518   0.336623   2.565 0.010337 *  
## country_codeSOM -0.055317   0.336623  -0.164 0.869477    
## country_codeSRB  6.431293   0.336623  19.105  < 2e-16 ***
## country_codeSSD -0.005595   0.336623  -0.017 0.986740    
## country_codeSTP  0.366061   0.336623   1.087 0.276884    
## country_codeSUR  3.853467   0.336623  11.447  < 2e-16 ***
## country_codeSVK  6.974218   0.336623  20.718  < 2e-16 ***
## country_codeSVN  7.200479   0.336623  21.390  < 2e-16 ***
## country_codeSWE  5.301153   0.336623  15.748  < 2e-16 ***
## country_codeSWZ  0.544586   0.336623   1.618 0.105765    
## country_codeSYC  4.148923   0.336623  12.325  < 2e-16 ***
## country_codeSYR  2.367683   0.336623   7.034 2.26e-12 ***
## country_codeTCD -0.032984   0.336623  -0.098 0.921948    
## country_codeTGO  0.162129   0.336623   0.482 0.630085    
## country_codeTHA  2.934701   0.336623   8.718  < 2e-16 ***
## country_codeTJK  0.507277   0.336623   1.507 0.131878    
## country_codeTKM 10.270291   0.336623  30.510  < 2e-16 ***
## country_codeTLS  0.189790   0.388699   0.488 0.625377    
## country_codeTON  1.033917   0.336623   3.071 0.002141 ** 
## country_codeTTO 11.873655   0.336623  35.273  < 2e-16 ***
## country_codeTUN  2.132285   0.336623   6.334 2.57e-10 ***
## country_codeTUR  3.554528   0.336623  10.559  < 2e-16 ***
## country_codeTUV  0.883579   0.336623   2.625 0.008693 ** 
## country_codeTZA  0.020116   0.336623   0.060 0.952351    
## country_codeUGA -0.036767   0.336623  -0.109 0.913030    
## country_codeUKR  6.588003   0.336623  19.571  < 2e-16 ***
## country_codeURY  1.651478   0.336623   4.906 9.56e-07 ***
## country_codeUSA 18.034505   0.336623  53.575  < 2e-16 ***
## country_codeUZB  4.327410   0.336623  12.855  < 2e-16 ***
## country_codeVCT  2.035908   0.336623   6.048 1.56e-09 ***
## country_codeVEN  5.219441   0.336623  15.505  < 2e-16 ***
## country_codeVNM  1.122892   0.336623   3.336 0.000856 ***
## country_codeVUT  0.369471   0.336623   1.098 0.272436    
## country_codeWSM  0.871810   0.336623   2.590 0.009626 ** 
## country_codeYEM  0.688349   0.336623   2.045 0.040915 *  
## country_codeZAF  7.197892   0.336623  21.383  < 2e-16 ***
## country_codeZMB  0.134405   0.336623   0.399 0.689705    
## country_codeZWE  0.932715   0.336623   2.771 0.005611 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.304 on 5513 degrees of freedom
## Multiple R-squared:  0.946,  Adjusted R-squared:  0.9441 
## F-statistic:   508 on 190 and 5513 DF,  p-value: < 2.2e-16
AIC(full_model, forward_model, backward_model, step_model)
##                 df      AIC
## full_model     193 19403.74
## forward_model  192 19402.76
## backward_model 192 19402.76
## step_model     192 19402.76
best_model <- step_model

par(mfrow = c(2,2))
plot(best_model)