PARTE 2

library(htmltab)
Felicidad = htmltab(doc = "https://es.wikipedia.org/wiki/%C3%8Dndice_global_de_felicidad", 
               which =  '//*[@id="mw-content-text"]/div/table')
str (Felicidad)
## 'data.frame':    156 obs. of  9 variables:
##  $ №                                     : chr  "1" "2" "3" "4" ...
##  $ País                                  : chr  "Finlandia" "Noruega" "Dinamarca" "Islandia" ...
##  $ Puntuación                            : chr  "7.633" "7.594" "7.555" "7.495" ...
##  $ PIB per cápita                        : chr  "1.305" "1.456" "1.351" "1.343" ...
##  $ Apoyo social                          : chr  "1.592" "1.582" "1.590" "1.644" ...
##  $ Esperanza de años de vida saludable   : chr  "0.874" "0.861" "0.868" "0.914" ...
##  $ Libertad para tomar decisiones vitales: chr  "0.681" "0.686" "0.683" "0.677" ...
##  $ Generosidad                           : chr  "0.192" "0.286" "0.284" "0.353" ...
##  $ Percepción de la corrupción           : chr  "0.393" "0.340" "0.408" "0.138" ...

Primero recodifico.

Felicidad$Puntuación = as.numeric(Felicidad$Puntuación)
Felicidad= Felicidad [,c (1:3)]
str(Felicidad)
## 'data.frame':    156 obs. of  3 variables:
##  $ №         : chr  "1" "2" "3" "4" ...
##  $ País      : chr  "Finlandia" "Noruega" "Dinamarca" "Islandia" ...
##  $ Puntuación: num  7.63 7.59 7.55 7.5 7.49 ...

1) ¿La puntuación de la felicidad se distribuye asimetricamente?

Para considerar a una variable asimétrica la media y la mediana han de ser iguales, característica que no se cumple en la variable explorada. Igualmente, el histograma nos muestra que existe una leve inclinación a la izquierda, hecho que también se puede constatar en el boxplot. A la par, el skew nos indica que la asimetría es mínima pero existente.  
summary(Felicidad$Puntuación)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   2.905   4.454   5.378   5.376   6.168   7.633
library(DescTools)
Skew(Felicidad$Puntuación,conf.level = 0.05)
##       skew     lwr.ci     upr.ci 
## 0.01494113 0.01128785 0.02793371
library(ggplot2)
aas= ggplot(Felicidad,aes(x=Puntuación)) + geom_histogram(bins=8) 
aas  

library(ggplot2)
basep=ggplot(data=Felicidad, aes(y=as.numeric(Puntuación)))
basep +  geom_boxplot() + coord_flip()

2) ¿El valor representativo de indice de felicidad es robusto?

Sí lo es debido a que la mediana y la media son muy parecidas, cualquiera de las dos puede ser.

summary(Felicidad$Puntuación)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   2.905   4.454   5.378   5.376   6.168   7.633

3) ¿Puedes concluir que hay mucha desigualdad en este indice?

Sí, la desigualdad es mínima. Ello nos lo demuestra el gini al ser su resultado menor a 0.

Gini(Felicidad$Puntuación,conf.level=0.95)
##      gini    lwr.ci    upr.ci 
## 0.1196207 0.1093158 0.1328299

4) ¿Se puede afirmar que aproximadamente el 80% de los paises del mundo suman el 75% del puntaje acumulado de felicidad?

No, ello se niega y es demostrado por el Lorenz.

library(gglorenz)
## Registered S3 methods overwritten by 'ineq':
##   method   from     
##   plot.Lc  DescTools
##   lines.Lc DescTools
ggplot(Felicidad,aes(x=Puntuación))+ gglorenz::stat_lorenz(color='red') +
    geom_abline(linetype = "dashed") + coord_fixed() +
    labs(x = "A",
         y = "B",
         title = "C",
         caption = "D")

5) ¿Hay atipicos en el puntaje de felicidad?

El boxplot nos indica que no existe atípicos. A la par, los cálculos dados más abajo nos dan un resultado nulo a la búsqueda de valores atípicos.

library(ggplot2)
basep=ggplot(data=Felicidad, aes(y=as.numeric(Puntuación)))
basep +  geom_boxplot() + coord_flip()

q3=quantile(Felicidad$Puntuación,0.75)
            
q1=quantile(Felicidad$Puntuación,0.25)

# calculando umbrales 
umbralAlto= q3+1.5*IQR(Felicidad$Puntuación)
umbralBajo= q1-1.5*IQR(Felicidad$Puntuación)
Felicidad[Felicidad$Puntuación>=umbralAlto,]
## [1] №          País       Puntuación
## <0 rows> (or 0-length row.names)
Felicidad[Felicidad$Puntuación>=umbralAlto,]
## [1] №          País       Puntuación
## <0 rows> (or 0-length row.names)

PARTE 1

