<< This R script was submitted as replication file for the article From one participant cohort to another: Surveying inter-generational political incubation in an Indian University. A copy is available on the SAtextometry repository on GitHub.
|
Prepare the data
rm(list = ls())
#install.packages("MASS")
#install.packages("erer")
#install.packages("stargazer")
library(stargazer)
library(MASS)
library(ggplot2)
library(foreign)
library(aod)
library(ggplot2)
library(Rcpp)
library(erer)
mfx2 <- function(x,sims=1000){
set.seed(1984)
pdf <- ifelse(as.character(x$call)[3]=="binomial(link = \"probit\")",
mean(dnorm(predict(x, type = "link"))),
mean(dlogis(predict(x, type = "link"))))
pdfsd <- ifelse(as.character(x$call)[3]=="binomial(link = \"probit\")",
sd(dnorm(predict(x, type = "link"))),
sd(dlogis(predict(x, type = "link"))))
marginal.effects <- pdf*coef(x)
sim <- matrix(rep(NA,sims*length(coef(x))), nrow=sims)
for(i in 1:length(coef(x))){
sim[,i] <- rnorm(sims,coef(x)[i],diag(vcov(x)^0.5)[i])
}
pdfsim <- rnorm(sims,pdf,pdfsd)
sim.se <- pdfsim*sim
res <- cbind(marginal.effects,sd(sim.se))
colnames(res)[2] <- "standard.error"
ifelse(names(x$coefficients[1])=="(Intercept)",
return(res[2:nrow(res),]),return(res))
}
#JTdata <- read.csv("~/Desktop/untitled.csv")
JTdata <- read.dta("~/Desktop/mydata.dta")
#rm(mydataframe)
data2 <- data.frame(JTdata$Q5)
data2$PolSpec[JTdata$Q5 == 0] <- 0
data2$PolSpec[JTdata$Q5 == 6] <- 1
data2$PolSpec[JTdata$Q5 == 7] <- 2
data2$PolSpec[JTdata$Q5 == 8] <- 3
data2$PolSpec[JTdata$Q5 == 9] <- 4
data2$PolSpec[JTdata$Q5 == 10] <- 5
data2$PolSpec[JTdata$Q5 == 5] <- -1
data2$PolSpec[JTdata$Q5 == 4] <- -2
data2$PolSpec[JTdata$Q5 == 3] <- -3
data2$PolSpec[JTdata$Q5 == 2] <- -4
data2$PolSpec[JTdata$Q5 == 1] <- -5
data2$PolSpec[JTdata$Q5 == "Don't Know"] <- 0
data2$JTdata.Q5 <- NULL
data2$Radical[data2$PolSpec == 0] <- 0
data2$Radical[data2$PolSpec == 1] <- 0
data2$Radical[data2$PolSpec == 2] <- 0
data2$Radical[data2$PolSpec == -1] <- 0
data2$Radical[data2$PolSpec == -2] <- 0
data2$Radical[data2$PolSpec == 3] <- 1
data2$Radical[data2$PolSpec == -3] <- 1
data2$Radical[data2$PolSpec == -4] <- 1
data2$Radical[data2$PolSpec == -5] <- 1
data2$Radical[data2$PolSpec == 4] <- 1
data2$Radical[data2$PolSpec == 5] <- 1
data2$Radicalization <- abs(data2$PolSpec)
data2$Semester <- JTdata$Q15D
data2$Semester[JTdata$Q15D > 13] <- 13
summary(data2$Semester)
library(psych)
describe(data2$Semester)
data2$StudyYear[data2$Semester <= 2 ] <- 1
data2$StudyYear[data2$Semester == 3 | data2$Semester == 4 ] <- 2
data2$StudyYear[data2$Semester == 5 | data2$Semester == 6 ] <- 3
data2$StudyYear[data2$Semester == 7 | data2$Semester == 8 ] <- 4
data2$StudyYear[data2$Semester >= 9 ] <- 5
data2$SchoolType <- JTdata$Q15FF
data2$SchoolType2 <- NA
data2$SchoolType2[JTdata$Q15FF == "SSS - School of Social Sciences" ] <- 1
data2$SchoolType2[JTdata$Q15FF == "SIS - School of International Studies" ] <- 2
data2$SchoolType2[JTdata$Q15FF == "SL - School of Languages" ] <- 3
data2$SchoolType2[JTdata$Q15FF == "CS - Combined Schools" ] <- 4
data2$SchoolType <- as.numeric(data2$SchoolType2)
data2$SchoolType2 <- NULL
data2$Age <- JTdata$Q15C
data2$Religion <- JTdata$Q15J
data2$Religion2[JTdata$Q15J == "Hindu" ] <- 1
data2$Religion2[JTdata$Q15J == "Atheist/Agnostic" ] <- 2
data2$Religion2[JTdata$Q15J == "Muslim" ] <- 3
data2$Religion2[JTdata$Q15J == "Buddhist" ] <- 4
data2$Religion2[JTdata$Q15J == "Christian" ] <- 4
data2$Religion2[JTdata$Q15J == "Other" ] <- 4
data2$Religion2[JTdata$Q15J == "Sikh" ] <- 4
data2$Religion2[JTdata$Q15J == "Jain" ] <- 4
data2$Religion <- NULL
data2$Religion <- as.numeric(data2$Religion2)
data2$Religion2 <- NULL
data2$Hindu[data2$Religion == 1 ] <- 1
data2$Hindu[data2$Religion != 1 ] <- 0
data2$Hindu[is.na(data2$Religion) ] <- NA
data2$Atheist[data2$Religion == 2 ] <- 1
data2$Atheist[data2$Religion != 2 ] <- 0
data2$Atheist[is.na(data2$Religion) ] <- NA
data2$Female2 <- JTdata$Q15A
data2$Female <- NA
data2$Female[data2$Female2 == "Female"] <- 1
data2$Female[data2$Female2 == "Male"] <- 0
data2$Female2 <- NULL
data2$adminCat2 <- JTdata$Q15H
toString(data2$adminCat)
data2$AdminCat[data2$adminCat2 == "Unreserved" ] <- 1
data2$AdminCat[data2$adminCat2 == "OBC" ] <- 2
data2$AdminCat[data2$adminCat2 == "ST" ] <- 3
data2$AdminCat[data2$adminCat2 == "SC" ] <- 3
data2$AdminCat[data2$adminCat2 == "Foreign Student" ] <- 4
data2$AdminCat[data2$adminCat2 == "PH" ] <- 4
data2$adminCat2 <- NULL
data2$studyParent <- JTdata$Q15L
data2$StudyParent[data2$studyParent == "None of the above" ] <- 0
data2$StudyParent[data2$studyParent == "Matriculation (10th grade)" ] <- 1
data2$StudyParent[data2$studyParent == "Intermediate (10+2)" ] <- 2
data2$StudyParent[data2$studyParent == "Undergraduate" ] <- 3
data2$StudyParent[data2$studyParent == "Graduate" ] <- 4
data2$StudyParent[data2$studyParent == "Postgraduate" ] <- 5
data2$studyParent <- NULL
table(data2$StudyParent, useNA ="ifany")
data2$enrollment <- JTdata$Q15B2
data2$Enrol[data2$enrollment == "Undergraduate (BA & Btech)" ] <- 1
data2$Enrol[data2$enrollment == "Graduate (MA, Msc & MCa)" ] <- 2
data2$Enrol[data2$enrollment == "Postgraduate (Mphil, Mtech & PhD)" ] <- 3
data2$enrollment <- NULL
table(data2$Enrol, useNA ="ifany")
data2$urban <- JTdata$Q15O
data2$Urban[data2$urban == "Delhi" ] <- 1
data2$Urban[data2$urban == "Urban" ] <- 1
data2$Urban[data2$urban == "Other Mettro city" ] <- 1
data2$Urban[data2$urban == "Semi-urban" ] <- 2
data2$Urban[data2$urban == "Rural" ] <- 3
data2$Urban[data2$urban == "Small village" ] <- 3
data2$urban <- NULL
table(data2$Urban, useNA ="ifany")
data2$BirthPlace <- as.factor(JTdata$Q15U2)
#participation2 - direct scores from JT
data2$participation2 <- JTdata$IDP
data2$Participation[data2$participation2 >= 8 ] <- 4
data2$Participation[data2$participation2 == 7 ] <- 3
data2$Participation[data2$participation2 == 6 ] <- 3
data2$Participation[data2$participation2 == 5 ] <- 2
data2$Participation[data2$participation2 == 4 ] <- 2
data2$Participation[data2$participation2 == 3 ] <- 1
data2$Participation[data2$participation2 == 2 ] <- 1
data2$Participation[data2$participation2 == 1 ] <- 0
data2$Participation[data2$participation2 == 0 ] <- 0
data2$participation2 <- NULL
## 0 = No participation
## 1 = Rare/low participation
## 2 = Occasional participation
## 3 = Regular participation
## 4 = Always/daily participation
data2$polOrg2 <- JTdata$Q9
data2$Membership[data2$polOrg2 == "YES"] <- 1
data2$Membership[data2$polOrg2 == "NO"] <- 0
data2$polOrg2 <- NULL
data2$AdminCat <- factor(data2$AdminCat)
data2$Urban <- factor(data2$Urban)
data2$StudyParent <- as.numeric(data2$StudyParent)
data2$SchoolType <- factor(data2$SchoolType)
data2$Female <- factor(data2$Female)
data2$Enrol <- factor(data2$Enrol)
data2$Religion <- factor(data2$Religion)
data2$Hindu <- factor(data2$Hindu)
data2$Atheist <- factor(data2$Atheist)
data2$Age <- as.numeric(JTdata$Q15C)
View(JTdata$Q5)
xtabs(~ data2$Radical + data2$Female, data = data2)
model1 <- glm(Radical ~ Semester + AdminCat + Urban + StudyParent + SchoolType + Female + Enrol + Religion + BirthPlace, data = data2, family = "binomial")
summary(model1)
attach(data2)
data2$complete <- complete.cases(Radical, Semester, AdminCat, Urban, StudyParent, SchoolType, Female, Enrol, Religion, BirthPlace)
detach(data2)
data2.model1 <- subset(data2, data2$complete == TRUE)
# this is the same:
# data2.model1 <- data2[which(data2$complete == TRUE),]
install.packages("mfx")
library(mfx)
logitmfx(Radical ~ Semester + AdminCat + Urban + StudyParent + SchoolType + Female + Enrol + Religion + BirthPlace, data = data2)
table(data2$BirthPlace, useNA ="always")
attach(data2)
ftable(xtabs(~ Radicalization + Atheist + Female + Age, data = data2))
data2$Radicalization <- as.factor(data2$Radicalization)
model2 <- polr(Radicalization ~ Semester + AdminCat + Urban + StudyParent + SchoolType + Female + Enrol + Religion + BirthPlace, data = data2)
summary(model2)
model2.marginal <- ocME(model2, rev.dum=FALSE, digits = 6)
model2.marginal
summary(model2.marginal)
data2.numeric <- data2[, sapply(data2, is.numeric)]
stargazer(data2)
cor(data2.numeric, use="pairwise.complete.obs", method="pearson")
Results
#do file
https://drive.google.com/file/d/15sI8ki0PhMuEx_ot56fSkbPPBEzFm9Xh/view?usp=sharing
#dta file
https://drive.google.com/file/d/1ezSrrCF0CqPNLzkIK9EcLPq98YqyBvCH/view?usp=sharing