Download 27/replication_package/Table4_script.R from chuxuan/REPRO-Bench: direct link, hf CLI and curl.
- Browser
- Download file 4.59 kB
-
https://huggingface.co/datasets/chuxuan/REPRO-Bench/resolve/main/27/replication_package/Table4_script.R
- Command line
-
hf download hf://datasets/chuxuan/REPRO-Bench/27/replication_package/Table4_script.R
-
curl -L -o Table4_script.R https://huggingface.co/datasets/chuxuan/REPRO-Bench/resolve/main/27/replication_package/Table4_script.R
4.59 kB
| #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 | |
| ################################################################################################ | |