library(rio)
zozozoz='https://github.com/JoseManuelMagallanes/Estadistica_Para_AnalisisPolitico/raw/master/lapop17.dta'
lapop17=import(zozozoz)
names(lapop17)
##   [1] "pais"         "sobremuestra" "idnum"        "uniq_id"     
##   [5] "upm"          "prov"         "municipio"    "cluster"     
##   [9] "ur"           "tamano"       "idiomaq"      "fecha"       
##  [13] "wt"           "estratopri"   "estratosec"   "q2"          
##  [17] "q1"           "perprov"      "ls3"          "a4"          
##  [21] "soct2"        "idio2"        "np1"          "sgl1"        
##  [25] "cp6"          "cp7"          "cp8"          "cp13"        
##  [29] "cp20"         "it1"          "l1"           "prot3"       
##  [33] "jc10"         "jc13"         "jc15a"        "vic1ext"     
##  [37] "vic1exta"     "vic2new"      "aoj11"        "aoj12"       
##  [41] "b1"           "b2"           "b3"           "b4"          
##  [45] "b6"           "b43"          "b12"          "b13"         
##  [49] "b18"          "b21"          "b21a"         "b32"         
##  [53] "b37"          "b47a"         "m1"           "m2"          
##  [57] "sd2new2"      "sd3new2"      "sd6new2"      "infrax"      
##  [61] "infra3"       "ros1"         "ros4"         "ing4"        
##  [65] "eff1"         "eff2"         "aoj22new"     "media3"      
##  [69] "media4"       "exp_a"        "dst1b"        "drk1"        
##  [73] "env1c"        "env2b"        "envp3l"       "envp3l_o"    
##  [77] "envp3n"       "envp3n_o"     "envp41"       "envp42"      
##  [81] "pn4"          "w14a"         "e5"           "e15"         
##  [85] "e16"          "d1"           "d2"           "d3"          
##  [89] "d4"           "d5"           "d6"           "ivv3"        
##  [93] "lib1"         "lib2b"        "lib2c"        "lib4"        
##  [97] "exc2"         "exc6"         "exc20"        "exc11"       
## [101] "exc13"        "exc14"        "exc15"        "exc16"       
## [105] "exc18"        "exc7"         "exc7new"      "vb1"         
## [109] "vb2"          "vb3n"         "vb10"         "vb11"        
## [113] "pol1"         "vb20"         "dis7a"        "dis8a"       
## [117] "dis9a"        "dis10a"       "dis11a"       "for5"        
## [121] "mil10a"       "mil10e"       "ccq1"         "ccq2"        
## [125] "ccq3"         "ccq4"         "ie1"          "ie2"         
## [129] "ie3"          "ie6"          "ie9"          "ie10"        
## [133] "envp8"        "wf1"          "cct1b"        "ed"          
## [137] "ed2"          "q5a"          "q5b"          "q3c"         
## [141] "ocup4a"       "ocup1a"       "q10g"         "q10new"      
## [145] "q14"          "q10d"         "q10e"         "q11n"        
## [149] "q12c"         "q12bn"        "q12"          "q12m"        
## [153] "q12f"         "vac1"         "etid"         "iiet1"       
## [157] "iiet2"        "iiet3"        "www1"         "gi0"         
## [161] "pr1"          "r3"           "r4"           "r4a"         
## [165] "r5"           "r6"           "r7"           "r8"          
## [169] "r12"          "r14"          "r15"          "r18"         
## [173] "r1"           "r16"          "colorr"       "conocim"     
## [177] "iarea1"       "iarea2"       "iarea3"       "iarea4"      
## [181] "iarea6"       "iarea7"       "sexi"         "colori"      
## [185] "srvyrid"      "nationality"  "formatq"      "sex"
str(lapop17)
## 'data.frame':    2647 obs. of  188 variables:
##  $ pais        : num  11 11 11 11 11 11 11 11 11 11 ...
##   ..- attr(*, "label")= chr "Country"
##   ..- attr(*, "format.stata")= chr "%36.0g"
##   ..- attr(*, "labels")= Named num 11
##   .. ..- attr(*, "names")= chr "Peru"
##  $ sobremuestra: num  1 0 0 0 1 1 0 1 0 1 ...
##   ..- attr(*, "label")= chr "Sobremuestra"
##   ..- attr(*, "format.stata")= chr "%10.0g"
##  $ idnum       : num  1753 2596 229 1303 1989 ...
##   ..- attr(*, "label")= chr "Questionnaire Number"
##   ..- attr(*, "format.stata")= chr "%36.0g"
##  $ uniq_id     : num  16111753 16112596 16110229 16111303 16111989 ...
##   ..- attr(*, "label")= chr "Unique Identifier"
##   ..- attr(*, "format.stata")= chr "%36.0g"
##   ..- attr(*, "labels")= Named num  16110001 16110002 16110003 16110004 16110005 ...
##   .. ..- attr(*, "names")= chr  "PER16_0001" "PER16_0002" "PER16_0003" "PER16_0004" ...
##  $ upm         : num  241 97 97 103 232 205 102 206 97 232 ...
##   ..- attr(*, "label")= chr "Primary Sampling Unit"
##   ..- attr(*, "format.stata")= chr "%36.0g"
##  $ prov        : num  1122 1105 1105 1121 1116 ...
##   ..- attr(*, "label")= chr "Departament"
##   ..- attr(*, "format.stata")= chr "%36.0g"
##   ..- attr(*, "labels")= Named num  1101 1102 1103 1104 1105 ...
##   .. ..- attr(*, "names")= chr  "AMAZONAS" "ANCASH" "APURIMAC" "AREQUIPA" ...
##  $ municipio   : num  11221003 11050502 11050502 11210205 11160505 ...
##   ..- attr(*, "label")= chr "Municipio"
##   ..- attr(*, "format.stata")= chr "%36.0g"
##   ..- attr(*, "labels")= Named num  1.1e+07 1.1e+07 1.1e+07 1.1e+07 1.1e+07 ...
##   .. ..- attr(*, "names")= chr  "CAJARURO" "CUMBA" "HUARAZ" "JANGAS" ...
##  $ cluster     : num  467 223 224 236 430 483 234 321 223 431 ...
##   ..- attr(*, "label")= chr "Cluster"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##  $ ur          : num  2 2 2 2 2 2 2 2 2 2 ...
##   ..- attr(*, "label")= chr "Urban/Rural"
##   ..- attr(*, "format.stata")= chr "%36.0g"
##   ..- attr(*, "labels")= Named num  1 2
##   .. ..- attr(*, "names")= chr  "Urban" "Rural"
##  $ tamano      : num  5 5 5 5 5 5 5 5 5 5 ...
##   ..- attr(*, "label")= chr "Size of Location"
##   ..- attr(*, "format.stata")= chr "%37.0g"
##   ..- attr(*, "labels")= Named num  1 2 3 4 5
##   .. ..- attr(*, "names")= chr  "National Capital (Metropolitan area)" "Large City" "Medium City" "Small City" ...
##  $ idiomaq     : num  1 1 1 1 1 1 1 1 1 1 ...
##   ..- attr(*, "label")= chr "Language of Questionnaire"
##   ..- attr(*, "format.stata")= chr "%36.0g"
##   ..- attr(*, "labels")= Named num 1
##   .. ..- attr(*, "names")= chr "Spanish"
##  $ fecha       : Date, format: "2017-02-14" "2017-02-17" ...
##  $ wt          : num  0.303 1.431 1.431 1.431 0.303 ...
##   ..- attr(*, "label")= chr "Country Weight"
##   ..- attr(*, "format.stata")= chr "%36.0g"
##  $ estratopri  : num  1104 1107 1107 1107 1104 ...
##   ..- attr(*, "label")= chr "Primary Strata"
##   ..- attr(*, "format.stata")= chr "%36.0g"
##   ..- attr(*, "labels")= Named num  1101 1102 1103 1104 1105 ...
##   .. ..- attr(*, "names")= chr  "Costa Norte" "Costa Sur" "Lima Metropolitana" "Selva" ...
##  $ estratosec  : num  3 3 3 3 3 3 3 3 3 3 ...
##   ..- attr(*, "label")= chr "Secondary Strata"
##   ..- attr(*, "format.stata")= chr "%36.0g"
##   ..- attr(*, "labels")= Named num  1 2 3
##   .. ..- attr(*, "names")= chr  "Large (more than 100,000)" "Medium (between 25,000 and 100,000)" "Small (less than 25,000)"
##  $ q2          : num  39 52 56 68 59 45 52 19 34 32 ...
##   ..- attr(*, "label")= chr "Age"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##  $ q1          : num  1 2 1 1 1 2 1 1 2 1 ...
##   ..- attr(*, "label")= chr "Sex"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 2
##   .. ..- attr(*, "names")= chr  "Male" "Female"
##  $ perprov     : num  2210 505 505 2102 1605 ...
##   ..- attr(*, "label")= chr "Province"
##   ..- attr(*, "format.stata")= chr "%36.0g"
##   ..- attr(*, "labels")= Named num  107 201 204 208 210 212 218 301 304 401 ...
##   .. ..- attr(*, "names")= chr  "UTCUBAMBA" "HUARAZ" "ASUNCIÓN" "CASMA" ...
##  $ ls3         : num  1 3 2 NA 1 2 4 2 2 2 ...
##   ..- attr(*, "label")= chr "Life Satisfaction"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 2 3 4 NA NA
##   .. ..- attr(*, "names")= chr  "Very Satisfied" "Somewhat Satisfied" "Somewhat Dissatisfied" "Very Dissatisfied" ...
##  $ a4          : num  25 1 1 NA 13 4 13 13 21 NA ...
##   ..- attr(*, "label")= chr "Most Important Problem"
##   ..- attr(*, "format.stata")= chr "%64.0f"
##   ..- attr(*, "labels")= Named num  1 2 3 4 5 7 10 11 13 15 ...
##   .. ..- attr(*, "names")= chr  "Economy, problems with, crisis of" "Inflation, high prices" "Unemployment" "Poverty" ...
##  $ soct2       : num  3 3 3 2 2 2 3 2 3 NA ...
##   ..- attr(*, "label")= chr "Evaluation of the Economic Situation of the Country"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 2 3 NA NA
##   .. ..- attr(*, "names")= chr  "Better" "Same" "Worse" "Don't Know" ...
##  $ idio2       : num  3 3 3 2 3 3 3 2 3 2 ...
##   ..- attr(*, "label")= chr "Perception of Personal Economic Situation"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 2 3 NA NA
##   .. ..- attr(*, "names")= chr  "Better" "Same" "Worse" "Don't Know" ...
##  $ np1         : num  2 1 1 NA 2 2 2 2 2 2 ...
##   ..- attr(*, "label")= chr "Attendance at Municipal Meeting"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 2 NA NA
##   .. ..- attr(*, "names")= chr  "Yes" "No" "Don't Know" "No Response"
##  $ sgl1        : num  2 4 4 2 5 3 5 4 5 4 ...
##   ..- attr(*, "label")= chr "Quality of Municipal Services"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 2 3 4 5 NA NA
##   .. ..- attr(*, "names")= chr  "Very Good" "Good" "Neither Good nor Bad (Fair)" "Bad" ...
##  $ cp6         : num  4 3 3 1 3 4 2 3 1 3 ...
##   ..- attr(*, "label")= chr "Attendance at Meetings of Religious Organization"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 2 3 4 NA NA
##   .. ..- attr(*, "names")= chr  "Once a Week" "Once or Twice a Month" "Once or Twice a Year" "Never" ...
##  $ cp7         : num  3 2 2 4 4 3 4 4 1 2 ...
##   ..- attr(*, "label")= chr "Attendance at Meetings of Parent Association"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 2 3 4 NA NA
##   .. ..- attr(*, "names")= chr  "Once a Week" "Once or Twice a Month" "Once or Twice a Year" "Never" ...
##  $ cp8         : num  3 2 2 4 4 4 4 4 2 2 ...
##   ..- attr(*, "label")= chr "Attendance at Meetings of Community Improvement Group"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 2 3 4 NA NA
##   .. ..- attr(*, "names")= chr  "Once a Week" "Once or Twice a Month" "Once or Twice a Year" "Never" ...
##  $ cp13        : num  3 4 4 4 1 4 4 4 4 4 ...
##   ..- attr(*, "label")= chr "Attendance at Meetings of Political Movements or Parties"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 2 3 4 NA NA
##   .. ..- attr(*, "names")= chr  "Once a Week" "Once or Twice a Month" "Once or Twice a Year" "Never" ...
##  $ cp20        : num  NA 2 NA NA NA 1 NA NA 2 NA ...
##   ..- attr(*, "label")= chr "Attendance at Meetings of Women's Group"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 2 3 4 NA NA NA
##   .. ..- attr(*, "names")= chr  "Once a Week" "Once or Twice a Month" "Once or Twice a Year" "Never" ...
##  $ it1         : num  3 2 2 3 1 3 4 1 1 3 ...
##   ..- attr(*, "label")= chr "Interpersonal Trust"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 2 3 4 NA NA
##   .. ..- attr(*, "names")= chr  "Very Trustworthy" "Somewhat Trustworthy" "Not Very Trustworthy" "Untrustworthy" ...
##  $ l1          : num  10 NA NA 10 10 5 3 5 4 2 ...
##   ..- attr(*, "label")= chr "Ideology (Left / Right)"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 10 NA NA
##   .. ..- attr(*, "names")= chr  "Left" "Right" "Don't Know" "No Response"
##  $ prot3       : num  1 2 2 2 2 1 2 2 2 2 ...
##   ..- attr(*, "label")= chr "Participated in a Protest"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 2 NA
##   .. ..- attr(*, "names")= chr  "Yes, I have participated" "No, I have not participated" "Don't Know"
##  $ jc10        : num  NA 2 NA NA 1 1 NA 1 2 1 ...
##   ..- attr(*, "label")= chr "Coup is Justified when Crime is High"
##   ..- attr(*, "format.stata")= chr "%74.0f"
##   ..- attr(*, "labels")= Named num  1 2 NA NA NA
##   .. ..- attr(*, "names")= chr  "Yes, a military take-over of the state would be justified" "No, a military take-over of the state would not be justified" "Don't Know" "No Response" ...
##  $ jc13        : num  1 NA NA 2 NA NA 2 NA NA NA ...
##   ..- attr(*, "label")= chr "Coup is Justified when Corruption is High"
##   ..- attr(*, "format.stata")= chr "%74.0f"
##   ..- attr(*, "labels")= Named num  1 2 NA NA NA
##   .. ..- attr(*, "names")= chr  "Yes, a military take-over of the state would be justified" "No, a military take-over of the state would not be justified" "Don't Know" "No Response" ...
##  $ jc15a       : num  1 NA NA 2 2 1 2 2 2 2 ...
##   ..- attr(*, "label")= chr "JC15A. ¿Cree usted que cuando el país enfrenta momentos muy difíciles, se justif"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 2 NA NA
##   .. ..- attr(*, "names")= chr  "Yes, it is justified" "No, it is not justified" "Don't Know" "No Response"
##  $ vic1ext     : num  2 2 2 2 1 2 2 2 2 2 ...
##   ..- attr(*, "label")= chr "Victim of Crime in the Last 12 Months"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 2 NA NA
##   .. ..- attr(*, "names")= chr  "Yes" "No" "Don't Know" "No Response"
##  $ vic1exta    : num  NA NA NA NA 3 NA NA NA NA NA ...
##   ..- attr(*, "label")= chr "Victim of Crime in the Last 12 Months (Frequency)"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  NA NA NA
##   .. ..- attr(*, "names")= chr  "Don't Know" "No Response" "Not Applicable"
##  $ vic2new     : num  NA NA NA NA 8 NA NA NA NA NA ...
##   ..- attr(*, "label")= chr "Type of Victimization"
##   ..- attr(*, "format.stata")= chr "%75.0f"
##   ..- attr(*, "labels")= Named num  1 2 3 4 5 6 7 8 9 10 ...
##   .. ..- attr(*, "names")= chr  "Unarmed robbery, no assault or physical threats" "Unarmed robbery with assault or physical threats" "Armed robbery" "Assault but not robbery" ...
##  $ aoj11       : num  1 3 3 NA 4 2 4 1 3 2 ...
##   ..- attr(*, "label")= chr "Perception of Neighborhood Insecurity"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 2 3 4 NA NA
##   .. ..- attr(*, "names")= chr  "Very Safe" "Somewhat Safe" "Somewhat Unsafe" "Very Unsafe" ...
##  $ aoj12       : num  1 4 4 4 1 4 2 2 1 4 ...
##   ..- attr(*, "label")= chr "Confidence that Judiciary will Punish the Guilty"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 2 3 4 NA NA
##   .. ..- attr(*, "names")= chr  "A lot" "Some" "Little" "None" ...
##  $ b1          : num  7 2 2 4 1 3 2 2 7 3 ...
##   ..- attr(*, "label")= chr "Courts Guarantee Fair Trial"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 7 NA NA
##   .. ..- attr(*, "names")= chr  "Not at All" "A Lot" "Don't Know" "No Response"
##  $ b2          : num  7 NA 3 5 7 5 2 4 7 5 ...
##   ..- attr(*, "label")= chr "Respect for Political Institutions"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 7 NA NA
##   .. ..- attr(*, "names")= chr  "Not at All" "A Lot" "Don't Know" "No Response"
##  $ b3          : num  7 3 2 3 1 6 1 2 7 2 ...
##   ..- attr(*, "label")= chr "Basic Rights are Protected"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 7 NA NA
##   .. ..- attr(*, "names")= chr  "Not at All" "A Lot" "Don't Know" "No Response"
##  $ b4          : num  5 2 NA 2 1 4 2 4 7 7 ...
##   ..- attr(*, "label")= chr "Pride in Political System"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 7 NA NA
##   .. ..- attr(*, "names")= chr  "Not at All" "A Lot" "Don't Know" "No Response"
##  $ b6          : num  NA 1 2 3 7 6 3 3 7 1 ...
##   ..- attr(*, "label")= chr "People Should Support the Political System"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 7 NA NA
##   .. ..- attr(*, "names")= chr  "Not at All" "A Lot" "Don't Know" "No Response"
##  $ b43         : num  6 7 7 6 7 7 5 7 7 7 ...
##   ..- attr(*, "label")= chr "Pride in Nationality"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 7 NA NA
##   .. ..- attr(*, "names")= chr  "Not at All" "A Lot" "Don't Know" "No Response"
##  $ b12         : num  7 1 2 7 5 5 3 4 7 7 ...
##   ..- attr(*, "label")= chr "Trust in Armed Forces"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 7 NA NA
##   .. ..- attr(*, "names")= chr  "Not at All" "A Lot" "Don't Know" "No Response"
##  $ b13         : num  1 2 2 1 1 3 2 2 7 6 ...
##   ..- attr(*, "label")= chr "Trust in the National Legislature"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 7 NA NA
##   .. ..- attr(*, "names")= chr  "Not at All" "A Lot" "Don't Know" "No Response"
##  $ b18         : num  2 1 2 1 7 6 1 1 7 2 ...
##   ..- attr(*, "label")= chr "Trust in National Police"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 7 NA NA
##   .. ..- attr(*, "names")= chr  "Not at All" "A Lot" "Don't Know" "No Response"
##  $ b21         : num  3 1 2 2 1 4 3 2 4 4 ...
##   ..- attr(*, "label")= chr "Trust in Political Parties"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 7 NA NA
##   .. ..- attr(*, "names")= chr  "Not at All" "A Lot" "Don't Know" "No Response"
##  $ b21a        : num  NA NA NA 6 1 6 3 4 3 5 ...
##   ..- attr(*, "label")= chr "Trust in Executive"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 7 NA NA
##   .. ..- attr(*, "names")= chr  "Not at All" "A Lot" "Don't Know" "No Response"
##  $ b32         : num  5 3 2 2 1 6 3 3 1 1 ...
##   ..- attr(*, "label")= chr "Trust in Local Government"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 7 NA NA
##   .. ..- attr(*, "names")= chr  "Not at All" "A Lot" "Don't Know" "No Response"
##  $ b37         : num  7 4 4 4 7 7 3 2 4 7 ...
##   ..- attr(*, "label")= chr "Trust in the Media"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 7 NA NA
##   .. ..- attr(*, "names")= chr  "Not at All" "A Lot" "Don't Know" "No Response"
##  $ b47a        : num  1 3 2 5 1 6 4 3 6 7 ...
##   ..- attr(*, "label")= chr "Trust in Elections"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 7 NA NA
##   .. ..- attr(*, "names")= chr  "Not at All" "A Lot" "Don't Know" "No Response"
##  $ m1          : num  5 3 3 4 5 3 5 3 NA 2 ...
##   ..- attr(*, "label")= chr "Presidential Job Approval"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 2 3 4 5 NA NA
##   .. ..- attr(*, "names")= chr  "Very Good" "Good" "Neither Good nor Bad (Fair)" "Bad" ...
##  $ m2          : num  3 NA 3 5 5 1 3 4 3 NA ...
##   ..- attr(*, "label")= chr "Congressional Job Approval"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 2 3 4 5 NA NA
##   .. ..- attr(*, "names")= chr  "Very Well" "Well" "Neither well nor poorly" "Poorly" ...
##  $ sd2new2     : num  4 3 3 2 4 3 3 3 2 2 ...
##   ..- attr(*, "label")= chr "Satisfaction with Roads"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 2 3 4 NA NA NA
##   .. ..- attr(*, "names")= chr  "Very Satisfied" "Satisfied" "Dissatisfied" "Very Dissatisfied" ...
##  $ sd3new2     : num  2 3 3 1 2 1 3 3 1 2 ...
##   ..- attr(*, "label")= chr "Satisfaction with Public Schools"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 2 3 4 NA NA NA
##   .. ..- attr(*, "names")= chr  "Very Satisfied" "Satisfied" "Dissatisfied" "Very Dissatisfied" ...
##  $ sd6new2     : num  2 3 3 1 2 4 3 3 1 2 ...
##   ..- attr(*, "label")= chr "Satisfaction with Public Medical and Health Services"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 2 3 4 NA NA NA
##   .. ..- attr(*, "names")= chr  "Very Satisfied" "Satisfied" "Dissatisfied" "Very Dissatisfied" ...
##  $ infrax      : num  4 6 6 5 2 1 2 6 4 6 ...
##   ..- attr(*, "label")= chr "Police Response Time"
##   ..- attr(*, "format.stata")= chr "%52.0f"
##   ..- attr(*, "labels")= Named num  1 2 3 4 5 6 NA NA
##   .. ..- attr(*, "names")= chr  "Less than 10 minutes" "Between 10 and 30 minutes" "More than 30 minutes and up to an hour" "More than 1 hour and up to 3 hours" ...
##  $ infra3      : num  4 4 2 3 2 1 3 1 1 1 ...
##   ..- attr(*, "label")= chr "Time it Takes to Get to the Hospital"
##   ..- attr(*, "format.stata")= chr "%84.0f"
##   ..- attr(*, "labels")= Named num  1 2 3 4 5 6 NA NA
##   .. ..- attr(*, "names")= chr  "Less than 10 minutes" "Between 10 and 30 minutes" "More than 30 minutes and up to an hour" "More than 1 hour and up to 3 hours" ...
##  $ ros1        : num  2 6 4 2 5 6 4 6 6 5 ...
##   ..- attr(*, "label")= chr "The State Should Own Important Industries"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 7 NA NA
##   .. ..- attr(*, "names")= chr  "Strongly Disagree" "Strongly Agree" "Don't Know" "No Response"
##  $ ros4        : num  2 6 4 4 7 7 3 7 5 7 ...
##   ..- attr(*, "label")= chr "Government Should Implement Policies to Reduce Income Inequality"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 7 NA NA
##   .. ..- attr(*, "names")= chr  "Strongly Disagree" "Strongly Agree" "Don't Know" "No Response"
##  $ ing4        : num  4 4 3 6 4 7 3 7 4 3 ...
##   ..- attr(*, "label")= chr "Democracy is Better than Any Other Form of Government"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 7 NA NA
##   .. ..- attr(*, "names")= chr  "Strongly Disagree" "Strongly Agree" "Don't Know" "No Response"
##  $ eff1        : num  1 3 3 4 3 7 4 2 3 5 ...
##   ..- attr(*, "label")= chr "Leaders Are Interested in What People Think"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 7 NA NA
##   .. ..- attr(*, "names")= chr  "Strongly Disagree" "Strongly Agree" "Don't Know" "No Response"
##  $ eff2        : num  2 1 2 3 6 5 4 2 2 2 ...
##   ..- attr(*, "label")= chr "Understands Important Political Issues"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 7 NA NA
##   .. ..- attr(*, "names")= chr  "Strongly Disagree" "Strongly Agree" "Don't Know" "No Response"
##  $ aoj22new    : num  7 7 7 5 7 7 5 5 7 7 ...
##   ..- attr(*, "label")= chr "Penalties for Crimes Need to Increase"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 7 NA NA
##   .. ..- attr(*, "names")= chr  "Strongly Disagree" "Strongly Agree" "Don't Know" "No Response"
##  $ media3      : num  2 5 4 6 4 7 3 3 4 6 ...
##   ..- attr(*, "label")= chr "News Media Represents the Different Views that Exist in the Country"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 7 NA NA
##   .. ..- attr(*, "names")= chr  "Strongly Disagree" "Strongly Agree" "Don't Know" "No Response"
##  $ media4      : num  3 3 3 4 2 4 4 6 2 5 ...
##   ..- attr(*, "label")= chr "News Media is Controlled by a Few Economic Groups"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 7 NA NA
##   .. ..- attr(*, "names")= chr  "Strongly Disagree" "Strongly Agree" "Don't Know" "No Response"
##  $ exp_a       : num  2 1 1 1 2 1 1 1 2 2 ...
##   ..- attr(*, "label")= chr "Experimental Test A"
##   ..- attr(*, "format.stata")= chr "%36.0g"
##   ..- attr(*, "labels")= Named num  1 2
##   .. ..- attr(*, "names")= chr  "Set 1" "Set 2"
##  $ dst1b       : num  1 4 4 4 7 7 3 4 7 7 ...
##   ..- attr(*, "label")= chr "Government Should Spend More to Enforce Building Codes to Make Homes Safe"
##   ..- attr(*, "format.stata")= chr "%36.0g"
##   ..- attr(*, "labels")= Named num  1 7 NA NA
##   .. ..- attr(*, "names")= chr  "Strongly Disagree" "Strongly Agree" "Don't Know" "No Response"
##  $ drk1        : num  3 4 4 2 4 4 4 4 3 4 ...
##   ..- attr(*, "label")= chr "Likelihood of Death or Harm from Natural Disaster"
##   ..- attr(*, "format.stata")= chr "%36.0g"
##   ..- attr(*, "labels")= Named num  1 2 3 4 NA NA
##   .. ..- attr(*, "names")= chr  "Not Likely at All" "A Little Likely" "Somewhat Likely" "Very Likely" ...
##  $ env1c       : num  2 1 1 2 5 1 4 2 7 3 ...
##   ..- attr(*, "label")= chr "Higher Priority for Protecting Environment or Promoting Economic Growth"
##   ..- attr(*, "format.stata")= chr "%36.0g"
##   ..- attr(*, "labels")= Named num  1 7 NA NA
##   .. ..- attr(*, "names")= chr  "Environment as priority" "Economic growth as priority" "Don't Know" "No Response"
##  $ env2b       : num  1 1 1 3 2 1 1 1 3 2 ...
##   ..- attr(*, "label")= chr "Seriousness of Climate Change"
##   ..- attr(*, "format.stata")= chr "%36.0g"
##   ..- attr(*, "labels")= Named num  1 2 3 4 NA NA
##   .. ..- attr(*, "names")= chr  "Very Serious" "Somewhat Serious" "Not So Serious" "Not Serious at All" ...
##  $ envp3l      : num  1 1 1 5 3 3 7 1 1 6 ...
##   ..- attr(*, "label")= chr "Most Serious Environmental Problem in Locality"
##   ..- attr(*, "format.stata")= chr "%73.0f"
##   ..- attr(*, "labels")= Named num  0 1 2 3 4 5 6 7 8 NA
##   .. ..- attr(*, "names")= chr  "None [Do not read] (there is no environmental problem in my area)" "Air pollution" "Pollution of rivers and seas" "Floods" ...
##  $ envp3l_o    : chr  "" "" "" "" ...
##   ..- attr(*, "label")= chr "Most Serious Environmental Problem in Locality (Other)"
##   ..- attr(*, "format.stata")= chr "%-37s"
##  $ envp3n      : num  5 1 1 1 3 2 1 4 1 NA ...
##   ..- attr(*, "label")= chr "Most Serious Environmental Problem in the Country"
##   ..- attr(*, "format.stata")= chr "%68.0f"
##   ..- attr(*, "labels")= Named num  1 2 3 4 5 6 7 8 NA NA
##   .. ..- attr(*, "names")= chr  "Air pollution" "Pollution of rivers and seas" "Floods" "Flash flooding" ...
##  $ envp3n_o    : chr  "" "" "" "" ...
##   ..- attr(*, "label")= chr "Most Serious Environmental Problem in the Country (Other)"
##   ..- attr(*, "format.stata")= chr "%-37s"
##  $ envp41      : num  2 NA NA NA 2 5 NA 1 5 NA ...
##   ..- attr(*, "label")= chr "Responsible for Environmental Pollution"
##   ..- attr(*, "format.stata")= chr "%60.0f"
##   ..- attr(*, "labels")= Named num  1 2 3 4 5 7 NA NA NA
##   .. ..- attr(*, "names")= chr  "People" "Extractive enterprises (mining, oil, gase, fishery)" "Other companies" "The State" ...
##  $ envp42      : num  NA 2 7 4 NA NA 5 NA NA 2 ...
##   ..- attr(*, "label")= chr "Responsible for Environmental Pollution"
##   ..- attr(*, "format.stata")= chr "%60.0f"
##   ..- attr(*, "labels")= Named num  1 2 3 4 5 7 NA NA NA
##   .. ..- attr(*, "names")= chr  "People" "Extractive enterprises (mining, oil, gase, fishery)" "Other companies" "The State" ...
##  $ pn4         : num  4 3 2 1 3 4 3 3 4 2 ...
##   ..- attr(*, "label")= chr "Satisfaction with Democracy"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 2 3 4 NA NA
##   .. ..- attr(*, "names")= chr  "Very Satisfied" "Satisfied" "Dissatisfied" "Very Dissatisfied" ...
##  $ w14a        : num  1 1 1 2 2 1 2 2 2 NA ...
##   ..- attr(*, "label")= chr "Abortion Justified When Mother's Health is at Risk"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 2 NA NA
##   .. ..- attr(*, "names")= chr  "Yes, it is justified" "No, it is not justified" "Don't Know" "No Response"
##  $ e5          : num  2 5 2 6 4 10 5 6 6 4 ...
##   ..- attr(*, "label")= chr "Approval of Those Participating in Legal Demonstration"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 10 NA NA
##   .. ..- attr(*, "names")= chr  "Strongly disapprove" "Strongly approve" "Don't Know" "No Response"
##  $ e15         : num  10 2 2 6 2 7 5 2 1 1 ...
##   ..- attr(*, "label")= chr "Approval of Those Blocking Roads to Protest"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 10 NA NA
##   .. ..- attr(*, "names")= chr  "Strongly disapprove" "Strongly approve" "Don't Know" "No Response"
##  $ e16         : num  10 10 5 6 3 6 6 8 4 10 ...
##   ..- attr(*, "label")= chr "Approval of Vigilante Justice"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 10 NA NA
##   .. ..- attr(*, "names")= chr  "Strongly disapprove" "Strongly approve" "Don't Know" "No Response"
##  $ d1          : num  9 6 3 6 4 9 3 2 8 5 ...
##   ..- attr(*, "label")= chr "Approval of Government Critics' Right to Vote"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 10 NA NA
##   .. ..- attr(*, "names")= chr  "Strongly disapprove" "Strongly approve" "Don't Know" "No Response"
##  $ d2          : num  3 5 3 4 5 10 4 3 9 8 ...
##   ..- attr(*, "label")= chr "Approval of Government Critics' Right to Peaceful Demonstrations"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 10 NA NA
##   .. ..- attr(*, "names")= chr  "Strongly disapprove" "Strongly approve" "Don't Know" "No Response"
##  $ d3          : num  2 8 3 6 2 10 5 4 4 4 ...
##   ..- attr(*, "label")= chr "Approval of Government Critics' Right to Run for Office"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 10 NA NA
##   .. ..- attr(*, "names")= chr  "Strongly disapprove" "Strongly approve" "Don't Know" "No Response"
##  $ d4          : num  9 5 2 4 4 10 4 4 10 9 ...
##   ..- attr(*, "label")= chr "Approval of Government Critics' Right to Make Speeches"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 10 NA NA
##   .. ..- attr(*, "names")= chr  "Strongly disapprove" "Strongly approve" "Don't Know" "No Response"
##  $ d5          : num  1 NA NA 3 1 10 4 1 8 1 ...
##   ..- attr(*, "label")= chr "Approval of Homosexuals' Right to Run for Office"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 10 NA NA
##   .. ..- attr(*, "names")= chr  "Strongly disapprove" "Strongly approve" "Don't Know" "No Response"
##  $ d6          : num  2 1 NA 6 1 10 5 1 10 1 ...
##   ..- attr(*, "label")= chr "Approval of Same-Sex Couples' Right to Marry"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 10 NA NA
##   .. ..- attr(*, "names")= chr  "Strongly disapprove" "Strongly approve" "Don't Know" "No Response"
##  $ ivv3        : num  1 NA NA 8 1 1 3 1 4 1 ...
##   ..- attr(*, "label")= chr "Approve of Those Trying to Convince Voters to Nullify Ballots"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 10 NA NA
##   .. ..- attr(*, "names")= chr  "Strongly disapprove" "Strongly approve" "Don't Know" "No Response"
##  $ lib1        : num  3 1 1 1 1 1 1 3 1 1 ...
##   ..- attr(*, "label")= chr "Level of Freedom of the Press Today"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 2 3 NA NA
##   .. ..- attr(*, "names")= chr  "Very Little" "Enough" "Too Much" "Don't Know" ...
##  $ lib2b       : num  3 1 1 NA 1 1 1 1 1 3 ...
##   ..- attr(*, "label")= chr "Level of Freedom of Expression Today"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 2 3 NA NA
##   .. ..- attr(*, "names")= chr  "Very Little" "Enough" "Too Much" "Don't Know" ...
##  $ lib2c       : num  3 1 1 3 1 1 1 1 3 1 ...
##   ..- attr(*, "label")= chr "Level of Freedom to Express Political Opinions without Fear"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 2 3 NA NA
##   .. ..- attr(*, "names")= chr  "Very Little" "Enough" "Too Much" "Don't Know" ...
##  $ lib4        : num  3 1 1 3 1 1 1 1 2 1 ...
##   ..- attr(*, "label")= chr "Level of Protection of Human Rights Today"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  1 2 3 NA NA
##   .. ..- attr(*, "names")= chr  "Very Little" "Enough" "Too Much" "Don't Know" ...
##  $ exc2        : num  0 0 0 0 0 0 0 0 0 0 ...
##   ..- attr(*, "label")= chr "Police Officer Asked for a Bribe"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  0 1 NA NA
##   .. ..- attr(*, "names")= chr  "No" "Yes" "Don't Know" "No Response"
##  $ exc6        : num  1 0 0 0 0 0 0 0 0 0 ...
##   ..- attr(*, "label")= chr "Government Employee Asked for a Bribe"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  0 1 NA NA
##   .. ..- attr(*, "names")= chr  "No" "Yes" "Don't Know" "No Response"
##  $ exc20       : num  0 0 0 0 0 0 0 0 0 0 ...
##   ..- attr(*, "label")= chr "Soldier Requested a Bribe"
##   ..- attr(*, "format.stata")= chr "%36.0f"
##   ..- attr(*, "labels")= Named num  0 1 NA NA
##   .. ..- attr(*, "names")= chr  "No" "Yes" "Don't Know" "No Response"
##   [list output truncated]
##  - attr(*, "label")= chr "©AmericasBarometer, LAPOP; created 21 Sep 2017; type: notes list"
##  - attr(*, "notes")= chr  "For more information and details about the sample design, please consult the technical and country reports thro"| __truncated__ "4" "All data are de-identified and regulated by the Institutional Review Board (IRB) of Vanderbilt University. They"| __truncated__ "All data are copyrighted by the Latin American Public Opinion Project (LAPOP) and may only be used with the exp"| __truncated__ ...
library(stringr)
names(lapop17)=str_split(names(lapop17)," ",simplify = T)[,1]
names(lapop17)=str_replace_all(names(lapop17), "[^[:ascii:]]", "")
lapop17[,]=lapply(lapop17[,], str_replace_all,"[^[:ascii:]]","")
str (lapop17)
## 'data.frame':    2647 obs. of  188 variables:
##  $ pais        : chr  "11" "11" "11" "11" ...
##  $ sobremuestra: chr  "1" "0" "0" "0" ...
##  $ idnum       : chr  "1753" "2596" "229" "1303" ...
##  $ uniq_id     : chr  "16111753" "16112596" "16110229" "16111303" ...
##  $ upm         : chr  "241" "97" "97" "103" ...
##  $ prov        : chr  "1122" "1105" "1105" "1121" ...
##  $ municipio   : chr  "11221003" "11050502" "11050502" "11210205" ...
##  $ cluster     : chr  "467" "223" "224" "236" ...
##  $ ur          : chr  "2" "2" "2" "2" ...
##  $ tamano      : chr  "5" "5" "5" "5" ...
##  $ idiomaq     : chr  "1" "1" "1" "1" ...
##  $ fecha       : chr  "2017-02-14" "2017-02-17" "2017-02-17" "2017-03-25" ...
##  $ wt          : chr  "0.303381085395813" "1.43081080913544" "1.43081080913544" "1.43081080913544" ...
##  $ estratopri  : chr  "1104" "1107" "1107" "1107" ...
##  $ estratosec  : chr  "3" "3" "3" "3" ...
##  $ q2          : chr  "39" "52" "56" "68" ...
##  $ q1          : chr  "1" "2" "1" "1" ...
##  $ perprov     : chr  "2210" "505" "505" "2102" ...
##  $ ls3         : chr  "1" "3" "2" NA ...
##  $ a4          : chr  "25" "1" "1" NA ...
##  $ soct2       : chr  "3" "3" "3" "2" ...
##  $ idio2       : chr  "3" "3" "3" "2" ...
##  $ np1         : chr  "2" "1" "1" NA ...
##  $ sgl1        : chr  "2" "4" "4" "2" ...
##  $ cp6         : chr  "4" "3" "3" "1" ...
##  $ cp7         : chr  "3" "2" "2" "4" ...
##  $ cp8         : chr  "3" "2" "2" "4" ...
##  $ cp13        : chr  "3" "4" "4" "4" ...
##  $ cp20        : chr  NA "2" NA NA ...
##  $ it1         : chr  "3" "2" "2" "3" ...
##  $ l1          : chr  "10" NA NA "10" ...
##  $ prot3       : chr  "1" "2" "2" "2" ...
##  $ jc10        : chr  NA "2" NA NA ...
##  $ jc13        : chr  "1" NA NA "2" ...
##  $ jc15a       : chr  "1" NA NA "2" ...
##  $ vic1ext     : chr  "2" "2" "2" "2" ...
##  $ vic1exta    : chr  NA NA NA NA ...
##  $ vic2new     : chr  NA NA NA NA ...
##  $ aoj11       : chr  "1" "3" "3" NA ...
##  $ aoj12       : chr  "1" "4" "4" "4" ...
##  $ b1          : chr  "7" "2" "2" "4" ...
##  $ b2          : chr  "7" NA "3" "5" ...
##  $ b3          : chr  "7" "3" "2" "3" ...
##  $ b4          : chr  "5" "2" NA "2" ...
##  $ b6          : chr  NA "1" "2" "3" ...
##  $ b43         : chr  "6" "7" "7" "6" ...
##  $ b12         : chr  "7" "1" "2" "7" ...
##  $ b13         : chr  "1" "2" "2" "1" ...
##  $ b18         : chr  "2" "1" "2" "1" ...
##  $ b21         : chr  "3" "1" "2" "2" ...
##  $ b21a        : chr  NA NA NA "6" ...
##  $ b32         : chr  "5" "3" "2" "2" ...
##  $ b37         : chr  "7" "4" "4" "4" ...
##  $ b47a        : chr  "1" "3" "2" "5" ...
##  $ m1          : chr  "5" "3" "3" "4" ...
##  $ m2          : chr  "3" NA "3" "5" ...
##  $ sd2new2     : chr  "4" "3" "3" "2" ...
##  $ sd3new2     : chr  "2" "3" "3" "1" ...
##  $ sd6new2     : chr  "2" "3" "3" "1" ...
##  $ infrax      : chr  "4" "6" "6" "5" ...
##  $ infra3      : chr  "4" "4" "2" "3" ...
##  $ ros1        : chr  "2" "6" "4" "2" ...
##  $ ros4        : chr  "2" "6" "4" "4" ...
##  $ ing4        : chr  "4" "4" "3" "6" ...
##  $ eff1        : chr  "1" "3" "3" "4" ...
##  $ eff2        : chr  "2" "1" "2" "3" ...
##  $ aoj22new    : chr  "7" "7" "7" "5" ...
##  $ media3      : chr  "2" "5" "4" "6" ...
##  $ media4      : chr  "3" "3" "3" "4" ...
##  $ exp_a       : chr  "2" "1" "1" "1" ...
##  $ dst1b       : chr  "1" "4" "4" "4" ...
##  $ drk1        : chr  "3" "4" "4" "2" ...
##  $ env1c       : chr  "2" "1" "1" "2" ...
##  $ env2b       : chr  "1" "1" "1" "3" ...
##  $ envp3l      : chr  "1" "1" "1" "5" ...
##  $ envp3l_o    : chr  "" "" "" "" ...
##  $ envp3n      : chr  "5" "1" "1" "1" ...
##  $ envp3n_o    : chr  "" "" "" "" ...
##  $ envp41      : chr  "2" NA NA NA ...
##  $ envp42      : chr  NA "2" "7" "4" ...
##  $ pn4         : chr  "4" "3" "2" "1" ...
##  $ w14a        : chr  "1" "1" "1" "2" ...
##  $ e5          : chr  "2" "5" "2" "6" ...
##  $ e15         : chr  "10" "2" "2" "6" ...
##  $ e16         : chr  "10" "10" "5" "6" ...
##  $ d1          : chr  "9" "6" "3" "6" ...
##  $ d2          : chr  "3" "5" "3" "4" ...
##  $ d3          : chr  "2" "8" "3" "6" ...
##  $ d4          : chr  "9" "5" "2" "4" ...
##  $ d5          : chr  "1" NA NA "3" ...
##  $ d6          : chr  "2" "1" NA "6" ...
##  $ ivv3        : chr  "1" NA NA "8" ...
##  $ lib1        : chr  "3" "1" "1" "1" ...
##  $ lib2b       : chr  "3" "1" "1" NA ...
##  $ lib2c       : chr  "3" "1" "1" "3" ...
##  $ lib4        : chr  "3" "1" "1" "3" ...
##  $ exc2        : chr  "0" "0" "0" "0" ...
##  $ exc6        : chr  "1" "0" "0" "0" ...
##  $ exc20       : chr  "0" "0" "0" "0" ...
##   [list output truncated]
##  - attr(*, "label")= chr "©AmericasBarometer, LAPOP; created 21 Sep 2017; type: notes list"
##  - attr(*, "notes")= chr  "For more information and details about the sample design, please consult the technical and country reports thro"| __truncated__ "4" "All data are de-identified and regulated by the Institutional Review Board (IRB) of Vanderbilt University. They"| __truncated__ "All data are copyrighted by the Latin American Public Opinion Project (LAPOP) and may only be used with the exp"| __truncated__ ...

