Code
=
tiv <- data.frame(TB_SEC_IVaVD)
write.csv(data,"C:/Users/valer/Desktop/tiv_clean.csv", row.names = TRUE)
tiv <- data.frame(TB_SEC_IVaVD)
data_new <- tiv[ , colSums(is.na(tiv)) < nrow(tiv)]
data <- data_new[vapply(data_new, function(x) length(unique(x)) > 1, logical(1L))]
print(TVIV$P1_2)
#Variables that hold the answers we want to calculate
P7_6 <- paste0("P7_6_", 1:18)
P7_8 <- paste0("P7_8_", 1:18) #Academic
P8_9 <- paste0("P8_9_", 1:19)
P8_11 <- paste0("P8_11_", 1:19) # Career
P8_8 <- paste0("P8_8_", 1:9) # Discrimination
P9_1 <- paste0("P9_1_", 1:16)
P9_3 <- paste0("P9_3_", 1:16) # community
P11_1 <- paste0("P11_1_", 1:20) # Family
P14_1 <- paste0("P14_1_", 1:38)
P14_1[c(23, 24, 35:38)] <- paste0(P14_1[c(23, 24, 35:38)], "AB") # Relationship
P14_3 <- paste0("P14_3_", 1:38)
P14_3[c(23, 24, 35:38)] <- paste0(P14_3[c(23, 24, 35:38)], "AB") # Relationship
variables <- c(
"UPM_DIS", "EST_DIS", "FAC_MUJ", "CVE_ENT", "T_INSTRUM", "P7_1", "P7_2", P7_6, P7_8,
"P8_1", "P8_2", "P8_3_1_1", "P8_3_1_2", "P8_3_2_1", "P8_3_2_2", "P8_3_2_3",
"P8_4", "P8_5", P8_9, P8_11, P8_8, P9_1, P9_3, P11_1, "P13_C_1", P14_1, P14_3
)
#collecting question answers
muj <- TB_SEC_IVaVD[, variables]
muj$vtot_lv_con <- ifelse(
(muj$P7_6_1%in%'1' | muj$P7_6_2%in%'1' | muj$P7_6_3%in%'1' |
muj$P7_6_4%in%'1' | muj$P7_6_5%in%'1' | muj$P7_6_6%in%'1' |
muj$P7_6_7%in%'1' | muj$P7_6_8%in%'1' | muj$P7_6_9%in%'1' |
muj$P7_6_10%in%'1' | muj$P7_6_11%in%'1' | muj$P7_6_12%in%'1' |
muj$P7_6_13%in%'1' | muj$P7_6_14%in%'1' | muj$P7_6_15%in%'1' |
muj$P7_6_16%in%'1' | muj$P7_6_17%in%'1' | muj$P7_6_18%in%'1' |
muj$P8_3_1_1%in%'1' | muj$P8_3_1_2%in%'1' | muj$P8_3_2_1%in%'1' |
muj$P8_3_2_2%in%'1' | muj$P8_3_2_3%in%'1' | muj$P8_8_1%in%'1' |
muj$P8_8_2%in%'1' | muj$P8_8_3%in%'1' | muj$P8_8_4%in%'1' |
muj$P8_8_5%in%'1' | muj$P8_8_6%in%'1' | muj$P8_8_7%in%'1' |
muj$P8_8_8%in%'1' | muj$P8_8_9%in%'1' | muj$P8_9_1%in%'1' |
muj$P8_9_2%in%'1' | muj$P8_9_3%in%'1' | muj$P8_9_4%in%'1' |
muj$P8_9_5%in%'1' | muj$P8_9_6%in%'1' | muj$P8_9_7%in%'1' |
muj$P8_9_8%in%'1' | muj$P8_9_9%in%'1' | muj$P8_9_10%in%'1' |
muj$P8_9_11%in%'1' | muj$P8_9_12%in%'1' | muj$P8_9_13%in%'1' |
muj$P8_9_14%in%'1' | muj$P8_9_15%in%'1' | muj$P8_9_16%in%'1' |
muj$P8_9_17%in%'1' | muj$P8_9_18%in%'1' | muj$P8_9_19%in%'1' |
muj$P9_1_1%in%'1' | muj$P9_1_2%in%'1' | muj$P9_1_3%in%'1' |
muj$P9_1_4%in%'1' | muj$P9_1_5%in%'1' | muj$P9_1_6%in%'1' |
muj$P9_1_7%in%'1' | muj$P9_1_8%in%'1' | muj$P9_1_9%in%'1' |
muj$P9_1_10%in%'1' | muj$P9_1_11%in%'1' | muj$P9_1_12%in%'1' |
muj$P9_1_13%in%'1' | muj$P9_1_14%in%'1' | muj$P9_1_15%in%'1' |
muj$P9_1_16%in%'1' |
muj$P11_1_1%in%c( '1','2','3') | muj$P11_1_2%in%c( '1','2','3') |
muj$P11_1_3%in%c( '1','2','3') | muj$P11_1_4%in%c( '1','2','3') |
muj$P11_1_5%in%c( '1','2','3') | muj$P11_1_6%in%c( '1','2','3') |
muj$P11_1_7%in%c( '1','2','3') | muj$P11_1_8%in%c( '1','2','3') |
muj$P11_1_9%in%c( '1','2','3') | muj$P11_1_10%in%c( '1','2','3') |
muj$P11_1_11%in%c( '1','2','3') | muj$P11_1_12%in%c( '1','2','3') |
muj$P11_1_13%in%c( '1','2','3') | muj$P11_1_14%in%c( '1','2','3') |
muj$P11_1_15%in%c( '1','2','3') | muj$P11_1_16%in%c( '1','2','3') |
muj$P11_1_17%in%c( '1','2','3') | muj$P11_1_18%in%c( '1','2','3') |
muj$P11_1_19%in%c( '1','2','3') | muj$P11_1_20%in%c( '1','2','3') |
muj$P14_1_1%in%c( '1','2','3') | muj$P14_1_2%in%c( '1','2','3') |
muj$P14_1_3%in%c( '1','2','3') | muj$P14_1_4%in%c( '1','2','3') |
muj$P14_1_5%in%c( '1','2','3') | muj$P14_1_6%in%c( '1','2','3') |
muj$P14_1_7%in%c( '1','2','3') | muj$P14_1_8%in%c( '1','2','3') |
muj$P14_1_9%in%c( '1','2','3') | muj$P14_1_10%in%c( '1','2','3') |
muj$P14_1_11%in%c( '1','2','3') | muj$P14_1_12%in%c( '1','2','3') |
muj$P14_1_13%in%c( '1','2','3') | muj$P14_1_14%in%c( '1','2','3') |
muj$P14_1_15%in%c( '1','2','3') | muj$P14_1_16%in%c( '1','2','3') |
muj$P14_1_17%in%c( '1','2','3') | muj$P14_1_18%in%c( '1','2','3') |
muj$P14_1_19%in%c( '1','2','3') | muj$P14_1_20%in%c( '1','2','3') |
muj$P14_1_21%in%c( '1','2','3') | muj$P14_1_22%in%c( '1','2','3') |
muj$P14_1_23AB%in%c( '1','2','3') | muj$P14_1_24AB%in%c( '1','2','3') |
muj$P14_1_25%in%c( '1','2','3') | muj$P14_1_26%in%c( '1','2','3') |
muj$P14_1_27%in%c( '1','2','3') | muj$P14_1_28%in%c( '1','2','3') |
muj$P14_1_29%in%c( '1','2','3') | muj$P14_1_30%in%c( '1','2','3') |
muj$P14_1_31%in%c( '1','2','3') | muj$P14_1_32%in%c( '1','2','3') |
muj$P14_1_33%in%c( '1','2','3') | muj$P14_1_34%in%c( '1','2','3') |
muj$P14_1_35AB%in%c( '1','2','3') | muj$P14_1_36AB%in%c( '1','2','3') |
muj$P14_1_37AB%in%c( '1','2','3') | muj$P14_1_38AB%in%c( '1','2','3')),1,0)
muj$pob_muj <- 1
# Defining the sample
disenio <- svydesign(id=~UPM_DIS, strata=~EST_DIS, data=muj, weights=~FAC_MUJ, nest=TRUE)
# calculating violence estimator
# National
n_vtot_lv_con <- svyratio(~vtot_lv_con, denominator=~pob_muj, disenio, na.rm = TRUE)
# state
e_vtot_lv_con <- svyby(~vtot_lv_con, denominator=~pob_muj, by=~CVE_ENT, disenio,
svyratio, na.rm = TRUE)
# Estimations
# National
est_n_vtot_lv_con <- n_vtot_lv_con[[1]]*100
se_n_vtot_lv_con <- SE(n_vtot_lv_con)*100
cv_n_vtot_lv_con <- cv(n_vtot_lv_con)*100
li_n_vtot_lv_con <- confint(n_vtot_lv_con,level=0.90)[1,1]*100
ls_n_vtot_lv_con <- confint(n_vtot_lv_con,level=0.90)[1,2]*100
# National
est_e_vtot_lv_con <- e_vtot_lv_con[[2]]*100
se_e_vtot_lv_con <- SE(e_vtot_lv_con)*100
cv_e_vtot_lv_con <- cv(e_vtot_lv_con)*100
li_e_vtot_lv_con <- confint(e_vtot_lv_con,level=0.90)[,1]*100
ls_e_vtot_lv_con <- confint(e_vtot_lv_con,level=0.90)[,2]*100
# Defining values by state
state<-c("Estados Unidos Mexicanos", "Aguascalientes", "Baja California", "Baja California Sur",
"Campeche", "Coahuila de Zaragoza", "Colima", "Chiapas", "Chihuahua", "Ciudad de México",
"Durango", "Guanajuato", "Guerrero", "Hidalgo", "Jalisco", "Estado de México",
"Michoacán de Ocampo", "Morelos", "Nayarit", "Nuevo León", "Oaxaca", "Puebla", "Querétaro",
"Quintana Roo", "San Luis Potosí", "Sinaloa", "Sonora", "Tabasco", "Tamaulipas", "Tlaxcala",
"Veracruz de Ignacio de la Llave", "Yucatán", "Zacatecas")
est_vtot_lv_con <- as.data.frame(cbind(state,
est_vtot_lv_con= c(est_n_vtot_lv_con, est_e_vtot_lv_con)))
se_vtot_lv_con <- as.data.frame(cbind(state,
se_vtot_lv_con= c(se_n_vtot_lv_con, se_e_vtot_lv_con)))
cv_vtot_lv_con <- as.data.frame(cbind(state,
cv_vtot_lv_con= c(cv_n_vtot_lv_con, cv_e_vtot_lv_con)))
lim_vtot_lv_con <- as.data.frame(cbind(state,
linf_vtot_lv_con= c(li_n_vtot_lv_con, li_e_vtot_lv_con),
lsup_vtot_lv_con= c(ls_n_vtot_lv_con, ls_e_vtot_lv_con)))
row.names(est_vtot_lv_con) <- row.names(se_vtot_lv_con) <- row.names(cv_vtot_lv_con) <- row.names(lim_vtot_lv_con) <- NULL
list_of_datasets <- list("Estimaciones" = est_vtot_lv_con,
"std err" = se_vtot_lv_con,
"Coef var" = cv_vtot_lv_con,
"Int Conf" = lim_vtot_lv_con)
write.csv(list_of_datasets, file = "violence.csv")
##Calculate emotional violence
P7_6 <- paste0("P7_6_", 1:18)
P7_8 <- paste0("P7_8_", 1:18)
P8_9 <- paste0("P8_9_", 1:19)
P8_11 <- paste0("P8_11_", 1:19)
P8_8 <- paste0("P8_8_", 1:9)
P9_1 <- paste0("P9_1_", 1:16)
P9_3 <- paste0("P9_3_", 1:16)
P11_1 <- paste0("P11_1_", 1:20)
P14_1 <- paste0("P14_1_", 1:38)
P14_1[c(23, 24, 35:38)] <- paste0(P14_1[c(23, 24, 35:38)], "AB")
P14_3 <- paste0("P14_3_", 1:38)
P14_3[c(23, 24, 35:38)] <- paste0(P14_3[c(23, 24, 35:38)], "AB")
variables <- c(
"UPM_DIS", "EST_DIS", "FAC_MUJ", "CVE_ENT", "T_INSTRUM", "P7_1", "P7_2", P7_6, P7_8,
"P8_1", "P8_2", "P8_3_1_1", "P8_3_1_2", "P8_3_2_1", "P8_3_2_2", "P8_3_2_3",
"P8_4", "P8_5", P8_9, P8_11, P8_8, P9_1, P9_3, P11_1, "P13_C_1", P14_1, P14_3
)
#Emotional violence questions
muj$vpsi_lv_con <- ifelse(
(muj$P7_6_4%in%'1' | muj$P7_6_9%in%'1' | muj$P7_6_13%in%'1' |
muj$P7_6_16%in%'1' | muj$P7_6_18%in%'1' | muj$P8_9_2 %in%'1' |
muj$P8_9_7%in%'1' | muj$P8_9_11%in%'1' | muj$P8_9_12%in%'1' |
muj$P8_9_17%in%'1' | muj$P8_9_18%in%'1' | muj$P9_1_2%in%'1' |
muj$P9_1_3%in%'1' | muj$P9_1_11%in%'1' | muj$P9_1_15%in%'1' |
muj$P11_1_1%in%c( '1','2','3') | muj$P11_1_6%in%c( '1','2','3') |
muj$P11_1_7%in%c( '1','2','3') | muj$P11_1_12%in%c( '1','2','3') |
muj$P11_1_14%in%c( '1','2','3') | muj$P11_1_17%in%c( '1','2','3') |
muj$P11_1_20%in%c( '1','2','3') | muj$P14_1_10%in%c( '1','2','3') |
muj$P14_1_11%in%c( '1','2','3') | muj$P14_1_12%in%c( '1','2','3') |
muj$P14_1_13%in%c( '1','2','3') | muj$P14_1_14%in%c( '1','2','3') |
muj$P14_1_15%in%c( '1','2','3') | muj$P14_1_16%in%c( '1','2','3') |
muj$P14_1_17%in%c( '1','2','3') | muj$P14_1_18%in%c( '1','2','3') |
muj$P14_1_19%in%c( '1','2','3') | muj$P14_1_20%in%c( '1','2','3') |
muj$P14_1_21%in%c( '1','2','3') | muj$P14_1_22%in%c( '1','2','3') |
muj$P14_1_23AB%in%c( '1','2','3') | muj$P14_1_24AB%in%c( '1','2','3') |
muj$P14_1_31%in%c( '1','2','3')),1,0)
muj$pob_muj <- 1
disenio <-
svydesign(id=~UPM_DIS, strata=~EST_DIS, data=muj, weights=~FAC_MUJ, nest=TRUE)
n_vpsi_lv_con <- svyratio(~vpsi_lv_con, denominator=~pob_muj, disenio, na.rm = TRUE)
e_vpsi_lv_con <- svyby(~vpsi_lv_con, denominator=~pob_muj, by=~CVE_ENT, disenio,
svyratio, na.rm = TRUE)
# National
est_n_vpsi_lv_con <- n_vpsi_lv_con[[1]]*100
se_n_vpsi_lv_con <- SE(n_vpsi_lv_con)*100
cv_n_vpsi_lv_con <- cv(n_vpsi_lv_con)*100
li_n_vpsi_lv_con <- confint(n_vpsi_lv_con,level=0.90)[1,1]*100
ls_n_vpsi_lv_con <- confint(n_vpsi_lv_con,level=0.90)[1,2]*100
# National
est_e_vpsi_lv_con <- e_vpsi_lv_con[[2]]*100
se_e_vpsi_lv_con <- SE(e_vpsi_lv_con)*100
cv_e_vpsi_lv_con <- cv(e_vpsi_lv_con)*100
li_e_vpsi_lv_con <- confint(e_vpsi_lv_con,level=0.90)[,1]*100
ls_e_vpsi_lv_con <- confint(e_vpsi_lv_con,level=0.90)[,2]*100
# states
state<-c("Estados Unidos Mexicanos", "Aguascalientes", "Baja California", "Baja California Sur",
"Campeche", "Coahuila de Zaragoza", "Colima", "Chiapas", "Chihuahua", "Ciudad de México",
"Durango", "Guanajuato", "Guerrero", "Hidalgo", "Jalisco", "Estado de México",
"Michoacán de Ocampo", "Morelos", "Nayarit", "Nuevo León", "Oaxaca", "Puebla", "Querétaro",
"Quintana Roo", "San Luis Potosí", "Sinaloa", "Sonora", "Tabasco", "Tamaulipas", "Tlaxcala",
"Veracruz de Ignacio de la Llave", "Yucatán", "Zacatecas")
est_vpsi_lv_con <- as.data.frame(cbind(state,
est_vpsi_lv_con= c(est_n_vpsi_lv_con, est_e_vpsi_lv_con)))
se_vpsi_lv_con <- as.data.frame(cbind(state,
se_vpsi_lv_con= c(se_n_vpsi_lv_con, se_e_vpsi_lv_con)))
cv_vpsi_lv_con <- as.data.frame(cbind(state,
cv_vpsi_lv_con= c(cv_n_vpsi_lv_con, cv_e_vpsi_lv_con)))
lim_vpsi_lv_con <- as.data.frame(cbind(state,
linf_vpsi_lv_con= c(li_n_vpsi_lv_con, li_e_vpsi_lv_con),
lsup_vpsi_lv_con= c(ls_n_vpsi_lv_con, ls_e_vpsi_lv_con)))
row.names(est_vpsi_lv_con) <- row.names(se_vpsi_lv_con) <- row.names(cv_vpsi_lv_con) <-
row.names(lim_vpsi_lv_con) <- NULL
list_of_datasets <- list("Estimaciones" = est_vpsi_lv_con,
"Error Estandar" = se_vpsi_lv_con)
write.csv(list_of_datasets, file = "emotional_violence.csv")
'tiv <- data.frame(TB_SEC_IVaVD)\nwrite.csv(data,"C:/Users/valer/Desktop/tiv_clean.csv", row.names = TRUE)\ntiv <- data.frame(TB_SEC_IVaVD)\ndata_new <- tiv[ , colSums(is.na(tiv)) < nrow(tiv)]\ndata <- data_new[vapply(data_new, function(x) length(unique(x)) > 1, logical(1L))]\n\nprint(TVIV$P1_2)\n#Variables that hold the answers we want to calculate\nP7_6 <- paste0("P7_6_", 1:18)\nP7_8 <- paste0("P7_8_", 1:18) #Academic\nP8_9 <- paste0("P8_9_", 1:19)\nP8_11 <- paste0("P8_11_", 1:19) # Career\nP8_8 <- paste0("P8_8_", 1:9) # Discrimination\nP9_1 <- paste0("P9_1_", 1:16)\nP9_3 <- paste0("P9_3_", 1:16) # community\nP11_1 <- paste0("P11_1_", 1:20) # Family\nP14_1 <- paste0("P14_1_", 1:38)\nP14_1[c(23, 24, 35:38)] <- paste0(P14_1[c(23, 24, 35:38)], "AB") # Relationship\nP14_3 <- paste0("P14_3_", 1:38)\nP14_3[c(23, 24, 35:38)] <- paste0(P14_3[c(23, 24, 35:38)], "AB") # Relationship\n\nvariables <- c(\n "UPM_DIS", "EST_DIS", "FAC_MUJ", "CVE_ENT", "T_INSTRUM", "P7_1", "P7_2", P7_6, P7_8,\n "P8_1", "P8_2", "P8_3_1_1", "P8_3_1_2", "P8_3_2_1", "P8_3_2_2", "P8_3_2_3",\n "P8_4", "P8_5", P8_9, P8_11, P8_8, P9_1, P9_3, P11_1, "P13_C_1", P14_1, P14_3\n)\n\n#collecting question answers\nmuj <- TB_SEC_IVaVD[, variables]\nmuj$vtot_lv_con <- ifelse(\n(muj$P7_6_1%in%\'1\' | muj$P7_6_2%in%\'1\' | muj$P7_6_3%in%\'1\' | \n muj$P7_6_4%in%\'1\' | muj$P7_6_5%in%\'1\' | muj$P7_6_6%in%\'1\' | \n muj$P7_6_7%in%\'1\' | muj$P7_6_8%in%\'1\' | muj$P7_6_9%in%\'1\' | \n muj$P7_6_10%in%\'1\' | muj$P7_6_11%in%\'1\' | muj$P7_6_12%in%\'1\' | \n muj$P7_6_13%in%\'1\' | muj$P7_6_14%in%\'1\' | muj$P7_6_15%in%\'1\' | \n muj$P7_6_16%in%\'1\' | muj$P7_6_17%in%\'1\' | muj$P7_6_18%in%\'1\' |\n muj$P8_3_1_1%in%\'1\' | muj$P8_3_1_2%in%\'1\' | muj$P8_3_2_1%in%\'1\' | \n muj$P8_3_2_2%in%\'1\' | muj$P8_3_2_3%in%\'1\' | muj$P8_8_1%in%\'1\' | \n muj$P8_8_2%in%\'1\' | muj$P8_8_3%in%\'1\' | muj$P8_8_4%in%\'1\' | \n muj$P8_8_5%in%\'1\' | muj$P8_8_6%in%\'1\' | muj$P8_8_7%in%\'1\' | \n muj$P8_8_8%in%\'1\' | muj$P8_8_9%in%\'1\' | muj$P8_9_1%in%\'1\' | \n muj$P8_9_2%in%\'1\' | muj$P8_9_3%in%\'1\' | muj$P8_9_4%in%\'1\' | \n muj$P8_9_5%in%\'1\' | muj$P8_9_6%in%\'1\' | muj$P8_9_7%in%\'1\' | \n muj$P8_9_8%in%\'1\' | muj$P8_9_9%in%\'1\' | muj$P8_9_10%in%\'1\' | \n muj$P8_9_11%in%\'1\' | muj$P8_9_12%in%\'1\' | muj$P8_9_13%in%\'1\' | \n muj$P8_9_14%in%\'1\' | muj$P8_9_15%in%\'1\' | muj$P8_9_16%in%\'1\' | \n muj$P8_9_17%in%\'1\' | muj$P8_9_18%in%\'1\' | muj$P8_9_19%in%\'1\' | \n muj$P9_1_1%in%\'1\' | muj$P9_1_2%in%\'1\' | muj$P9_1_3%in%\'1\' | \n muj$P9_1_4%in%\'1\' | muj$P9_1_5%in%\'1\' | muj$P9_1_6%in%\'1\' | \n muj$P9_1_7%in%\'1\' | muj$P9_1_8%in%\'1\' | muj$P9_1_9%in%\'1\' | \n muj$P9_1_10%in%\'1\' | muj$P9_1_11%in%\'1\' | muj$P9_1_12%in%\'1\' | \n muj$P9_1_13%in%\'1\' | muj$P9_1_14%in%\'1\' | muj$P9_1_15%in%\'1\' | \n muj$P9_1_16%in%\'1\' | \n muj$P11_1_1%in%c( \'1\',\'2\',\'3\') | muj$P11_1_2%in%c( \'1\',\'2\',\'3\') | \n muj$P11_1_3%in%c( \'1\',\'2\',\'3\') | muj$P11_1_4%in%c( \'1\',\'2\',\'3\') | \n muj$P11_1_5%in%c( \'1\',\'2\',\'3\') | muj$P11_1_6%in%c( \'1\',\'2\',\'3\') | \n muj$P11_1_7%in%c( \'1\',\'2\',\'3\') | muj$P11_1_8%in%c( \'1\',\'2\',\'3\') | \n muj$P11_1_9%in%c( \'1\',\'2\',\'3\') | muj$P11_1_10%in%c( \'1\',\'2\',\'3\') | \n muj$P11_1_11%in%c( \'1\',\'2\',\'3\') | muj$P11_1_12%in%c( \'1\',\'2\',\'3\') | \n muj$P11_1_13%in%c( \'1\',\'2\',\'3\') | muj$P11_1_14%in%c( \'1\',\'2\',\'3\') | \n muj$P11_1_15%in%c( \'1\',\'2\',\'3\') | muj$P11_1_16%in%c( \'1\',\'2\',\'3\') | \n muj$P11_1_17%in%c( \'1\',\'2\',\'3\') | muj$P11_1_18%in%c( \'1\',\'2\',\'3\') | \n muj$P11_1_19%in%c( \'1\',\'2\',\'3\') | muj$P11_1_20%in%c( \'1\',\'2\',\'3\') | \n muj$P14_1_1%in%c( \'1\',\'2\',\'3\') | muj$P14_1_2%in%c( \'1\',\'2\',\'3\') | \n muj$P14_1_3%in%c( \'1\',\'2\',\'3\') | muj$P14_1_4%in%c( \'1\',\'2\',\'3\') | \n muj$P14_1_5%in%c( \'1\',\'2\',\'3\') | muj$P14_1_6%in%c( \'1\',\'2\',\'3\') | \n muj$P14_1_7%in%c( \'1\',\'2\',\'3\') | muj$P14_1_8%in%c( \'1\',\'2\',\'3\') | \n muj$P14_1_9%in%c( \'1\',\'2\',\'3\') | muj$P14_1_10%in%c( \'1\',\'2\',\'3\') | \n muj$P14_1_11%in%c( \'1\',\'2\',\'3\') | muj$P14_1_12%in%c( \'1\',\'2\',\'3\') | \n muj$P14_1_13%in%c( \'1\',\'2\',\'3\') | muj$P14_1_14%in%c( \'1\',\'2\',\'3\') | \n muj$P14_1_15%in%c( \'1\',\'2\',\'3\') | muj$P14_1_16%in%c( \'1\',\'2\',\'3\') | \n muj$P14_1_17%in%c( \'1\',\'2\',\'3\') | muj$P14_1_18%in%c( \'1\',\'2\',\'3\') | \n muj$P14_1_19%in%c( \'1\',\'2\',\'3\') | muj$P14_1_20%in%c( \'1\',\'2\',\'3\') | \n muj$P14_1_21%in%c( \'1\',\'2\',\'3\') | muj$P14_1_22%in%c( \'1\',\'2\',\'3\') | \n muj$P14_1_23AB%in%c( \'1\',\'2\',\'3\') | muj$P14_1_24AB%in%c( \'1\',\'2\',\'3\') | \n muj$P14_1_25%in%c( \'1\',\'2\',\'3\') | muj$P14_1_26%in%c( \'1\',\'2\',\'3\') | \n muj$P14_1_27%in%c( \'1\',\'2\',\'3\') | muj$P14_1_28%in%c( \'1\',\'2\',\'3\') | \n muj$P14_1_29%in%c( \'1\',\'2\',\'3\') | muj$P14_1_30%in%c( \'1\',\'2\',\'3\') | \n muj$P14_1_31%in%c( \'1\',\'2\',\'3\') | muj$P14_1_32%in%c( \'1\',\'2\',\'3\') | \n muj$P14_1_33%in%c( \'1\',\'2\',\'3\') | muj$P14_1_34%in%c( \'1\',\'2\',\'3\') | \n muj$P14_1_35AB%in%c( \'1\',\'2\',\'3\') | muj$P14_1_36AB%in%c( \'1\',\'2\',\'3\') | \n muj$P14_1_37AB%in%c( \'1\',\'2\',\'3\') | muj$P14_1_38AB%in%c( \'1\',\'2\',\'3\')),1,0)\nmuj$pob_muj <- 1 \n# Defining the sample\ndisenio <- svydesign(id=~UPM_DIS, strata=~EST_DIS, data=muj, weights=~FAC_MUJ, nest=TRUE) \n# calculating violence estimator\n# National\nn_vtot_lv_con <- svyratio(~vtot_lv_con, denominator=~pob_muj, disenio, na.rm = TRUE) \n# state\ne_vtot_lv_con <- svyby(~vtot_lv_con, denominator=~pob_muj, by=~CVE_ENT, disenio, \nsvyratio, na.rm = TRUE) \n# Estimations\n# National\nest_n_vtot_lv_con <- n_vtot_lv_con[[1]]*100\nse_n_vtot_lv_con <- SE(n_vtot_lv_con)*100\ncv_n_vtot_lv_con <- cv(n_vtot_lv_con)*100\nli_n_vtot_lv_con <- confint(n_vtot_lv_con,level=0.90)[1,1]*100\nls_n_vtot_lv_con <- confint(n_vtot_lv_con,level=0.90)[1,2]*100\n# National\nest_e_vtot_lv_con <- e_vtot_lv_con[[2]]*100\nse_e_vtot_lv_con <- SE(e_vtot_lv_con)*100\ncv_e_vtot_lv_con <- cv(e_vtot_lv_con)*100\nli_e_vtot_lv_con <- confint(e_vtot_lv_con,level=0.90)[,1]*100\nls_e_vtot_lv_con <- confint(e_vtot_lv_con,level=0.90)[,2]*100\n# Defining values by state\nstate<-c("Estados Unidos Mexicanos", "Aguascalientes", "Baja California", "Baja California Sur",\n "Campeche", "Coahuila de Zaragoza", "Colima", "Chiapas", "Chihuahua", "Ciudad de México", \n "Durango", "Guanajuato", "Guerrero", "Hidalgo", "Jalisco", "Estado de México", \n "Michoacán de Ocampo", "Morelos", "Nayarit", "Nuevo León", "Oaxaca", "Puebla", "Querétaro",\n "Quintana Roo", "San Luis Potosí", "Sinaloa", "Sonora", "Tabasco", "Tamaulipas", "Tlaxcala", \n "Veracruz de Ignacio de la Llave", "Yucatán", "Zacatecas") \nest_vtot_lv_con <- as.data.frame(cbind(state, \n est_vtot_lv_con= c(est_n_vtot_lv_con, est_e_vtot_lv_con)))\nse_vtot_lv_con <- as.data.frame(cbind(state, \n se_vtot_lv_con= c(se_n_vtot_lv_con, se_e_vtot_lv_con)))\ncv_vtot_lv_con <- as.data.frame(cbind(state, \n cv_vtot_lv_con= c(cv_n_vtot_lv_con, cv_e_vtot_lv_con)))\nlim_vtot_lv_con <- as.data.frame(cbind(state, \n linf_vtot_lv_con= c(li_n_vtot_lv_con, li_e_vtot_lv_con),\n lsup_vtot_lv_con= c(ls_n_vtot_lv_con, ls_e_vtot_lv_con)))\nrow.names(est_vtot_lv_con) <- row.names(se_vtot_lv_con) <- row.names(cv_vtot_lv_con) <- row.names(lim_vtot_lv_con) <- NULL\nlist_of_datasets <- list("Estimaciones" = est_vtot_lv_con, \n "std err" = se_vtot_lv_con, \n "Coef var" = cv_vtot_lv_con, \n "Int Conf" = lim_vtot_lv_con)\nwrite.csv(list_of_datasets, file = "violence.csv")\n\n##Calculate emotional violence\n\nP7_6 <- paste0("P7_6_", 1:18)\nP7_8 <- paste0("P7_8_", 1:18)\nP8_9 <- paste0("P8_9_", 1:19)\nP8_11 <- paste0("P8_11_", 1:19)\nP8_8 <- paste0("P8_8_", 1:9)\nP9_1 <- paste0("P9_1_", 1:16)\nP9_3 <- paste0("P9_3_", 1:16)\nP11_1 <- paste0("P11_1_", 1:20)\nP14_1 <- paste0("P14_1_", 1:38)\nP14_1[c(23, 24, 35:38)] <- paste0(P14_1[c(23, 24, 35:38)], "AB")\nP14_3 <- paste0("P14_3_", 1:38)\nP14_3[c(23, 24, 35:38)] <- paste0(P14_3[c(23, 24, 35:38)], "AB")\nvariables <- c(\n "UPM_DIS", "EST_DIS", "FAC_MUJ", "CVE_ENT", "T_INSTRUM", "P7_1", "P7_2", P7_6, P7_8,\n "P8_1", "P8_2", "P8_3_1_1", "P8_3_1_2", "P8_3_2_1", "P8_3_2_2", "P8_3_2_3",\n "P8_4", "P8_5", P8_9, P8_11, P8_8, P9_1, P9_3, P11_1, "P13_C_1", P14_1, P14_3\n)\n#Emotional violence questions\nmuj$vpsi_lv_con <- ifelse(\n (muj$P7_6_4%in%\'1\' | muj$P7_6_9%in%\'1\' | muj$P7_6_13%in%\'1\' |\n muj$P7_6_16%in%\'1\' | muj$P7_6_18%in%\'1\' | muj$P8_9_2 %in%\'1\' | \n muj$P8_9_7%in%\'1\' | muj$P8_9_11%in%\'1\' | muj$P8_9_12%in%\'1\' | \n muj$P8_9_17%in%\'1\' | muj$P8_9_18%in%\'1\' | muj$P9_1_2%in%\'1\' | \n muj$P9_1_3%in%\'1\' | muj$P9_1_11%in%\'1\' | muj$P9_1_15%in%\'1\' | \n muj$P11_1_1%in%c( \'1\',\'2\',\'3\') | muj$P11_1_6%in%c( \'1\',\'2\',\'3\') | \n muj$P11_1_7%in%c( \'1\',\'2\',\'3\') | muj$P11_1_12%in%c( \'1\',\'2\',\'3\') | \n muj$P11_1_14%in%c( \'1\',\'2\',\'3\') | muj$P11_1_17%in%c( \'1\',\'2\',\'3\') | \n muj$P11_1_20%in%c( \'1\',\'2\',\'3\') | muj$P14_1_10%in%c( \'1\',\'2\',\'3\') | \n muj$P14_1_11%in%c( \'1\',\'2\',\'3\') | muj$P14_1_12%in%c( \'1\',\'2\',\'3\') | \n muj$P14_1_13%in%c( \'1\',\'2\',\'3\') | muj$P14_1_14%in%c( \'1\',\'2\',\'3\') | \n muj$P14_1_15%in%c( \'1\',\'2\',\'3\') | muj$P14_1_16%in%c( \'1\',\'2\',\'3\') | \n muj$P14_1_17%in%c( \'1\',\'2\',\'3\') | muj$P14_1_18%in%c( \'1\',\'2\',\'3\') | \n muj$P14_1_19%in%c( \'1\',\'2\',\'3\') | muj$P14_1_20%in%c( \'1\',\'2\',\'3\') | \n muj$P14_1_21%in%c( \'1\',\'2\',\'3\') | muj$P14_1_22%in%c( \'1\',\'2\',\'3\') | \n muj$P14_1_23AB%in%c( \'1\',\'2\',\'3\') | muj$P14_1_24AB%in%c( \'1\',\'2\',\'3\') | \n\nmuj$P14_1_31%in%c( \'1\',\'2\',\'3\')),1,0)\nmuj$pob_muj <- 1 \ndisenio <- \n svydesign(id=~UPM_DIS, strata=~EST_DIS, data=muj, weights=~FAC_MUJ, nest=TRUE) \nn_vpsi_lv_con <- svyratio(~vpsi_lv_con, denominator=~pob_muj, disenio, na.rm = TRUE) \n\ne_vpsi_lv_con <- svyby(~vpsi_lv_con, denominator=~pob_muj, by=~CVE_ENT, disenio, \n svyratio, na.rm = TRUE) \n# National\nest_n_vpsi_lv_con <- n_vpsi_lv_con[[1]]*100\nse_n_vpsi_lv_con <- SE(n_vpsi_lv_con)*100\ncv_n_vpsi_lv_con <- cv(n_vpsi_lv_con)*100\nli_n_vpsi_lv_con <- confint(n_vpsi_lv_con,level=0.90)[1,1]*100\nls_n_vpsi_lv_con <- confint(n_vpsi_lv_con,level=0.90)[1,2]*100\n# National\nest_e_vpsi_lv_con <- e_vpsi_lv_con[[2]]*100\nse_e_vpsi_lv_con <- SE(e_vpsi_lv_con)*100\ncv_e_vpsi_lv_con <- cv(e_vpsi_lv_con)*100\nli_e_vpsi_lv_con <- confint(e_vpsi_lv_con,level=0.90)[,1]*100\nls_e_vpsi_lv_con <- confint(e_vpsi_lv_con,level=0.90)[,2]*100\n# states\nstate<-c("Estados Unidos Mexicanos", "Aguascalientes", "Baja California", "Baja California Sur", \n "Campeche", "Coahuila de Zaragoza", "Colima", "Chiapas", "Chihuahua", "Ciudad de México", \n "Durango", "Guanajuato", "Guerrero", "Hidalgo", "Jalisco", "Estado de México", \n "Michoacán de Ocampo", "Morelos", "Nayarit", "Nuevo León", "Oaxaca", "Puebla", "Querétaro", \n "Quintana Roo", "San Luis Potosí", "Sinaloa", "Sonora", "Tabasco", "Tamaulipas", "Tlaxcala", \n "Veracruz de Ignacio de la Llave", "Yucatán", "Zacatecas") \nest_vpsi_lv_con <- as.data.frame(cbind(state, \nest_vpsi_lv_con= c(est_n_vpsi_lv_con, est_e_vpsi_lv_con)))\nse_vpsi_lv_con <- as.data.frame(cbind(state, \n se_vpsi_lv_con= c(se_n_vpsi_lv_con, se_e_vpsi_lv_con)))\ncv_vpsi_lv_con <- as.data.frame(cbind(state, \n cv_vpsi_lv_con= c(cv_n_vpsi_lv_con, cv_e_vpsi_lv_con)))\nlim_vpsi_lv_con <- as.data.frame(cbind(state, \n linf_vpsi_lv_con= c(li_n_vpsi_lv_con, li_e_vpsi_lv_con),\n lsup_vpsi_lv_con= c(ls_n_vpsi_lv_con, ls_e_vpsi_lv_con)))\nrow.names(est_vpsi_lv_con) <- row.names(se_vpsi_lv_con) <- row.names(cv_vpsi_lv_con) <- \n row.names(lim_vpsi_lv_con) <- NULL\nlist_of_datasets <- list("Estimaciones" = est_vpsi_lv_con, \n "Error Estandar" = se_vpsi_lv_con)\nwrite.csv(list_of_datasets, file = "emotional_violence.csv")\n'