#BASE1: list of freedom indices

link = "https://en.wikipedia.org/wiki/List_of_freedom_indices"
path = "/html/body/div[3]/div[3]/div[5]/div[1]/table[2]"
library(htmltab)
dataWS = htmltab(link, path)
head(dataWS)
##                 Country Freedom in the World 2021
## 2          Afghanistan                  not free
## 3              Albania               partly free
## 4              Algeria                  not free
## 5              Andorra                      free
## 6               Angola                  not free
## 7  Antigua and Barbuda                      free
##   2021 Index of Economic Freedom 2021 Press Freedom Index 2020 Democracy Index
## 2                  mostly unfree      difficult situation authoritarian regime
## 3                moderately free      noticeable problems     flawed democracy
## 4                      repressed      difficult situation authoritarian regime
## 5                            n/a   satisfactory situation                  n/a
## 6                  mostly unfree      noticeable problems authoritarian regime
## 7                            n/a   satisfactory situation                  n/a
dataWS$`Freedom in the World 2021` =factor(dataWS$`Freedom in the World 2021`,
                   levels=c("not free","partly free","free"), 
                   ordered = T)
dataWS$`2021 Index of Economic Freedom`=as.factor(dataWS$`2021 Index of Economic Freedom`)
dataWS$`2021 Press Freedom Index`=as.factor(dataWS$`2021 Press Freedom Index`)
dataWS$`2020 Democracy Index`=as.factor(dataWS$`2020 Democracy Index`)