1)¿Cree la mayoria de la gente que los servicios que dan los municipios son malos?

No, así no lo cree.

mode (lapop17$sgl1)
## [1] "character"

2) ¿Esa creencia es relevante o no?

El Herfindahl y la representatividad efectiva nos indican que no es muy relevante.

 Herfindahl(table(lapop17$sgl1))
## [1] 0.2917169
 1/Herfindahl(table(lapop17$sgl1))
## [1] 3.427981

3) ¿Podemos afirmar que alrededor de 70% de los entrevistados cree que los derechos básicos del ciudadano estan a los mås medianamente protegidos por el sistema político peruano?

No, la tabla de frecuencias nos indica lo contrario.

library(questionr)
library(magrittr)
BKE=freq(lapop17$b3,total = F,exclude = c(NA),cum = T) %>% data.frame()
BKE=data.frame(row.names(BKE),BKE,row.names = NULL)

names(lapop17)=c("Categoria","Conteo", "Porcentaje", "Porcentaje Acumulado")
BKE
##   row.names.BKE.   n   X. X.cum
## 1              1 358 13.7  13.7
## 2              2 449 17.2  31.0
## 3              3 557 21.4  52.3
## 4              4 557 21.4  73.7
## 5              5 379 14.5  88.3
## 6              6 181  6.9  95.2
## 7              7 125  4.8 100.0