File size: 7,154 Bytes
3af64c0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#install packages
# install.packages('plyr')
# install.packages('dplyr')
# install.packages('stringr')

rm(list=ls())
#setwd() #set working directory

library('plyr');library('dplyr')
library('stringr')

#India as a whole
InSc = read.csv('india_sc_4-20-20.csv',
                stringsAsFactors = F) %>%
  rename(PopSc = Population)
InTo = read.csv('india_pop_4-20-20.csv',
                stringsAsFactors = F)
In = merge(InSc, InTo, by = 'State') %>%
  mutate(PropSc = ( PopSc %>% str_replace_all(',','') %>% as.numeric() ) /
           ( Population %>% str_replace_all(',','') %>% as.numeric()  ),
         Pop = Population %>% str_replace_all(',','') %>% as.numeric(),
         PopSc = PopSc %>% str_replace_all(',','') %>% as.numeric()) %>%
  filter(State != 'India')
rm(InSc, InTo)

#Karnataka district data
KaL = readRDS('Karnataka_district_censusdata_2-22-19.RDS')
Ka = data.frame(matrix(unlist(KaL), nrow=length(KaL), byrow=T)) 
names = Ka[1,1:13]
Ka = Ka %>% select(X27:X39)
names(Ka) = names[1,] %>% apply(1,as.character)  
Ka = Ka %>% rename(STprF = 'Scheduled Tribes (ST) %',
                   SCprF = 'Scheduled Caste (SC) %')
Ka$Pop = Ka$Population %>% as.character() %>% as.numeric()
Ka$SCpr = Ka$SCprF %>% as.character() %>% as.numeric()
Ka$SCpo = Ka$SCpr * Ka$Pop
rm(names,KaL)

#Rajasthan district data
RaL = readRDS('Rajastan_district_censusdata_2-22-19.RDS')
Ra = data.frame(matrix(unlist(RaL), nrow=length(RaL), byrow=T)) 
names = Ra[1,1:13]
Ra = Ra %>% select(X27:X39)
names(Ra) = names[1,] %>% apply(1,as.character)  
Ra = Ra %>% rename(STprF = 'Scheduled Tribes (ST) %',
                   SCprF = 'Scheduled Caste (SC) %')
Ra$Pop = Ra$Population %>% as.character() %>% as.numeric()
Ra$SCpr = Ra$SCprF %>% as.character() %>% as.numeric()
Ra$SCpo = Ra$SCpr * Ra$Pop
rm(names,RaL)

#Bihar district data
BiL = readRDS('Bihar_district_censusdata_2-22-19.RDS')
Bi = data.frame(matrix(unlist(BiL), nrow=length(BiL), byrow=T)) 
names = Bi[1,1:13]
Bi = Bi %>% select(X27:X39)
names(Bi) = names[1,] %>% apply(1,as.character)  
Bi = Bi %>% rename(STprF = 'Scheduled Tribes (ST) %',
                   SCprF = 'Scheduled Caste (SC) %')
Bi$Pop = Bi$Population %>% as.character() %>% as.numeric()
Bi$SCpr = Bi$SCprF %>% as.character() %>% as.numeric()
Bi$SCpo = Bi$SCpr * Bi$Pop
rm(names,BiL)

#Bangalore-District data
BdL = readRDS('Bangalore_District_censusdata_2-25-19.RDS')
Bd = data.frame(matrix(unlist(BdL), nrow=length(BdL), byrow=T)) 
names = Bd[1,1:13]
Bd = Bd %>% select(X27:X39)
names(Bd) = names[1,] %>% apply(1,as.character)  
Bd = Bd %>% rename(STprF = 'Scheduled Tribes (ST) %',
                   SCprF = 'Scheduled Caste (SC) %')
Bd$Pop = Bd$Population %>% as.character() %>% as.numeric()
Bd$SCpr = Bd$SCprF %>% as.character() %>% as.numeric()
Bd$SCpo = Bd$SCpr * Bd$Pop
rm(names,BdL)

#Jaipur-District data
JdL = readRDS('Jaipur_District_censusdata_2-25-19.RDS')
Jd = data.frame(matrix(unlist(JdL), nrow=length(JdL), byrow=T)) 
names = Jd[1,1:13]
Jd = Jd %>% select(X27:X39)
names(Jd) = names[1,] %>% apply(1,as.character)  
Jd = Jd %>% rename(STprF = 'Scheduled Tribes (ST) %',
                   SCprF = 'Scheduled Caste (SC) %')
Jd$Pop = Jd$Population %>% as.character() %>% as.numeric()
Jd$SCpr = Jd$SCprF %>% as.character() %>% as.numeric()
Jd$SCpo = Jd$SCpr * Jd$Pop
rm(names,JdL)

#Patna-District data
PdL = readRDS('Bihar_District_censusdata_2-25-19.RDS')
Pd = data.frame(matrix(unlist(PdL), nrow=length(PdL), byrow=T)) 
names = Pd[1,1:13]
Pd = Pd %>% select(X27:X39)
names(Pd) = names[1,] %>% apply(1,as.character)  
Pd = Pd %>% rename(STprF = 'Scheduled Tribes (ST) %',
                   SCprF = 'Scheduled Caste (SC) %')
Pd$Pop = Pd$Population %>% as.character() %>% as.numeric()
Pd$SCpr = Pd$SCprF %>% as.character() %>% as.numeric()
Pd$SCpo = Pd$SCpr * Pd$Pop
rm(names,PdL)

#BBMP data
BaL = readRDS('BBMP_ward_censusdata_2-12-19.RDS')
Ba = data.frame(matrix(unlist(BaL), nrow=length(BaL), byrow=T)) 
names = Ba[1,1:11]
Ba = Ba %>% select(X23:X33)
names(Ba) = names[1,] %>% apply(1,as.character)  
Ba = Ba %>% rename(STprF = 'Scheduled Tribes (ST) %',
                   SCprF = 'Scheduled Caste (SC) %')
Ba$Pop = Ba$Population %>% as.character() %>% as.numeric()
Ba$SCpr = Ba$SCprF %>% as.character() %>% as.numeric()
Ba$SCpo = Ba$SCpr * Ba$Pop
rm(names,BaL)

#Jaipur data
JaL = readRDS('Jaipur_ward_censusdata_2-14-19.RDS')
Ja = data.frame(matrix(unlist(JaL), nrow=length(JaL), byrow=T)) 
names = Ja[1,1:11]
Ja = Ja %>% select(X23:X33)
names(Ja) = names[1,] %>% apply(1,as.character)  
Ja = Ja %>% rename(STprF = 'Scheduled Tribes (ST) %',
                   SCprF = 'Scheduled Caste (SC) %')
Ja$Pop = Ja$Population %>% as.character() %>% as.numeric()
Ja$SCpr = Ja$SCprF %>% as.character() %>% as.numeric()
Ja$SCpo = Ja$SCpr * Ja$Pop
rm(names,JaL)

#############################################################################################################
#SEGREGATION CALCULATIONS

#DISSIMILARITY INDEX FOR INDIA AS A WHOLE (SC)
#P: total minority proportion; ti: total pop in gridspace; pi: prop minority in gridspace
P = sum(In$PopSc) / sum(In$Pop)
T0 = sum(In$Pop)
In$D = In$Pop * abs(In$PropSc - P) / (2 * T0 * P * (1 - P))
D_India = sum(In$D) #This gives final value for dissimilarity index, based on SC population, for India as a whole
rm(T0,P)

#DISSIMILARITY INDEX FOR KARNATAKA AS A WHOLE (SC)
P = sum(Ka$SCpo) / sum(Ka$Pop)
T0 = sum(Ka$Pop)
Ka$D = Ka$Pop * abs(Ka$SCpr - P) / (2 * T0 * P * (1 - P))
D_Karnataka = sum(Ka$D)
rm(T0,P)

#DISSIMILARITY INDEX FOR RAJASTHAN AS A WHOLE (SC)
P = sum(Ra$SCpo) / sum(Ra$Pop)
T0 = sum(Ra$Pop)
Ra$D = Ra$Pop * abs(Ra$SCpr - P) / (2 * T0 * P * (1 - P))
D_Rajasthan = sum(Ra$D)
rm(T0,P)

#DISSIMILARITY INDEX FOR BIHAR AS A WHOLE (SC)
P = sum(Bi$SCpo) / sum(Bi$Pop)
T0 = sum(Bi$Pop)
Bi$D = Bi$Pop * abs(Bi$SCpr - P) / (2 * T0 * P * (1 - P))
D_Bihar = sum(Bi$D)
rm(T0,P)

#DISSIMILARITY INDEX FOR BANGALORE-DISTRICT BY TEHSIL
P = sum(Bd$SCpo) / sum(Bd$Pop)
T0 = sum(Bd$Pop)
Bd$D = Bd$Pop * abs(Bd$SCpr - P) / (2 * T0 * P * (1 - P))
D_BaD = sum(Bd$D) #
rm(T0,P)

#DISSIMILARITY INDEX FOR JAIPUR-DISTRICT BY TEHSIL
P = sum(Jd$SCpo) / sum(Jd$Pop)
T0 = sum(Jd$Pop)
Jd$D = Jd$Pop * abs(Jd$SCpr - P) / (2 * T0 * P * (1 - P))
D_JaD = sum(Jd$D)
rm(T0,P)

#DISSIMILARITY INDEX FOR PATNA-DISTRICT BY TEHSIL
P = sum(Pd$SCpo) / sum(Pd$Pop)
T0 = sum(Pd$Pop)
Pd$D = Pd$Pop * abs(Pd$SCpr - P) / (2 * T0 * P * (1 - P))
D_PdD = sum(Pd$D)
rm(T0,P)

#DISSIMILARITY INDEX FOR BBMP (198) BY WARD 
P = sum(Ba$SCpo) / sum(Ba$Pop)
T0 = sum(Ba$Pop)
Ba$D = Ba$Pop * abs(Ba$SCpr - P) / (2 * T0 * P * (1 - P))
D_Bbmp = sum(Ba$D) #very dissimilar; min 0 to max 0.5
rm(T0,P)

#DISSIMILARITY INDEX FOR JAIPUR BY WARD
P = sum(Ja$SCpo) / sum(Ja$Pop)
T0 = sum(Ja$Pop)
Ja$D = Ja$Pop * abs(Ja$SCpr - P) / (2 * T0 * P * (1 - P))
D_Jaipur = sum(Ja$D)
rm(T0,P)

#********THIS IS THE BASIS FOR TABLE 3********#
data.frame(Bangalore = c(D_India, D_Karnataka, D_BaD, D_Bbmp),
           Jaipur = c(D_India, D_Rajasthan, D_JaD, D_Jaipur),
           Patna = c(D_India, D_Bihar, D_PdD, NA))
#############################################################################################################