dataWS[dataWS == "n/a"] <- NA
na.omit(dataWS)
##                                 Country Freedom in the World 2021
## 2                          Afghanistan                  not free
## 3                              Albania               partly free
## 4                              Algeria                  not free
## 6                               Angola                  not free
## 8                            Argentina                      free
## 9                              Armenia               partly free
## 10                           Australia                      free
## 11                             Austria                      free
## 12                          Azerbaijan                  not free
## 14                             Bahrain                  not free
## 15                          Bangladesh               partly free
## 17                             Belarus                  not free
## 18                             Belgium                      free
## 20                               Benin               partly free
## 21                              Bhutan               partly free
## 22                             Bolivia               partly free
## 23              Bosnia and Herzegovina               partly free
## 24                            Botswana                      free
## 25                              Brazil                      free
## 27                            Bulgaria                      free
## 28                        Burkina Faso               partly free
## 29                               Burma                  not free
## 30                             Burundi                  not free
## 31                            Cambodia                  not free
## 32                            Cameroon                  not free
## 33                              Canada                      free
## 34                          Cape Verde                      free
## 35            Central African Republic                  not free
## 36                                Chad                  not free
## 37                               Chile                      free
## 38                               China                  not free
## 39                            Colombia               partly free
## 40                             Comoros               partly free
## 41                          Costa Rica                      free
## 42   Congo, Democratic Republic of the                  not free
## 43              Congo, Republic of the                  not free
## 44                             Croatia                      free
## 45                                Cuba                  not free
## 46                              Cyprus                      free
## 47                      Czech Republic                      free
## 48                             Denmark                      free
## 49                            Djibouti                  not free
## 51                  Dominican Republic               partly free
## 52                          East Timor                      free
## 53                             Ecuador               partly free
## 54                               Egypt                  not free
## 55                         El Salvador               partly free
## 56                   Equatorial Guinea                  not free
## 57                             Eritrea                  not free
## 58                             Estonia                      free
## 59                            Eswatini                  not free
## 60                            Ethiopia                  not free
## 61                                Fiji               partly free
## 62                             Finland                      free
## 63                              France                      free
## 64                               Gabon                  not free
## 65                              Gambia               partly free
## 66                             Georgia               partly free
## 67                             Germany                      free
## 68                               Ghana                      free
## 69                              Greece                      free
## 71                           Guatemala               partly free
## 72                              Guinea               partly free
## 73                       Guinea-Bissau               partly free
## 74                              Guyana                      free
## 75                               Haiti               partly free
## 76                            Honduras               partly free
## 78                             Hungary               partly free
## 79                             Iceland                      free
## 80                               India               partly free
## 81                           Indonesia               partly free
## 82                                Iran                  not free
## 84                             Ireland                      free
## 85                              Israel                      free
## 86                               Italy                      free
## 87                         Ivory Coast               partly free
## 88                             Jamaica                      free
## 89                               Japan                      free
## 90                              Jordan                  not free
## 91                          Kazakhstan                  not free
## 92                               Kenya               partly free
## 94                        Korea, North                  not free
## 95                        Korea, South                      free
## 97                              Kuwait               partly free
## 98                          Kyrgyzstan                  not free
## 99                                Laos                  not free
## 100                             Latvia                      free
## 101                            Lebanon               partly free
## 102                            Lesotho               partly free
## 103                            Liberia               partly free
## 106                          Lithuania                      free
## 107                         Luxembourg                      free
## 108                         Madagascar               partly free
## 109                             Malawi               partly free
## 110                           Malaysia               partly free
## 112                               Mali                  not free
## 113                              Malta                      free
## 115                         Mauritania               partly free
## 116                          Mauritius                      free
## 117                             Mexico               partly free
## 119                            Moldova               partly free
## 121                           Mongolia                      free
## 122                         Montenegro               partly free
## 123                            Morocco               partly free
## 124                         Mozambique               partly free
## 125                            Namibia                      free
## 127                            Nepal               partly free
## 128                        Netherlands                      free
## 129                        New Zealand                      free
## 130                          Nicaragua                  not free
## 131                              Niger               partly free
## 132                            Nigeria               partly free
## 133                    North Macedonia               partly free
## 134                             Norway                      free
## 135                               Oman                  not free
## 136                           Pakistan               partly free
## 139                             Panama                      free
## 140                   Papua New Guinea               partly free
## 141                           Paraguay               partly free
## 142                               Peru               partly free
## 143                        Philippines               partly free
## 144                             Poland                      free
## 145                           Portugal                      free
## 146                              Qatar                  not free
## 147                            Romania                      free
## 148                             Russia                  not free
## 149                             Rwanda                  not free
## 156                       Saudi Arabia                  not free
## 157                            Senegal               partly free
## 158                             Serbia               partly free
## 160                       Sierra Leone               partly free
## 161                          Singapore               partly free
## 162                           Slovakia                      free
## 163                           Slovenia                      free
## 166                       South Africa                      free
## 168                              Spain                      free
## 169                          Sri Lanka               partly free
## 170                              Sudan                  not free
## 171                           Suriname                      free
## 172                             Sweden                      free
## 173                       Switzerland                      free
## 175                             Taiwan                      free
## 176                         Tajikistan                  not free
## 177                           Tanzania               partly free
## 178                           Thailand                  not free
## 179                               Togo               partly free
## 181                Trinidad and Tobago                      free
## 182                            Tunisia                      free
## 183                             Turkey                  not free
## 184                       Turkmenistan                  not free
## 186                             Uganda                  not free
## 187                            Ukraine               partly free
## 188               United Arab Emirates                  not free
## 189                     United Kingdom                      free
## 190                      United States                      free
## 191                            Uruguay                      free
## 192                         Uzbekistan                  not free
## 194                          Venezuela                  not free
## 195                            Vietnam                  not free
## 197                             Zambia               partly free
## 198                           Zimbabwe                  not free
##     2021 Index of Economic Freedom 2021 Press Freedom Index
## 2                    mostly unfree      difficult situation
## 3                  moderately free      noticeable problems
## 4                        repressed      difficult situation
## 6                    mostly unfree      noticeable problems
## 8                    mostly unfree      noticeable problems
## 9                      mostly free      noticeable problems
## 10                            free   satisfactory situation
## 11                     mostly free   satisfactory situation
## 12                     mostly free   very serious situation
## 14                 moderately free   very serious situation
## 15                   mostly unfree      difficult situation
## 17                 moderately free      difficult situation
## 18                     mostly free           good situation
## 20                   mostly unfree      difficult situation
## 21                   mostly unfree      noticeable problems
## 22                       repressed      difficult situation
## 23                 moderately free      noticeable problems
## 24                 moderately free   satisfactory situation
## 25                   mostly unfree      difficult situation
## 27                     mostly free      difficult situation
## 28                   mostly unfree   satisfactory situation
## 29                   mostly unfree      difficult situation
## 30                       repressed      difficult situation
## 31                   mostly unfree      difficult situation
## 32                   mostly unfree      difficult situation
## 33                     mostly free   satisfactory situation
## 34                 moderately free   satisfactory situation
## 35                       repressed      difficult situation
## 36                   mostly unfree      difficult situation
## 37                     mostly free      noticeable problems
## 38                   mostly unfree   very serious situation
## 39                 moderately free      difficult situation
## 40                   mostly unfree      noticeable problems
## 41                 moderately free           good situation
## 42                       repressed      difficult situation
## 43                   mostly unfree      difficult situation
## 44                 moderately free      noticeable problems
## 45                       repressed   very serious situation
## 46                     mostly free   satisfactory situation
## 47                     mostly free   satisfactory situation
## 48                     mostly free           good situation
## 49                   mostly unfree   very serious situation
## 51                 moderately free      noticeable problems
## 52                       repressed      noticeable problems
## 53                   mostly unfree      noticeable problems
## 54                   mostly unfree   very serious situation
## 55                 moderately free      noticeable problems
## 56                       repressed   very serious situation
## 57                       repressed   very serious situation
## 58                     mostly free   satisfactory situation
## 59                   mostly unfree      difficult situation
## 60                   mostly unfree      noticeable problems
## 61                 moderately free      noticeable problems
## 62                     mostly free           good situation
## 63                 moderately free   satisfactory situation
## 64                   mostly unfree      difficult situation
## 65                   mostly unfree      noticeable problems
## 66                     mostly free      noticeable problems
## 67                     mostly free   satisfactory situation
## 68                   mostly unfree   satisfactory situation
## 69                 moderately free      noticeable problems
## 71                 moderately free      difficult situation
## 72                   mostly unfree      difficult situation
## 73                   mostly unfree      noticeable problems
## 74                   mostly unfree      noticeable problems
## 75                   mostly unfree      noticeable problems
## 76                   mostly unfree      difficult situation
## 78                 moderately free      noticeable problems
## 79                     mostly free   satisfactory situation
## 80                   mostly unfree      difficult situation
## 81                 moderately free      difficult situation
## 82                       repressed   very serious situation
## 84                            free           good situation
## 85                     mostly free      noticeable problems
## 86                 moderately free   satisfactory situation
## 87                 moderately free      noticeable problems
## 88                 moderately free           good situation
## 89                     mostly free      noticeable problems
## 90                 moderately free      difficult situation
## 91                     mostly free      difficult situation
## 92                   mostly unfree      noticeable problems
## 94                       repressed   very serious situation
## 95                     mostly free           good situation
## 97                 moderately free      noticeable problems
## 98                 moderately free      noticeable problems
## 99                   mostly unfree   very serious situation
## 100                    mostly free   satisfactory situation
## 101                  mostly unfree      noticeable problems
## 102                  mostly unfree      noticeable problems
## 103                      repressed      noticeable problems
## 106                    mostly free   satisfactory situation
## 107                    mostly free   satisfactory situation
## 108                  mostly unfree      noticeable problems
## 109                  mostly unfree      noticeable problems
## 110                    mostly free      difficult situation
## 112                  mostly unfree      noticeable problems
## 113                    mostly free      noticeable problems
## 115                  mostly unfree      noticeable problems
## 116                    mostly free      noticeable problems
## 117                moderately free      difficult situation
## 119                moderately free      noticeable problems
## 121                moderately free      noticeable problems
## 122                moderately free      noticeable problems
## 123                moderately free      difficult situation
## 124                  mostly unfree      difficult situation
## 125                moderately free   satisfactory situation
## 127                  mostly unfree      noticeable problems
## 128                    mostly free           good situation
## 129                           free           good situation
## 130                  mostly unfree      difficult situation
## 131                  mostly unfree      noticeable problems
## 132                  mostly unfree      difficult situation
## 133                moderately free      noticeable problems
## 134                    mostly free           good situation
## 135                moderately free      difficult situation
## 136                  mostly unfree      difficult situation
## 139                moderately free      noticeable problems
## 140                  mostly unfree   satisfactory situation
## 141                moderately free      noticeable problems
## 142                moderately free      noticeable problems
## 143                moderately free      difficult situation
## 144                moderately free      noticeable problems
## 145                moderately free           good situation
## 146                    mostly free      difficult situation
## 147                moderately free   satisfactory situation
## 148                moderately free      difficult situation
## 149                moderately free      difficult situation
## 156                moderately free   very serious situation
## 157                  mostly unfree      noticeable problems
## 158                moderately free      noticeable problems
## 160                  mostly unfree      noticeable problems
## 161                           free   very serious situation
## 162                moderately free   satisfactory situation
## 163                moderately free   satisfactory situation
## 166                  mostly unfree   satisfactory situation
## 168                moderately free   satisfactory situation
## 169                  mostly unfree      difficult situation
## 170                      repressed      difficult situation
## 171                      repressed   satisfactory situation
## 172                    mostly free           good situation
## 173                           free           good situation
## 175                    mostly free   satisfactory situation
## 176                  mostly unfree   very serious situation
## 177                moderately free      difficult situation
## 178                moderately free      difficult situation
## 179                  mostly unfree      noticeable problems
## 181                  mostly unfree   satisfactory situation
## 182                  mostly unfree      noticeable problems
## 183                moderately free      difficult situation
## 184                      repressed   very serious situation
## 186                  mostly unfree      difficult situation
## 187                  mostly unfree      noticeable problems
## 188                    mostly free      difficult situation
## 189                    mostly free   satisfactory situation
## 190                    mostly free   satisfactory situation
## 191                moderately free   satisfactory situation
## 192                  mostly unfree      difficult situation
## 194                      repressed      difficult situation
## 195                moderately free   very serious situation
## 197                  mostly unfree      difficult situation
## 198                      repressed      difficult situation
##     2020 Democracy Index
## 2   authoritarian regime
## 3       flawed democracy
## 4   authoritarian regime
## 6   authoritarian regime
## 8       flawed democracy
## 9          hybrid regime
## 10        full democracy
## 11        full democracy
## 12  authoritarian regime
## 14  authoritarian regime
## 15         hybrid regime
## 17  authoritarian regime
## 18      flawed democracy
## 20         hybrid regime
## 21         hybrid regime
## 22         hybrid regime
## 23         hybrid regime
## 24      flawed democracy
## 25      flawed democracy
## 27      flawed democracy
## 28  authoritarian regime
## 29  authoritarian regime
## 30  authoritarian regime
## 31  authoritarian regime
## 32  authoritarian regime
## 33        full democracy
## 34      flawed democracy
## 35  authoritarian regime
## 36  authoritarian regime
## 37        full democracy
## 38  authoritarian regime
## 39      flawed democracy
## 40  authoritarian regime
## 41        full democracy
## 42  authoritarian regime
## 43  authoritarian regime
## 44      flawed democracy
## 45  authoritarian regime
## 46      flawed democracy
## 47      flawed democracy
## 48        full democracy
## 49  authoritarian regime
## 51      flawed democracy
## 52      flawed democracy
## 53      flawed democracy
## 54  authoritarian regime
## 55         hybrid regime
## 56  authoritarian regime
## 57  authoritarian regime
## 58      flawed democracy
## 59  authoritarian regime
## 60  authoritarian regime
## 61         hybrid regime
## 62        full democracy
## 63      flawed democracy
## 64  authoritarian regime
## 65         hybrid regime
## 66         hybrid regime
## 67        full democracy
## 68      flawed democracy
## 69      flawed democracy
## 71         hybrid regime
## 72  authoritarian regime
## 73  authoritarian regime
## 74      flawed democracy
## 75         hybrid regime
## 76         hybrid regime
## 78      flawed democracy
## 79        full democracy
## 80      flawed democracy
## 81      flawed democracy
## 82  authoritarian regime
## 84        full democracy
## 85      flawed democracy
## 86      flawed democracy
## 87         hybrid regime
## 88      flawed democracy
## 89        full democracy
## 90  authoritarian regime
## 91  authoritarian regime
## 92         hybrid regime
## 94  authoritarian regime
## 95        full democracy
## 97  authoritarian regime
## 98         hybrid regime
## 99  authoritarian regime
## 100     flawed democracy
## 101        hybrid regime
## 102     flawed democracy
## 103        hybrid regime
## 106     flawed democracy
## 107       full democracy
## 108        hybrid regime
## 109        hybrid regime
## 110     flawed democracy
## 112 authoritarian regime
## 113     flawed democracy
## 115 authoritarian regime
## 116       full democracy
## 117     flawed democracy
## 119        hybrid regime
## 121     flawed democracy
## 122        hybrid regime
## 123        hybrid regime
## 124 authoritarian regime
## 125     flawed democracy
## 127        hybrid regime
## 128       full democracy
## 129       full democracy
## 130 authoritarian regime
## 131 authoritarian regime
## 132        hybrid regime
## 133        hybrid regime
## 134       full democracy
## 135 authoritarian regime
## 136        hybrid regime
## 139     flawed democracy
## 140     flawed democracy
## 141     flawed democracy
## 142     flawed democracy
## 143     flawed democracy
## 144     flawed democracy
## 145     flawed democracy
## 146 authoritarian regime
## 147     flawed democracy
## 148 authoritarian regime
## 149 authoritarian regime
## 156 authoritarian regime
## 157        hybrid regime
## 158     flawed democracy
## 160        hybrid regime
## 161     flawed democracy
## 162     flawed democracy
## 163     flawed democracy
## 166     flawed democracy
## 168       full democracy
## 169     flawed democracy
## 170 authoritarian regime
## 171     flawed democracy
## 172       full democracy
## 173       full democracy
## 175       full democracy
## 176 authoritarian regime
## 177        hybrid regime
## 178     flawed democracy
## 179 authoritarian regime
## 181     flawed democracy
## 182     flawed democracy
## 183        hybrid regime
## 184 authoritarian regime
## 186        hybrid regime
## 187        hybrid regime
## 188 authoritarian regime
## 189       full democracy
## 190     flawed democracy
## 191       full democracy
## 192 authoritarian regime
## 194 authoritarian regime
## 195 authoritarian regime
## 197        hybrid regime
## 198 authoritarian regime
dataWS$Country=substr(dataWS$Country,3,100)

#CLUSTER5( no seguda de 2-5)

library(cluster)
set.seed(123)
g.dist = daisy(dataWS[,c(2:5)], metric="gower")
library(cluster)
library(purrr)
library(factoextra)
## Loading required package: ggplot2
## Welcome! Want to learn more? See two factoextra-related books at https://goo.gl/ve3WBa
set.seed(123)
SUGERIDOS=5
res.pam=pam(g.dist,k = SUGERIDOS,cluster.only = F)
dataWS$pam=res.pam$cluster
res.agnes <- hcut(g.dist, k = SUGERIDOS,hc_func='agnes')
dataWS$agnes=res.agnes$cluster
res.diana <- hcut(g.dist, k = SUGERIDOS,hc_func='diana')
dataWS$diana=res.diana$cluster

#cluster3

library(cluster)
set.seed(123)
g.dist = daisy(dataWS[,c(2:5)], metric="gower")
set.seed(123)
SUGERIDOS=3
res.pam=pam(g.dist,k = SUGERIDOS,cluster.only = F)
dataWS$pam=res.pam$cluster
res.agnes <- hcut(g.dist, k = SUGERIDOS,hc_func='agnes')
dataWS$agnes=res.agnes$cluster
res.diana <- hcut(g.dist, k = SUGERIDOS,hc_func='diana')
dataWS$diana=res.diana$cluster

