Last active
November 2, 2021 23:59
-
-
Save DATAUNIRIO/5bc2f6cbb1176036ebb7f98787797c60 to your computer and use it in GitHub Desktop.
Latinobarometro.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#------------------------------------------------------------------------------ | |
# CARREGAR A BIBLIOTECA R | |
#------------------------------------------------------------------------------ | |
library(dplyr) | |
#------------------------------------------------------------------------------ | |
# CARREGAR A BASE DE DADOS | |
#------------------------------------------------------------------------------ | |
#load("/home/steven/Área de Trabalho/atendimento/ana_paula_lima/banco/Latinobarometro2016Esp_v20170205.rdata") | |
#load("/home/steven/Área de Trabalho/atendimento/ana_paula_lima/banco/Latinobarometro_2020_Esp_Rdata_v1_0.rdata") | |
#------------------------------------------------------------------------------ | |
# FILTRO BRASIL (LINHAS) | |
#------------------------------------------------------------------------------ | |
# 76 = Brazil | |
table(Latinobarometro2016Esp_v20170205$idenpa) | |
LB2016 <- Latinobarometro2016Esp_v20170205 %>% filter(idenpa==76) | |
remove(Latinobarometro2016Esp_v20170205) | |
LB2020 <-Latinobarometro_2020_Esp %>% filter(idenpa==76) | |
remove(Latinobarometro_2020_Esp) | |
#------------------------------------------------------------------------------ | |
# SELECAO DE VARIAVEIS (COLUNAS) | |
#------------------------------------------------------------------------------ | |
names(LB2016) | |
names(LB2020) | |
# colocar em n | |
names(LB2020) <- tolower(names(LB2020)) | |
LB2020 <- LB2020 %>% select(numinves, idenpa, reg, | |
ciudad, tamciud, edad, sexo, | |
p1st, p2st, p3stgbs, p4stgbs, p10stgbs, | |
p11stgbs.a, p12st, p13stgbs.a, p13stgbs.b, | |
p13st.c,p13st.d, p13st.e, p13st.f, p13st.g, p13st.h, p13st.i, p14gbs, | |
p15st.a, p15st.b, p15st.c, p15st.d, p15st.e, p15st.f, p15st.g, p20st.a, | |
p22stm.b, p20stm.c, p21stm, p22st.c, p22st.d, p47st.a, p53n, p54st.a, p54st.b, p54st.c, | |
p55st.a, p55st.b, p55st.c, p55st.d, p55st.e, p55st.f, p56n, p57st, p58st, p59st.a, | |
p59st.b, p59n.c, p60st, p61st, p62n.a, p62st.b) | |
#------------------------------------------------------------------------------ | |
#selecionando as varáveis que vou usar de 2016 | |
names(LB2016) <- tolower(names(LB2016)) | |
LB2016 <- select(LB2016,numinves, idenpa, reg, | |
ciudad, tamciud, edad, sexo, | |
p1st, p2st, p3stgbs, p4stgbs,p8stgbs, p10st, | |
p11stgbs, p11stgbs, p13stgbsa, p13stgbsb, #p13stgbsap13stgbsb, | |
p13stc,p13std, p13ste, p13stf, p13stg, p13sth, #p13sti, | |
p14st, #p14gbs | |
p19st,p20st, | |
#.d, | |
p31sta, p47sta, | |
p31sta, #p53n, | |
#p54sta, p54stb, p54stc, | |
p54n_a, p54n_b, p54n_c, | |
#p55sta, p55stb, p55stc, p55std, p55ste, p55stf, | |
p55n_a, p55n_b, p55n_c, p55n_d, p55n_e, p55n_f, | |
p57n1, # p57st, | |
p58n_a, #p58st, | |
#p59st.a,p59st.b, p59n.c, | |
p59na,p59nb,p59nc, | |
p60n_a,#p60st, | |
p61n,#p61st, | |
p62st) #p62n.a, p62st.b) | |
#------------------------------------------------------------------------------ | |
# próximo passos | |
#------------------------------------------------------------------------------ | |
names(LB2016)[2] <- "paises" | |
names(LB2020)[2] <- "paises" | |
names(LB2016)[13] <- "grupos_poderosos" | |
names(LB2020)[14] <- "grupos_poderosos" | |
#------------------------------------------------------------------------------ | |
# TRATAMENTO DO NAO SABE NAO RESPONDEU | |
#------------------------------------------------------------------------------ | |
#2016 | |
#1-.- No sabe | |
#-2-.- No responde | |
#-3-.- No aplicable | |
#-4-.- No preguntada | |
#------------------------------------------------------------------------------ | |
#Em 2020 temos: | |
#-1-- No sabe | |
#-2-- No contesta (aqui muda a forma como está escrito, mas acredito que não há prejuízo) | |
#-3-- No aplicable - | |
# 4-- No preguntada | |
#-5-- No sabe / No contesta (esta nova opção é acrescentada) | |
#------------------------------------------------------------------------------ | |
sum(is.na(LB2016)) | |
LB2016[,8:44] | |
LB2016 %>% select(8:44) | |
LB2016[,8:44]<- as.data.frame(lapply(LB2016[,8:44], function(y) gsub(-1, NA, y))) | |
LB2016[,8:44]<- as.data.frame(lapply(LB2016[,8:44], function(y) gsub(-2, NA, y))) | |
LB2016[,8:44]<- as.data.frame(lapply(LB2016[,8:44], function(y) gsub(-3, NA, y))) | |
LB2016[,8:44]<- as.data.frame(lapply(LB2016[,8:44], function(y) gsub(-4, NA, y))) | |
sum(is.na(LB2016)) | |
#------------------------------------------------------------------------------ | |
#------------------------------------------------------------------------------ | |
sum(is.na(LB2020)) | |
LB2020[,8:58]<- as.data.frame(lapply(LB2020[,8:58], function(y) gsub(-1, NA, y))) | |
LB2020[,8:58]<- as.data.frame(lapply(LB2020[,8:58], function(y) gsub(-2, NA, y))) | |
LB2020[,8:58]<- as.data.frame(lapply(LB2020[,8:58], function(y) gsub(-3, NA, y))) | |
LB2020[,8:58]<- as.data.frame(lapply(LB2020[,8:58], function(y) gsub(-4, NA, y))) | |
LB2020[,8:58]<- as.data.frame(lapply(LB2020[,8:58], function(y) gsub(-5, NA, y))) | |
sum(is.na(LB2020)) | |
#------------------------------------------------------------------------------ | |
# Criacao da variavel ano | |
#------------------------------------------------------------------------------ | |
names(LB2016)[1]<-'ano' | |
names(LB2020)[1]<-'ano' | |
#---------------------------------------------------------------------------- | |
# revisar os nomes das variaveis antes de continuar (p10st != p10stgbs ) | |
#---------------------------------------------------------------------------- | |
identical(colnames(LB2016),colnames(LB2020)) | |
selecao <- c("paises","reg","ciudad","tamciud", "edad","sexo","ano") | |
LB2016 <- LB2016[,selecao] | |
LB2020 <- LB2020[,selecao] | |
Latin_barometro <- LB2016 %>% add_row(LB2020) | |
remove(selecao,LB2016,LB2020) | |
nomes<-c("Nome dos paises","Região","cidade da entrevista", | |
"Tamanho da cidade","Idade em anos completos", | |
"Sexo/Gênero do entrevistado","Ano da entrevista") | |
attr(Latin_barometro, "variable.labels") <- nomes | |
attributes(Latin_barometro) | |
save(Latin_barometro,file = "C:/Users/Hp/Downloads/Latin_barometro.RDATA") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment