File size: 4,589 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
#Table 4: Comparison of most common occupations for network and household data sets. 

#install packages
# install.packages('plyr')
# install.packages('dplyr')
# install.packages('tidyr')
# install.packages('ggplot2')
# install.packages('multiwayvcov')
# install.packages('lmtest')
# install.packages('stargazer')

rm(list=ls())

#setwd() #set working directory

library(plyr);library(dplyr, warn.conflicts = FALSE)
library(tidyr);library(ggplot2)
suppressMessages(library(multiwayvcov, warn.conflicts = F))
suppressMessages(library(lmtest, warn.conflicts = F))
suppressMessages(library(stargazer))

s = function(x){summary(factor(x))}

#Read network data
A = readRDS('4-20-20_Network-KNearest_DeID_demed.RDS')
#Read and clean household sample data
H = read.csv('4-20-20_deid_nearestK.csv',
             na.strings=c('','NA'),strip.white=T,stringsAsFactors = F)
Hprime = H[H$A.A7_Area.Neighborhood %in% names(which(table(H$A.A7_Area.Neighborhood) >= 30)),]#Drop neighborhoods with < 30 observations
Hprime = Hprime[which(!is.na(Hprime$A.A7_Area.Neighborhood)),] #drop NA neighborhoods
Hprime = Hprime[which(Hprime$A.A7_Area.Neighborhood != 'Bangalore NA'),]
H = Hprime; rm(Hprime)

########################################################################################################################

############################################################################################################
#Map values to occupations
A$Job = mapvalues(A$D.D1_Occupation,
                  from = c(12,
                           13,
                           19,
                           2,
                           20,
                           21,
                           3,
                           4,
                           6,
                           7,
                           9),
                  to = c('Garbage',
                         'Gardener',
                         'Security',
                         'Butcher',
                         'Tailor',
                         'Vendor',
                         'Carpenter',
                         'Construction',
                         'Cook',
                         'Corporate', 
                         'Electrician'))

H$Job = mapvalues(H$D.D1_Occupation.,
                  from = c(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, #B17: retired
                           27), #B17: unemployed
                  to = c('Agriculture',
                         'Butcher',
                         'Carpenter',
                         'Construction',
                         'Labour',
                         'Cook',
                         'Corporation', 
                         'Driver',
                         'Electrical',
                         'Factory',
                         'Flower',
                         'Garbage',
                         'Gardener',
                         'Maid',
                         'Mechanic',
                         'Painter',
                         'ProfessionalSvc',
                         'Grocessory',
                         'Security',
                         'Tailor',
                         'Vendor',
                         'Government',
                         'Housewife',
                         'Student',
                         'Other',
                         NA, NA )) #Map retired/unemployed to NA so they don't affect denominator

#Note that B17 includes retired/unemployed; these are mapped above to NA and dropped from table (and not included in denominator)

#Network
sort (s(A$Job) / sum(!is.na(A$Job )) * 100  , decreasing = T) %>% round(2)
#Household
sort (s(H$Job) / sum(!is.na(H$Job )) * 100  , decreasing = T) %>% round(2)
#These are basis for manually-created Table 4

################################################################################################