#Evaluando cual es mejor

fviz_silhouette(res.pam)
##   cluster size ave.sil.width
## 1       1   64          0.41
## 2       2   49          0.45
## 3       3   84          0.47

fviz_silhouette(res.agnes)
##   cluster size ave.sil.width
## 1       1   49          0.61
## 2       2   81          0.19
## 3       3   67          0.53

fviz_silhouette(res.diana)
##   cluster size ave.sil.width
## 1       1   31          0.67
## 2       2   97          0.43
## 3       3   69          0.05

#base2:Democracy Index(falta)(country)

link1 = "https://en.wikipedia.org/wiki/Democracy_Index"
path1 = "/html/body/div[3]/div[3]/div[5]/div[1]/table[6]"
library(htmltab)
dataWS1 = htmltab(link1, path1)
head(dataWS1)
##           Region 2020 rank         Country      Regime type 2020 2019 2018 2017
## 2  North America         5         Canada   Full democracy 9.24 9.22 9.15 9.15
## 3  North America        25  United States Flawed democracy 7.92 7.96 7.96 7.98
## 4 Western Europe        18        Austria   Full democracy 8.16 8.29 8.29 8.42
## 5 Western Europe        36        Belgium Flawed democracy 7.51 7.64 7.78 7.78
## 6 Western Europe        34         Cyprus Flawed democracy 7.56 7.59 7.59 7.59
## 7 Western Europe         7        Denmark   Full democracy 9.15 9.22 9.22 9.22
##   2016 2015 2014 2013 2012 2011 2010 2008 2006
## 2 9.15 9.08 9.08 9.08 9.08 9.08 9.08 9.07 9.07
## 3 7.98 8.05 8.11 8.11 8.11 8.11 8.18 8.22 8.22
## 4 8.41 8.54 8.54 8.48 8.62 8.49 8.49 8.49 8.69
## 5 7.77 7.93 7.93 8.05 8.05 8.05 8.05 8.16 8.15
## 6 7.65 7.53 7.40 7.29 7.29 7.29 7.29 7.70 7.60
## 7 9.20 9.11 9.11 9.38 9.52 9.52 9.52 9.52 9.52
dataWS1$Country=substr(dataWS1$Country,3,100)
dataWS1 = dataWS1[,-c(1,2)]
dataWS1 = dataWS1[,-c(4,5,6,7,8,9,10,11,12,13,14)]

#Base3:World Happiness Report(falta)

