#Loading orginal data set from the Encuesta Nacional Sobre La Dinámica de Las Relaciones En Los Hogares 2003, specifically the nacionalm2.csv dataframe
ogdata2003 = read.csv("nacionalm2.csv")

#Creating a subset of variables that look at areas of domestic abuse or intimate partner violence
mexdata2003=subset(ogdata2003, select=c(HABLAR1, AVERGO1, DESTRU1, AMENA1, ENOJO1, ENCERA1, ENGANA1, MIEDO1, CONTRA1, IGNORA1, ARMA1, MATAR1, ERGA1, ECOTA1, ENOGA1, EGADIN1, EPTRA1, EPTRE1, EEMJP1, EAM1, EPAT1, EAOB1, EGOLM1, ETHOA1, EACU1, EDISA1, EEXSE1, EOBSE2, EFUSE3, ENCONF4))
#SPECIFICATION OF COLUMNS: (All questions that the columns represent refer to a timeframe within the last 12 months. In the dataset for all the columns except ENCONF4, a response of 1=Yes, a response of 2=No, and a response of 3=No Response. For ENCONF4, the presence of a 4 means that woman did not inform any source about a form of violence they experienced while a lack of value means that woman informed some source about a form of violence they experienced or did not respond) 
#HABLAR1 responds to the question: le ha dejado de hablar? 
#AVERGO1 responds to the question: la ha avergonzado, menospreciado, le ha dicho que es fea o la ha comparado con otras mujeres?
#DESTRU1 responds to the question: ha destruido, tirado o escondido cosas de usted o del hogar?
#AMENA1 responds to the question: la ha amenazado con irse, dañarla, quitarle a los hijos o correrla?
#ENOJO1 responds to the question: se ha enojado mucho porque no está listo el quehacer, porque la comida no está como él quiere o cree que usted no cumplió con sus obligaciones?
#ENCERA1 responds to the question: la ha encerrado, le ha prohibido salir o que la visiten?
#ENGANA1 responds to the question: le ha dicho que usted lo engaña?
#MIEDO1 responds to the question: le ha hecho sentir miedo?
#CONTRA1 responds to the question: ha hecho que los hijos o parientes se pongan contra usted?
#IGNORA1 responds to the question: la ignora, no la toma en cuenta o no le brinda cariño?
#ARMA1 responds to the question: la ha amenazado con alguna arma (cuchillo, navaja, pistola o rifle)?
#MATAR1 responds to the question: la ha amenazado con matarla, matarse él o matar a los niños?
#ERGA1 responds to the question: le ha reclamado cómo gasta usted el dinero?
#ECOTA1 responds to the question: aunque tenga dinero ha sido codo o tacaño con los gastos de la casa?
#ENOGA1 responds to the question: le ha amenazado que no le va a dar gasto o no le da?
#EGADIN1 responds to the question: se ha gastado el dinero que se necesita para la casa?
#EPTRA1 responds to the question: se ha adueñado o le ha quitado dinero o bienes (cosas, terrenos, animales, etc.)?
#EPTRE1 responds to the question: le ha prohibido trabajar o estudiar?
#EEMJP1 responds to the question: la ha empujado o le ha jalado el pelo?
#EAM1 responds to the question: la ha amarrado?
#EPAT1 responds to the question: la ha pateado?
#EAOB1 responds to the question: le ha aventado algún objeto?
#EGOLM1 responds to the question: la ha golpeado con las manos o con algún objeto?
#ETHOA1 responds to the question: la ha tratado de ahorcar o asfixiar?
#EACU1 responds to the question: la ha agredido con cuchillo o navaja?
#EDISA1 responds to the question: le ha disparado con una arma?
#EEXSE1 responds to the question: le ha exigido tener relaciones sexuales aunque usted no quiera?
#EOBSE2 responds to the question: la ha obligado a hacer actos sexuales que a usted no le parecen?
#EFUSE3 responds to the question: ha usado su fuerza física para obligarla a tener relaciones sexuales?
#ENCONF4 responds to the question: Cuando ha sucedido algún conflicto con su esposo (pareja), ¿ha recurrido...
#Creating dataset for those who experienced at least one form of IPV in the last 12 months for 2003
mexdata2003_1=subset(mexdata2003, HABLAR1 == 1 | AVERGO1 == 1 | DESTRU1 == 1 | AMENA1 == 1 |ENOJO1 == 1 | ENCERA1 == 1 | ENGANA1 == 1 | MIEDO1 == 1 | CONTRA1 == 1 | IGNORA1 == 1 | ARMA1 == 1 | MATAR1 == 1 | ERGA1 == 1 | ECOTA1 == 1 | ENOGA1 == 1 | EGADIN1 == 1 | EPTRA1 == 1 | EPTRE1 == 1 | EEMJP1 == 1 | EAM1 == 1 | EPAT1 == 1 | EAOB1 == 1 | EGOLM1 == 1 | ETHOA1 == 1 | EACU1 == 1 | EDISA1 == 1 | EEXSE1 == 1 | EOBSE2 == 1 | EFUSE3 == 1)

mexdata2003_2=subset(mexdata2003, HABLAR1 == 2 & AVERGO1 == 2 & DESTRU1 == 2 & AMENA1 == 2 & ENOJO1 == 2 & ENCERA1 == 2 & ENGANA1 == 2 & MIEDO1 == 2 & CONTRA1 == 2 & IGNORA1 == 2 & ARMA1 == 2 & MATAR1 == 2 & ERGA1 == 2 & ECOTA1 == 2 & ENOGA1 == 2 & EGADIN1 == 2 & EPTRA1 == 2 & EPTRE1 == 2 & EEMJP1 == 2 & EAM1 == 2 & EPAT1 == 2 & EAOB1 == 2 & EGOLM1 == 2 & ETHOA1 == 2 & EACU1 == 2 & EDISA1 == 2 & EEXSE1 == 2 & EOBSE2 == 2 & EFUSE3 == 2)

mexdata2003_3=subset(mexdata2003, HABLAR1 == 3 & AVERGO1 == 3 & DESTRU1 == 3 & AMENA1 == 3 & ENOJO1 == 3 & ENCERA1 == 3 & ENGANA1 == 3 & MIEDO1 == 3 & CONTRA1 == 3 & IGNORA1 == 3 & ARMA1 == 3 & MATAR1 == 3 & ERGA1 == 3 & ECOTA1 == 3 & ENOGA1 == 3 & EGADIN1 == 3 & EPTRA1 == 3 & EPTRE1 == 3 & EEMJP1 == 3 & EAM1 == 3 & EPAT1 == 3 & EAOB1 == 3 & EGOLM1 == 3 & ETHOA1 == 3 & EACU1 == 3 & EDISA1 == 3 & EEXSE1 == 3 & EOBSE2 == 3 & EFUSE3 == 3)
#Providing dimensions 
dim(mexdata2003_1)
## [1] 13920    30
dim(mexdata2003_2)
## [1] 19800    30
dim(mexdata2003_3)
## [1]  1 30
#Creating a pie chart examining out of those who have experienced some form of IPV in the last 12 months, to what extent did these women tell some source, give no response, or not tell any source in 2003

slices2003=c(13920, 19800, 1)
labels2003=c("Yes", "No", "No Answer Given")
pct=round(slices2003/sum(slices2003)*100)
lbls2003=paste(labels2003, pct)
lbls2003=paste(lbls2003,"%",sep="") 
pie(slices2003,labels = lbls2003, col=rainbow(length(lbls2003)),
   main="Responses in 2003 of Mexican Women on Whether They Have Experienced At Least One Form of IPV in the Last 12 Months")

#Creating a pie chart with presented data from the Encuesta Nacional Sobre La Dinámica de Las Relaciones En Los Hogares 2006
slices2006=c(19125815, 26871684)
labels2006=c("Yes", "No")
pct_6=round(slices2006/sum(slices2006)*100)
lbls2006=paste(labels2006, pct_6)
lbls2006=paste(lbls2006,"%",sep="") 
pie(slices2006,labels = lbls2006, col=rainbow(length(lbls2006)),
   main="Responses in 2006 of Mexican Women on Whether They Have Experienced At Least One Form of IPV in the Last 12 Months")