library(ggplot2)
library(dplyr)
library(readxl)
library(devtools)
library(ggjoy)
library(ggplot2)
library(tidyverse)
library(lubridate)
library(tidytext)
library(XML)
library(rvest)
library(stringr)
library(ggthemes)
library(ggridges)
library(wesanderson)
library(RColorBrewer)
library(knitr)
library(kableExtra)
library(radarchart)
library(hrbrthemes)
library(tinytex)
library(prettydoc)
library(devtools)
library(haven)
library(summarytools)
library(questionr)
library(haven)
library(sjlabelled)
library(Hmisc)
library(labelled)
library(sjmisc)
library(ggridges)
library(ggplot2)
library(viridis)
library(hrbrthemes)
library(statsr)
library(rstatix)
library(stargazer)
library(jtools)
#library(car) Este paquete me daña la función reorder de Dplyr
library(dplyr)
library(knitr)
Original_2018<- read_dta("Colombia LAPOP AmericasBarometer 2018 v1.0_W.dta")
Original_2014 <- read_dta("1543363879Colombia LAPOP AmericasBarometer 2014 v3.0_W.dta")
Lapop_2018<- read_dta("Colombia LAPOP AmericasBarometer 2018 v1.0_W.dta")
Lapop_2014<- read_dta("1543363879Colombia LAPOP AmericasBarometer 2014 v3.0_W.dta")
setwd("~/Santiago/LAPOP/Satisfaccion Democracia")
# Variables 2018---------------------------------------------------------------
#2018:
#COLPROPAZ1B (Apoyo al proceso de paz)
Lapop_2018$colpropaz1b<- as.factor(Lapop_2018$colpropaz1b)
#PN4 (Satisfacción con la democracia)
Lapop_2018$pn4<- as.factor(Lapop_2018$pn4)
#B13 (Nivel de representación de las instituciones)
Lapop_2018$b13<- as.factor(Lapop_2018$b13)
#IDIO2 (Situación económica)
Lapop_2018$idio2<- as.factor(Lapop_2018$idio2)
#M1 (Desempeño del gobierno)
Lapop_2018$m1<- as.factor(Lapop_2018$m1)
#EXC7 (Corrupción)
Lapop_2018$exc7<- as.factor(Lapop_2018$exc7)
#Prov (Departamento)
Lapop_2018$Departamento<-as.factor(to_label(Lapop_2018$prov))
#Q2 (Edad)
Lapop_2018$q2<-as.factor(Lapop_2018$q2)
# Creando base 2018 -------------------------------------------------------
Data_2018<-Lapop_2018 %>%
select(colpropaz1b,pn4,b13,idio2,m1,Departamento,q2) %>%
na.omit() %>%
mutate(Year=as.factor(2018))
#Rename
Data_2018<- rename(Data_2018, Apoyo_Proceso_Paz=colpropaz1b, Satisfacción_democracia=pn4,
Representación_instituciones=b13,Situación_económica=idio2,Desempeño_gobierno=m1,Edad=q2)
# Variables 2014 ----------------------------------------------------------
#COLPROPAZ1 (Apoyo al proceso de paz)
Lapop_2014$colpropaz1<- as.factor(Lapop_2014$colpropaz1)
#PN4 (Satisfacción con la democracia)
Lapop_2014$pn4<- as.factor(Lapop_2014$pn4)
#B13 (Nivel de representación de las instituciones)
Lapop_2014$b13<- as.factor(Lapop_2014$b13)
#IDIO2 (Situación económica)
Lapop_2014$idio2<- as.factor(Lapop_2014$idio2)
#M1 (Desempeño del gobierno)
Lapop_2014$m1<- as.factor(Lapop_2014$m1)
#EXC7 (Corrupción)
Lapop_2014$exc7<- as.factor(Lapop_2014$exc7)
#PROV. [CODELPA]
Lapop_2014$Departamento<-as.factor(to_label(Lapop_2014$prov))
#Q2 (Edad)
Lapop_2014$q2<-as.numeric(Lapop_2014$q2)
# Creando Base 2014
Data_2014 <-Lapop_2014 %>%
select(colpropaz1,pn4,b13,idio2,m1,Departamento,q2) %>%
na.omit() %>%
mutate(Year=as.factor(2014))
#Rename
Data_2014 <-rename(Data_2014, Apoyo_Proceso_Paz=colpropaz1, Satisfacción_democracia=pn4,
Representación_instituciones=b13,Situación_económica=idio2,Desempeño_gobierno=m1,Edad=q2)
(Invertiendo las escalas y creando versiones numéricas de las variables )
####2014
##Recoding Base 2014(ojo, las variables Inv quedan es como Numeric)
unique(Original_2018$colpropaz1b)
## <labelled<double>[8]>: Apoyo al acuerdo de paz
## [1] 1 4 7 5 2 6 3 NA(a)
##
## Labels:
## value label
## 1 Nada
## 7 Mucho
## NA(a) No sabe
## NA(b) No responde
## NA(c) No Aplica
Data_2014 <- Data_2014 %>%
mutate(Inv_Satisfacción_democracia =recode(Satisfacción_democracia, "1" = 4, "2" = 3, "3" = 2, "4" = 1))
summary(Data_2014$Satisfacción_democracia)
## 1 2 3 4
## 28 465 734 152
summary(as.factor(Data_2014$Inv_Satisfacción_democracia))
## 1 2 3 4
## 152 734 465 28
Data_2014 <- Data_2014 %>%
mutate(Inv_Situación_económica=recode(Situación_económica, "1" = 3, "2" = 2, "3" = 1))
summary(Data_2014$Situación_económica)
## 1 2 3
## 441 620 318
summary(as.factor(Data_2014$Inv_Situación_económica))
## 1 2 3
## 318 620 441
Data_2014 <- Data_2014 %>%
mutate(Inv_Desempeño_gobierno=recode(Desempeño_gobierno, "1" = 5, "2" = 4, "3" = 3, "4" = 2,"5" =1))
summary(Data_2014$Desempeño_gobierno)
## 1 2 3 4 5
## 31 363 701 186 98
summary(as.factor(Data_2014$Inv_Desempeño_gobierno))
## 1 2 3 4 5
## 98 186 701 363 31
#Convertir Apoyo al proceso de Paz y Satisfacción económica a Numeric también
Data_2014$Num_Apoyo_Proceso_Paz= as.numeric(Data_2014$Apoyo_Proceso_Paz)
Data_2014$Num_Representación_instituciones= as.numeric(Data_2014$Representación_instituciones)
##Recoding Base 2018 (ojo, las variables Inv quedan es como Numeric)
Data_2018 <- Data_2018%>%
mutate(Inv_Satisfacción_democracia =recode(Satisfacción_democracia, "1" = 4, "2" = 3, "3" = 2, "4" = 1))
summary(Data_2018$Satisfacción_democracia)
## 1 2 3 4
## 33 408 826 272
summary(as.factor(Data_2018$Inv_Satisfacción_democracia))
## 1 2 3 4
## 272 826 408 33
Data_2018 <- Data_2018 %>%
mutate(Inv_Situación_económica=recode(Situación_económica, "1" = 3, "2" = 2, "3" = 1))
summary(Data_2018$Situación_económica)
## 1 2 3
## 231 693 615
summary(as.factor(Data_2018$Inv_Situación_económica))
## 1 2 3
## 615 693 231
Data_2018 <- Data_2018 %>%
mutate(Inv_Desempeño_gobierno=recode(Desempeño_gobierno, "1" = 5, "2" = 4, "3" = 3, "4" = 2,"5" =1))
summary(Data_2018$Desempeño_gobierno)
## 1 2 3 4 5
## 108 509 606 171 145
summary(as.factor(Data_2018$Inv_Desempeño_gobierno))
## 1 2 3 4 5
## 145 171 606 509 108
#Convertir Apoyo al proceso de Paz y Satisfacción económica a Numeric también
Data_2018$Num_Apoyo_Proceso_Paz= as.numeric(Data_2018$Apoyo_Proceso_Paz)
Data_2018$Num_Representación_instituciones= as.numeric(Data_2018$Representación_instituciones)
Data_2014_2018<-rbind(Data_2014,Data_2018)
#Satisfacción Democracia (Mean. HT)
Data_2014_2018 %>%
inference(y =Inv_Satisfacción_democracia , x = Year, statistic = "mean", type = "ht",
null = 0, alternative = "twosided", method = "theoretical")
## Response variable: numerical
## Explanatory variable: categorical (2 levels)
## n_2014 = 1379, y_bar_2014 = 2.2676, s_2014 = 0.6763
## n_2018 = 1539, y_bar_2018 = 2.1313, s_2018 = 0.7146
## H0: mu_2014 = mu_2018
## HA: mu_2014 != mu_2018
## t = 5.2926, df = 1378
## p_value = < 0.0001
#Satisfacción Democracia (Mean. CI)
Data_2014_2018 %>%
inference(y =Inv_Satisfacción_democracia , x = Year, statistic = "mean", type = "ci",
null = 0, alternative = "twosided", method = "theoretical")
## Response variable: numerical, Explanatory variable: categorical (2 levels)
## n_2014 = 1379, y_bar_2014 = 2.2676, s_2014 = 0.6763
## n_2018 = 1539, y_bar_2018 = 2.1313, s_2018 = 0.7146
## 95% CI (2014 - 2018): (0.0858 , 0.1869)
#Apoyo Proceso Paz (Mean. HT)
Data_2014_2018 %>%
inference(y = Num_Apoyo_Proceso_Paz, x = Year, statistic = "mean", type = "ht",
null = 0, alternative = "twosided", method = "theoretical")
## Response variable: numerical
## Explanatory variable: categorical (2 levels)
## n_2014 = 1379, y_bar_2014 = 4.3561, s_2014 = 2.2054
## n_2018 = 1539, y_bar_2018 = 4.1001, s_2018 = 2.0603
## H0: mu_2014 = mu_2018
## HA: mu_2014 != mu_2018
## t = 3.229, df = 1378
## p_value = 0.0013
#Apoyo Proceso Paz (Mean. CI)
Data_2014_2018 %>%
inference(y =Num_Apoyo_Proceso_Paz , x = Year, statistic = "mean", type = "ci",
null = 0, alternative = "twosided", method = "theoretical")
## Response variable: numerical, Explanatory variable: categorical (2 levels)
## n_2014 = 1379, y_bar_2014 = 4.3561, s_2014 = 2.2054
## n_2018 = 1539, y_bar_2018 = 4.1001, s_2018 = 2.0603
## 95% CI (2014 - 2018): (0.1005 , 0.4115)
#Usando Apoyo_Proceso_Paz como variable numérica
m1_2014 <- lm(Inv_Satisfacción_democracia ~ Num_Apoyo_Proceso_Paz, data = Data_2014)
m1_2018 <- lm(Inv_Satisfacción_democracia ~ Num_Apoyo_Proceso_Paz, data = Data_2018)
summary(m1_2014)
##
## Call:
## lm(formula = Inv_Satisfacción_democracia ~ Num_Apoyo_Proceso_Paz,
## data = Data_2014)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.3534 -0.3210 -0.1911 0.6790 1.8414
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.126147 0.040119 52.996 < 2e-16 ***
## Num_Apoyo_Proceso_Paz 0.032469 0.008217 3.951 8.17e-05 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.6727 on 1377 degrees of freedom
## Multiple R-squared: 0.01121, Adjusted R-squared: 0.01049
## F-statistic: 15.61 on 1 and 1377 DF, p-value: 8.168e-05
summary(m1_2018)
##
## Call:
## lm(formula = Inv_Satisfacción_democracia ~ Num_Apoyo_Proceso_Paz,
## data = Data_2018)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.2080 -0.1948 -0.1286 0.7920 1.9508
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.022741 0.040477 49.97 < 2e-16 ***
## Num_Apoyo_Proceso_Paz 0.026466 0.008822 3.00 0.00274 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.7128 on 1537 degrees of freedom
## Multiple R-squared: 0.005822, Adjusted R-squared: 0.005175
## F-statistic: 9.001 on 1 and 1537 DF, p-value: 0.002742
#Usando Apoyo_Proceso_Paz como variable ordinal
m2_2014 <- lm(Inv_Satisfacción_democracia ~ Apoyo_Proceso_Paz, data = Data_2014)
m2_2018 <- lm(Inv_Satisfacción_democracia ~ Apoyo_Proceso_Paz, data = Data_2018)
summary(m2_2014)
##
## Call:
## lm(formula = Inv_Satisfacción_democracia ~ Apoyo_Proceso_Paz,
## data = Data_2014)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.3541 -0.3298 -0.1609 0.6702 1.8391
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.160920 0.041640 51.896 < 2e-16 ***
## Apoyo_Proceso_Paz2 0.004029 0.079995 0.050 0.95984
## Apoyo_Proceso_Paz3 -0.011666 0.071491 -0.163 0.87040
## Apoyo_Proceso_Paz4 0.139080 0.068926 2.018 0.04380 *
## Apoyo_Proceso_Paz5 0.193147 0.062443 3.093 0.00202 **
## Apoyo_Proceso_Paz6 0.168923 0.064056 2.637 0.00846 **
## Apoyo_Proceso_Paz7 0.162523 0.055468 2.930 0.00345 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.6727 on 1372 degrees of freedom
## Multiple R-squared: 0.01488, Adjusted R-squared: 0.01057
## F-statistic: 3.455 on 6 and 1372 DF, p-value: 0.002162
summary(m2_2018)
##
## Call:
## lm(formula = Inv_Satisfacción_democracia ~ Apoyo_Proceso_Paz,
## data = Data_2018)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.23944 -0.23944 -0.09179 0.76056 1.98502
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.01498 0.04358 46.236 < 2e-16 ***
## Apoyo_Proceso_Paz2 0.07111 0.07251 0.981 0.326877
## Apoyo_Proceso_Paz3 0.12163 0.06834 1.780 0.075304 .
## Apoyo_Proceso_Paz4 0.07681 0.06595 1.165 0.244331
## Apoyo_Proceso_Paz5 0.19983 0.06146 3.251 0.001173 **
## Apoyo_Proceso_Paz6 0.22446 0.06542 3.431 0.000617 ***
## Apoyo_Proceso_Paz7 0.11405 0.06280 1.816 0.069554 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.7121 on 1532 degrees of freedom
## Multiple R-squared: 0.01098, Adjusted R-squared: 0.007107
## F-statistic: 2.835 on 6 and 1532 DF, p-value: 0.00952
#Apoyo al proceso de Paz
Data_2014_2018 %>%
ggplot(aes(y=Inv_Satisfacción_democracia,x=Num_Apoyo_Proceso_Paz))+
geom_point()+
geom_smooth(method=lm, color="darkred", fill="blue")+
labs(title="Satisfacción con la democracia vs Apoyo al proceso de Paz",
subtitle="1 = Nada / 7 = Mucho")+
facet_grid( ~Year)
## `geom_smooth()` using formula 'y ~ x'
#Desempeño del gobierno
Data_2014_2018 %>%
ggplot(aes(y=Inv_Satisfacción_democracia,x=Inv_Desempeño_gobierno))+
geom_point()+
labs(title="Satisfacción con la democracia vs Desempeño_gobierno",
subtitle="1 = Muy malo (pésimo) / 5 = Muy bueno")+
geom_smooth(method=lm, color="darkred", fill="blue")+
facet_grid( ~Year)
## `geom_smooth()` using formula 'y ~ x'
#Situación económica
Data_2014_2018 %>%
ggplot(aes(y=Inv_Satisfacción_democracia,x=Inv_Situación_económica))+
geom_point()+
labs(title="Satisfacción con la democracia vs Situación_económica",
subtitle="1 = Peor / 3 = Mejor")+
geom_smooth(method=lm, color="darkred", fill="blue")+
facet_grid( ~Year)
## `geom_smooth()` using formula 'y ~ x'
#Representación instituciones
Data_2014_2018 %>%
ggplot(aes(y=Inv_Satisfacción_democracia,x=Num_Representación_instituciones))+
geom_point()+
labs(title="Satisfacción con la democracia vs Confianza_Congreso",
subtitle="1 = Nada / 3 = Mucho")+
geom_smooth(method=lm, color="darkred", fill="blue")+
facet_grid( ~Year)
## `geom_smooth()` using formula 'y ~ x'
##Cuatro modelos iguales pero con órdenes distintos en las escalas
##Satisfacción con la democracia vs situación económica en 2014 (Como variable categórica)
m1_2014 <- lm(as.numeric(Satisfacción_democracia) ~ as.factor(Inv_Situación_económica), data = Data_2014)
m2_2014 <- lm(Inv_Satisfacción_democracia ~ as.factor(Inv_Situación_económica), data = Data_2014)
m3_2014<- lm(as.numeric(Satisfacción_democracia) ~ Situación_económica, data = Data_2014)
m4_2014<- lm(Inv_Satisfacción_democracia ~ Situación_económica, data = Data_2014)
summary(m1_2014)
##
## Call:
## lm(formula = as.numeric(Satisfacción_democracia) ~ as.factor(Inv_Situación_económica),
## data = Data_2014)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.8239 -0.6644 0.2661 0.3356 1.3356
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.82390 0.03781 74.686 < 2e-16 ***
## as.factor(Inv_Situación_económica)2 -0.09003 0.04651 -1.936 0.05310 .
## as.factor(Inv_Situación_económica)3 -0.15950 0.04960 -3.216 0.00133 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.6743 on 1376 degrees of freedom
## Multiple R-squared: 0.007462, Adjusted R-squared: 0.006019
## F-statistic: 5.172 on 2 and 1376 DF, p-value: 0.005782
summary(m2_2014)
##
## Call:
## lm(formula = Inv_Satisfacción_democracia ~ as.factor(Inv_Situación_económica),
## data = Data_2014)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.3356 -0.3356 -0.2661 0.6644 1.8239
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.17610 0.03781 57.553 < 2e-16 ***
## as.factor(Inv_Situación_económica)2 0.09003 0.04651 1.936 0.05310 .
## as.factor(Inv_Situación_económica)3 0.15950 0.04960 3.216 0.00133 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.6743 on 1376 degrees of freedom
## Multiple R-squared: 0.007462, Adjusted R-squared: 0.006019
## F-statistic: 5.172 on 2 and 1376 DF, p-value: 0.005782
summary(m3_2014)
##
## Call:
## lm(formula = as.numeric(Satisfacción_democracia) ~ Situación_económica,
## data = Data_2014)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.8239 -0.6644 0.2661 0.3356 1.3356
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.66440 0.03211 82.984 < 2e-16 ***
## Situación_económica2 0.06947 0.04200 1.654 0.09835 .
## Situación_económica3 0.15950 0.04960 3.216 0.00133 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.6743 on 1376 degrees of freedom
## Multiple R-squared: 0.007462, Adjusted R-squared: 0.006019
## F-statistic: 5.172 on 2 and 1376 DF, p-value: 0.005782
summary(m4_2014)
##
## Call:
## lm(formula = Inv_Satisfacción_democracia ~ Situación_económica,
## data = Data_2014)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.3356 -0.3356 -0.2661 0.6644 1.8239
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.33560 0.03211 72.743 < 2e-16 ***
## Situación_económica2 -0.06947 0.04200 -1.654 0.09835 .
## Situación_económica3 -0.15950 0.04960 -3.216 0.00133 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.6743 on 1376 degrees of freedom
## Multiple R-squared: 0.007462, Adjusted R-squared: 0.006019
## F-statistic: 5.172 on 2 and 1376 DF, p-value: 0.005782
##En la primera voy a hacer un bar plot de frecuencias
#y uno de proporciones. En el resto lo voy a hacer solo de proporciones.
#Apoyo Proceso Paz (FREC)
Data_2014_2018 %>%
ggplot(aes(x=Apoyo_Proceso_Paz))+
geom_bar(fill="Skyblue")+
labs(title="Apoyo al proceso de Paz 2014 vs 2018",
subtitle="1= Nada / 7= Mucho")+
facet_grid(~Year)
#Apoyo Proceso Paz (Prop)
Data_2014_2018 %>%
ggplot()+
geom_bar(mapping = aes(x =Apoyo_Proceso_Paz, y = ..prop.., group=1),
fill="Skyblue")+
labs(title="Apoyo al Proceso de Paz 2014 vs 2018",
subtitle="1= Nada / 7= Mucho")+
facet_grid(~Year)
#Satisfacción Democracia
Data_2014_2018 %>%
ggplot()+
geom_bar(mapping = aes(x =Inv_Satisfacción_democracia, y = ..prop.., group=1),
fill="Skyblue")+
labs(title="Satisfacción con la democracia 2014 vs 2018",
subtitle="1= Muy insatisfecho(a) / 5 = Muy satisfecho(a)")+
facet_grid(~Year)
#Representación Instituciones
Data_2014_2018 %>%
ggplot()+
geom_bar(mapping = aes(x =Representación_instituciones, y = ..prop.., group=1),
fill="Skyblue")+
labs(title="Confianza en el Congreso 2014 vs 2018",
subtitle="1= Nada / 7= Mucho")+
facet_grid(~Year)
#Situacion Económica
Data_2014_2018 %>%
ggplot(aes(x=Inv_Situación_económica))+
geom_bar(mapping = aes(x =Inv_Situación_económica, y = ..prop.., group=1),
fill="Skyblue")+
labs(title="Percepción sobre su situación económica 2014 vs 2018",
subtitle="1= Peor / 2= Igual /3= Mejor (Últimos 12 meses)")+
facet_grid(~Year)
#Desempeño Gobierno
Data_2014_2018 %>%
ggplot()+
geom_bar(mapping = aes(x =Inv_Desempeño_gobierno, y = ..prop.., group=1), stat = "count",
fill="Skyblue")+
labs(title="Desempeño del gobierno actual",
subtitle="1 = Muy malo (pésimo) / 5 = Muy bueno")+
facet_grid(~Year)
#Edad
Data_2014_2018 %>%
ggplot(aes(x=Edad))+
geom_bar(fill="Skyblue")+
labs(title="Edades")+
facet_grid(~Year)
#Departamento
Data_2014_2018 %>%
ggplot(aes(x=Departamento))+
geom_bar(fill="Skyblue")+
labs(title="Departamentos")+
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))+
facet_grid(~Year)