link3 = "https://en.wikipedia.org/wiki/World_Happiness_Report"
path3 = "/html/body/div[3]/div[3]/div[5]/div[1]/div[11]/table/tbody/tr[2]/td/table"
library(htmltab)
dataWS3 = htmltab(link3, path3)
head(dataWS3)
##   Overall rank Country or region Score GDP per capita Social support
## 2            1          Finland 7.809          1.285          1.500
## 3            2          Denmark 7.646          1.327          1.503
## 4            3     Switzerland 7.560          1.391          1.472
## 5            4          Iceland 7.504          1.327          1.548
## 6            5           Norway 7.488          1.424          1.495
## 7            6      Netherlands 7.449          1.339          1.464
##   Healthy life expectancy Freedom to make life choices Generosity
## 2                   0.961                        0.662      0.160
## 3                   0.979                        0.665      0.243
## 4                   1.041                        0.629      0.269
## 5                   1.001                        0.662      0.362
## 6                   1.008                        0.670      0.288
## 7                   0.976                        0.614      0.336
##   Perceptions of corruption
## 2                     0.478
## 3                     0.495
## 4                     0.408
## 5                     0.145
## 6                     0.434
## 7                     0.369
dataWS3 = dataWS3[,-c(4,9)]
str(dataWS3$Score)
##  chr [1:153] "7.809" "7.646" "7.560" "7.504" "7.488" "7.449" "7.353" ...
dataWS3$Score= as.numeric(dataWS3$Score)
library(rio)
data="https://raw.githubusercontent.com/FernandaPizarro/FINAL-ESTADISTICA/main/export.csv"
DATA4 =import(data)

#base5:TWF: EDUCACION EXPENDITURES

library(rio)
daa5="https://raw.githubusercontent.com/FernandaPizarro/FINAL-ESTADISTICA/main/export%20(1).csv"
DATA5 =import(daa5)

#base6: Current health expenditure (% of GDP) (TWB)

library(rio)
daa6="https://github.com/FernandaPizarro/FINAL-ESTADISTICA/blob/main/API_SH.XPD.CHEX.GD.ZS_DS2_en_excel_v2_3360262.xls?raw=true"
DATA6 =import(daa6)
## New names:
## * `` -> ...3
## * `` -> ...4
## * `` -> ...5
## * `` -> ...6
## * `` -> ...7
## * ...
dataWS[dataWS == "n/a"] <- NA
na.omit(dataWS)
##                               Country Freedom in the World 2021
## 2                         Afghanistan                  not free
## 3                             Albania               partly free
## 4                             Algeria                  not free
## 6                              Angola                  not free
## 8                           Argentina                      free
## 9                             Armenia               partly free
## 10                          Australia                      free
## 11                            Austria                      free
## 12                         Azerbaijan                  not free
## 14                            Bahrain                  not free
## 15                         Bangladesh               partly free
## 17                            Belarus                  not free
## 18                            Belgium                      free
## 20                              Benin               partly free
## 21                             Bhutan               partly free
## 22                            Bolivia               partly free
## 23             Bosnia and Herzegovina               partly free
## 24                           Botswana                      free
## 25                             Brazil                      free
## 27                           Bulgaria                      free
## 28                       Burkina Faso               partly free
## 29                              Burma                  not free
## 30                            Burundi                  not free
## 31                           Cambodia                  not free
## 32                           Cameroon                  not free
## 33                             Canada                      free
## 34                         Cape Verde                      free
## 35           Central African Republic                  not free
## 36                               Chad                  not free
## 37                              Chile                      free
## 38                              China                  not free
## 39                           Colombia               partly free
## 40                            Comoros               partly free
## 41                         Costa Rica                      free
## 42  Congo, Democratic Republic of the                  not free
## 43             Congo, Republic of the                  not free
## 44                            Croatia                      free
## 45                               Cuba                  not free
## 46                             Cyprus                      free
## 47                     Czech Republic                      free
## 48                            Denmark                      free
## 49                           Djibouti                  not free
## 51                 Dominican Republic               partly free
## 52                         East Timor                      free
## 53                            Ecuador               partly free
## 54                              Egypt                  not free
## 55                        El Salvador               partly free
## 56                  Equatorial Guinea                  not free
## 57                            Eritrea                  not free
## 58                            Estonia                      free
## 59                           Eswatini                  not free
## 60                           Ethiopia                  not free
## 61                               Fiji               partly free
## 62                            Finland                      free
## 63                             France                      free
## 64                              Gabon                  not free
## 65                             Gambia               partly free
## 66                            Georgia               partly free
## 67                            Germany                      free
## 68                              Ghana                      free
## 69                             Greece                      free
## 71                          Guatemala               partly free
## 72                             Guinea               partly free
## 73                      Guinea-Bissau               partly free
## 74                             Guyana                      free
## 75                              Haiti               partly free
## 76                           Honduras               partly free
## 78                            Hungary               partly free
## 79                            Iceland                      free
## 80                              India               partly free
## 81                          Indonesia               partly free
## 82                               Iran                  not free
## 84                            Ireland                      free
## 85                             Israel                      free
## 86                              Italy                      free
## 87                        Ivory Coast               partly free
## 88                            Jamaica                      free
## 89                              Japan                      free
## 90                             Jordan                  not free
## 91                         Kazakhstan                  not free
## 92                              Kenya               partly free
## 94                       Korea, North                  not free
## 95                       Korea, South                      free
## 97                             Kuwait               partly free
## 98                         Kyrgyzstan                  not free
## 99                               Laos                  not free
## 100                            Latvia                      free
## 101                           Lebanon               partly free
## 102                           Lesotho               partly free
## 103                           Liberia               partly free
## 106                         Lithuania                      free
## 107                        Luxembourg                      free
## 108                        Madagascar               partly free
## 109                            Malawi               partly free
## 110                          Malaysia               partly free
## 112                              Mali                  not free
## 113                             Malta                      free
## 115                        Mauritania               partly free
## 116                         Mauritius                      free
## 117                            Mexico               partly free
## 119                           Moldova               partly free
## 121                          Mongolia                      free
## 122                        Montenegro               partly free
## 123                           Morocco               partly free
## 124                        Mozambique               partly free
## 125                           Namibia                      free
## 127                           Nepal               partly free
## 128                       Netherlands                      free
## 129                       New Zealand                      free
## 130                         Nicaragua                  not free
## 131                             Niger               partly free
## 132                           Nigeria               partly free
## 133                   North Macedonia               partly free
## 134                            Norway                      free
## 135                              Oman                  not free
## 136                          Pakistan               partly free
## 139                            Panama                      free
## 140                  Papua New Guinea               partly free
## 141                          Paraguay               partly free
## 142                              Peru               partly free
## 143                       Philippines               partly free
## 144                            Poland                      free
## 145                          Portugal                      free
## 146                             Qatar                  not free
## 147                           Romania                      free
## 148                            Russia                  not free
## 149                            Rwanda                  not free
## 156                      Saudi Arabia                  not free
## 157                           Senegal               partly free
## 158                            Serbia               partly free
## 160                      Sierra Leone               partly free
## 161                         Singapore               partly free
## 162                          Slovakia                      free
## 163                          Slovenia                      free
## 166                      South Africa                      free
## 168                             Spain                      free
## 169                         Sri Lanka               partly free
## 170                             Sudan                  not free
## 171                          Suriname                      free
## 172                            Sweden                      free
## 173                      Switzerland                      free
## 175                            Taiwan                      free
## 176                        Tajikistan                  not free
## 177                          Tanzania               partly free
## 178                          Thailand                  not free
## 179                              Togo               partly free
## 181               Trinidad and Tobago                      free
## 182                           Tunisia                      free
## 183                            Turkey                  not free
## 184                      Turkmenistan                  not free
## 186                            Uganda                  not free
## 187                           Ukraine               partly free
## 188              United Arab Emirates                  not free
## 189                    United Kingdom                      free
## 190                     United States                      free
## 191                           Uruguay                      free
## 192                        Uzbekistan                  not free
## 194                         Venezuela                  not free
## 195                           Vietnam                  not free
## 197                            Zambia               partly free
## 198                          Zimbabwe                  not free
##     2021 Index of Economic Freedom 2021 Press Freedom Index
## 2                    mostly unfree      difficult situation
## 3                  moderately free      noticeable problems
## 4                        repressed      difficult situation
## 6                    mostly unfree      noticeable problems
## 8                    mostly unfree      noticeable problems
## 9                      mostly free      noticeable problems
## 10                            free   satisfactory situation
## 11                     mostly free   satisfactory situation
## 12                     mostly free   very serious situation
## 14                 moderately free   very serious situation
## 15                   mostly unfree      difficult situation
## 17                 moderately free      difficult situation
## 18                     mostly free           good situation
## 20                   mostly unfree      difficult situation
## 21                   mostly unfree      noticeable problems
## 22                       repressed      difficult situation
## 23                 moderately free      noticeable problems
## 24                 moderately free   satisfactory situation
## 25                   mostly unfree      difficult situation
## 27                     mostly free      difficult situation
## 28                   mostly unfree   satisfactory situation
## 29                   mostly unfree      difficult situation
## 30                       repressed      difficult situation
## 31                   mostly unfree      difficult situation
## 32                   mostly unfree      difficult situation
## 33                     mostly free   satisfactory situation
## 34                 moderately free   satisfactory situation
## 35                       repressed      difficult situation
## 36                   mostly unfree      difficult situation
## 37                     mostly free      noticeable problems
## 38                   mostly unfree   very serious situation
## 39                 moderately free      difficult situation
## 40                   mostly unfree      noticeable problems
## 41                 moderately free           good situation
## 42                       repressed      difficult situation
## 43                   mostly unfree      difficult situation
## 44                 moderately free      noticeable problems
## 45                       repressed   very serious situation
## 46                     mostly free   satisfactory situation
## 47                     mostly free   satisfactory situation
## 48                     mostly free           good situation
## 49                   mostly unfree   very serious situation
## 51                 moderately free      noticeable problems
## 52                       repressed      noticeable problems
## 53                   mostly unfree      noticeable problems
## 54                   mostly unfree   very serious situation
## 55                 moderately free      noticeable problems
## 56                       repressed   very serious situation
## 57                       repressed   very serious situation
## 58                     mostly free   satisfactory situation
## 59                   mostly unfree      difficult situation
## 60                   mostly unfree      noticeable problems
## 61                 moderately free      noticeable problems
## 62                     mostly free           good situation
## 63                 moderately free   satisfactory situation
## 64                   mostly unfree      difficult situation
## 65                   mostly unfree      noticeable problems
## 66                     mostly free      noticeable problems
## 67                     mostly free   satisfactory situation
## 68                   mostly unfree   satisfactory situation
## 69                 moderately free      noticeable problems
## 71                 moderately free      difficult situation
## 72                   mostly unfree      difficult situation
## 73                   mostly unfree      noticeable problems
## 74                   mostly unfree      noticeable problems
## 75                   mostly unfree      noticeable problems
## 76                   mostly unfree      difficult situation
## 78                 moderately free      noticeable problems
## 79                     mostly free   satisfactory situation
## 80                   mostly unfree      difficult situation
## 81                 moderately free      difficult situation
## 82                       repressed   very serious situation
## 84                            free           good situation
## 85                     mostly free      noticeable problems
## 86                 moderately free   satisfactory situation
## 87                 moderately free      noticeable problems
## 88                 moderately free           good situation
## 89                     mostly free      noticeable problems
## 90                 moderately free      difficult situation
## 91                     mostly free      difficult situation
## 92                   mostly unfree      noticeable problems
## 94                       repressed   very serious situation
## 95                     mostly free           good situation
## 97                 moderately free      noticeable problems
## 98                 moderately free      noticeable problems
## 99                   mostly unfree   very serious situation
## 100                    mostly free   satisfactory situation
## 101                  mostly unfree      noticeable problems
## 102                  mostly unfree      noticeable problems
## 103                      repressed      noticeable problems
## 106                    mostly free   satisfactory situation
## 107                    mostly free   satisfactory situation
## 108                  mostly unfree      noticeable problems
## 109                  mostly unfree      noticeable problems
## 110                    mostly free      difficult situation
## 112                  mostly unfree      noticeable problems
## 113                    mostly free      noticeable problems
## 115                  mostly unfree      noticeable problems
## 116                    mostly free      noticeable problems
## 117                moderately free      difficult situation
## 119                moderately free      noticeable problems
## 121                moderately free      noticeable problems
## 122                moderately free      noticeable problems
## 123                moderately free      difficult situation
## 124                  mostly unfree      difficult situation
## 125                moderately free   satisfactory situation
## 127                  mostly unfree      noticeable problems
## 128                    mostly free           good situation
## 129                           free           good situation
## 130                  mostly unfree      difficult situation
## 131                  mostly unfree      noticeable problems
## 132                  mostly unfree      difficult situation
## 133                moderately free      noticeable problems
## 134                    mostly free           good situation
## 135                moderately free      difficult situation
## 136                  mostly unfree      difficult situation
## 139                moderately free      noticeable problems
## 140                  mostly unfree   satisfactory situation
## 141                moderately free      noticeable problems
## 142                moderately free      noticeable problems
## 143                moderately free      difficult situation
## 144                moderately free      noticeable problems
## 145                moderately free           good situation
## 146                    mostly free      difficult situation
## 147                moderately free   satisfactory situation
## 148                moderately free      difficult situation
## 149                moderately free      difficult situation
## 156                moderately free   very serious situation
## 157                  mostly unfree      noticeable problems
## 158                moderately free      noticeable problems
## 160                  mostly unfree      noticeable problems
## 161                           free   very serious situation
## 162                moderately free   satisfactory situation
## 163                moderately free   satisfactory situation
## 166                  mostly unfree   satisfactory situation
## 168                moderately free   satisfactory situation
## 169                  mostly unfree      difficult situation
## 170                      repressed      difficult situation
## 171                      repressed   satisfactory situation
## 172                    mostly free           good situation
## 173                           free           good situation
## 175                    mostly free   satisfactory situation
## 176                  mostly unfree   very serious situation
## 177                moderately free      difficult situation
## 178                moderately free      difficult situation
## 179                  mostly unfree      noticeable problems
## 181                  mostly unfree   satisfactory situation
## 182                  mostly unfree      noticeable problems
## 183                moderately free      difficult situation
## 184                      repressed   very serious situation
## 186                  mostly unfree      difficult situation
## 187                  mostly unfree      noticeable problems
## 188                    mostly free      difficult situation
## 189                    mostly free   satisfactory situation
## 190                    mostly free   satisfactory situation
## 191                moderately free   satisfactory situation
## 192                  mostly unfree      difficult situation
## 194                      repressed      difficult situation
## 195                moderately free   very serious situation
## 197                  mostly unfree      difficult situation
## 198                      repressed      difficult situation
##     2020 Democracy Index pam agnes diana
## 2   authoritarian regime   1     1     1
## 3       flawed democracy   2     2     2
## 4   authoritarian regime   1     1     1
## 6   authoritarian regime   1     2     3
## 8       flawed democracy   3     2     2
## 9          hybrid regime   2     2     3
## 10        full democracy   3     3     2
## 11        full democracy   3     3     2
## 12  authoritarian regime   1     1     3
## 14  authoritarian regime   1     1     3
## 15         hybrid regime   2     2     3
## 17  authoritarian regime   1     1     1
## 18      flawed democracy   3     3     2
## 20         hybrid regime   2     2     3
## 21         hybrid regime   2     2     3
## 22         hybrid regime   2     2     3
## 23         hybrid regime   2     2     3
## 24      flawed democracy   3     3     2
## 25      flawed democracy   3     2     2
## 27      flawed democracy   3     2     2
## 28  authoritarian regime   1     3     3
## 29  authoritarian regime   1     1     1
## 30  authoritarian regime   1     1     1
## 31  authoritarian regime   1     1     1
## 32  authoritarian regime   1     1     1
## 33        full democracy   3     3     2
## 34      flawed democracy   3     3     2
## 35  authoritarian regime   1     1     1
## 36  authoritarian regime   1     1     1
## 37        full democracy   3     3     2
## 38  authoritarian regime   1     1     3
## 39      flawed democracy   1     2     2
## 40  authoritarian regime   2     2     3
## 41        full democracy   3     3     2
## 42  authoritarian regime   1     1     1
## 43  authoritarian regime   1     1     1
## 44      flawed democracy   3     2     2
## 45  authoritarian regime   1     1     3
## 46      flawed democracy   3     3     2
## 47      flawed democracy   3     3     2
## 48        full democracy   3     3     2
## 49  authoritarian regime   1     1     3
## 51      flawed democracy   2     2     2
## 52      flawed democracy   3     2     2
## 53      flawed democracy   2     2     2
## 54  authoritarian regime   1     1     3
## 55         hybrid regime   2     2     3
## 56  authoritarian regime   1     1     3
## 57  authoritarian regime   1     1     3
## 58      flawed democracy   3     3     2
## 59  authoritarian regime   1     1     1
## 60  authoritarian regime   1     2     3
## 61         hybrid regime   2     2     3
## 62        full democracy   3     3     2
## 63      flawed democracy   3     3     2
## 64  authoritarian regime   1     1     1
## 65         hybrid regime   2     2     3
## 66         hybrid regime   2     2     3
## 67        full democracy   3     3     2
## 68      flawed democracy   3     3     2
## 69      flawed democracy   3     2     2
## 71         hybrid regime   2     2     3
## 72  authoritarian regime   1     1     1
## 73  authoritarian regime   2     2     3
## 74      flawed democracy   3     2     2
## 75         hybrid regime   2     2     3
## 76         hybrid regime   2     2     3
## 78      flawed democracy   2     2     2
## 79        full democracy   3     3     2
## 80      flawed democracy   1     2     3
## 81      flawed democracy   1     2     2
## 82  authoritarian regime   1     1     3
## 84        full democracy   3     3     2
## 85      flawed democracy   3     2     2
## 86      flawed democracy   3     3     2
## 87         hybrid regime   2     2     3
## 88      flawed democracy   3     3     2
## 89        full democracy   3     3     2
## 90  authoritarian regime   1     1     1
## 91  authoritarian regime   1     1     1
## 92         hybrid regime   2     2     3
## 94  authoritarian regime   1     1     3
## 95        full democracy   3     3     2
## 97  authoritarian regime   2     2     3
## 98         hybrid regime   2     2     3
## 99  authoritarian regime   1     1     3
## 100     flawed democracy   3     3     2
## 101        hybrid regime   2     2     3
## 102     flawed democracy   2     2     2
## 103        hybrid regime   2     2     3
## 106     flawed democracy   3     3     2
## 107       full democracy   3     3     2
## 108        hybrid regime   2     2     3
## 109        hybrid regime   2     2     3
## 110     flawed democracy   1     2     2
## 112 authoritarian regime   1     2     3
## 113     flawed democracy   3     2     2
## 115 authoritarian regime   2     2     3
## 116       full democracy   3     3     2
## 117     flawed democracy   1     2     2
## 119        hybrid regime   2     2     3
## 121     flawed democracy   3     2     2
## 122        hybrid regime   2     2     3
## 123        hybrid regime   2     2     3
## 124 authoritarian regime   1     1     1
## 125     flawed democracy   3     3     2
## 127        hybrid regime   2     2     3
## 128       full democracy   3     3     2
## 129       full democracy   3     3     2
## 130 authoritarian regime   1     1     1
## 131 authoritarian regime   2     2     3
## 132        hybrid regime   2     2     3
## 133        hybrid regime   2     2     3
## 134       full democracy   3     3     2
## 135 authoritarian regime   1     1     1
## 136        hybrid regime   2     2     3
## 139     flawed democracy   3     2     2
## 140     flawed democracy   3     3     2
## 141     flawed democracy   2     2     2
## 142     flawed democracy   2     2     2
## 143     flawed democracy   1     2     2
## 144     flawed democracy   3     2     2
## 145     flawed democracy   3     3     2
## 146 authoritarian regime   1     1     1
## 147     flawed democracy   3     3     2
## 148 authoritarian regime   1     1     1
## 149 authoritarian regime   1     1     1
## 156 authoritarian regime   1     1     3
## 157        hybrid regime   2     2     3
## 158     flawed democracy   2     2     2
## 160        hybrid regime   2     2     3
## 161     flawed democracy   3     2     2
## 162     flawed democracy   3     3     2
## 163     flawed democracy   3     3     2
## 166     flawed democracy   3     3     2
## 168       full democracy   3     3     2
## 169     flawed democracy   1     2     3
## 170 authoritarian regime   1     1     1
## 171     flawed democracy   3     3     2
## 172       full democracy   3     3     2
## 173       full democracy   3     3     2
## 175       full democracy   3     3     2
## 176 authoritarian regime   1     1     3
## 177        hybrid regime   2     2     3
## 178     flawed democracy   1     2     1
## 179 authoritarian regime   2     2     3
## 181     flawed democracy   3     3     2
## 182     flawed democracy   3     2     2
## 183        hybrid regime   1     2     3
## 184 authoritarian regime   1     1     3
## 186        hybrid regime   1     2     3
## 187        hybrid regime   2     2     3
## 188 authoritarian regime   1     1     1
## 189       full democracy   3     3     2
## 190     flawed democracy   3     3     2
## 191       full democracy   3     3     2
## 192 authoritarian regime   1     1     1
## 194 authoritarian regime   1     1     1
## 195 authoritarian regime   1     1     3
## 197        hybrid regime   2     2     3
## 198 authoritarian regime   1     1     1
dataWS$Country=substr(dataWS$Country,3,100)

DATA6 = DATA6[,-c(5:50)]
dataWS$`Freedom in the World 2021` =factor(dataWS$`Freedom in the World 2021`,
                   levels=c("not free","partly free","free"), 
                   ordered = T)
dataWS$`2021 Index of Economic Freedom`=as.factor(dataWS$`2021 Index of Economic Freedom`)
dataWS$`2021 Press Freedom Index`=as.factor(dataWS$`2021 Press Freedom Index`)
dataWS$`2020 Democracy Index`=as.factor(dataWS$`2020 Democracy Index`)

#base7: TWB: INFANT MORTALITY RATE

library(rio)
daa7="https://raw.githubusercontent.com/FernandaPizarro/FINAL-ESTADISTICA/main/export%20(2).csv"
DATA7 =import(daa7)

#base8: TQF: NET MIGRATION RATE

library(rio)
daa8="https://raw.githubusercontent.com/FernandaPizarro/FINAL-ESTADISTICA/main/export%20(3).csv"
DATA8 =import(daa8)

#base9: TWF- UNEMPLOYMENT

library(rio)
daa9="https://raw.githubusercontent.com/FernandaPizarro/FINAL-ESTADISTICA/main/export%20(4).csv"
DATA9 =import(daa9)