rm(list=ls(all=t))
filename <- "midline1" # !!!Update filename
functions_vers <- "functions_1.7.R" # !!!Update helper functions file
source (functions_vers)
## --------
## This is sdcMicro v5.6.0.
## For references, please have a look at citation('sdcMicro')
## Note: since version 5.0.0, the graphical user-interface is a shiny-app that can be started with sdcApp().
## Please submit suggestions and bugs at: https://github.com/sdcTools/sdcMicro/issues
## --------
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
## Loading required package: sp
## Checking rgeos availability: TRUE
##
## Attaching package: 'raster'
## The following object is masked from 'package:dplyr':
##
## select
## The following object is masked from 'package:sdcMicro':
##
## freq
## rgdal: version: 1.5-23, (SVN revision 1121)
## Geospatial Data Abstraction Library extensions to R successfully loaded
## Loaded GDAL runtime: GDAL 3.2.1, released 2020/12/29
## Path to GDAL shared files: C:/Users/C_Pablo_Diego-Rosell/Documents/R/R-3.6.3/library/rgdal/gdal
## GDAL binary built with GEOS: TRUE
## Loaded PROJ runtime: Rel. 7.2.1, January 1st, 2021, [PJ_VERSION: 721]
## Path to PROJ shared files: C:/Users/C_Pablo_Diego-Rosell/Documents/R/R-3.6.3/library/rgdal/proj
## PROJ CDN enabled: FALSE
## Linking to sp version:1.4-5
## To mute warnings of possible GDAL/OSR exportToProj4() degradation,
## use options("rgdal_show_exportToProj4_warnings"="none") before loading rgdal.
## Overwritten PROJ_LIB was C:/Users/C_Pablo_Diego-Rosell/Documents/R/R-3.6.3/library/rgdal/proj
## Loading required package: spatstat.data
## Loading required package: spatstat.geom
## spatstat.geom 2.0-1
##
## Attaching package: 'spatstat.geom'
## The following objects are masked from 'package:raster':
##
## area, rotate, shift
## Loading required package: spatstat.core
## Loading required package: nlme
##
## Attaching package: 'nlme'
## The following object is masked from 'package:raster':
##
## getData
## The following object is masked from 'package:dplyr':
##
## collapse
## Loading required package: rpart
## spatstat.core 2.0-0
## Loading required package: spatstat.linnet
## spatstat.linnet 2.1-1
##
## spatstat 2.0-1 (nickname: 'Caution: contains small parts')
## For an introduction to spatstat, type 'beginner'
## rgeos version: 0.5-5, (SVN revision 640)
## GEOS runtime version: 3.8.0-CAPI-1.13.1
## Linking to sp version: 1.4-4
## Polygon checking: TRUE
##
## Spatial Point Pattern Analysis Code in S-Plus
##
## Version 2 - Spatial and Space-Time analysis
##
## Attaching package: 'splancs'
## The following object is masked from 'package:raster':
##
## zoom
## The following object is masked from 'package:dplyr':
##
## tribble
## Loading required package: spam
## Loading required package: dotCall64
## Loading required package: grid
## Spam version 2.6-0 (2020-12-14) is loaded.
## Type 'help( Spam)' or 'demo( spam)' for a short introduction
## and overview of this package.
## Help for individual functions is also obtained by adding the
## suffix '.spam' to the function name, e.g. 'help( chol.spam)'.
##
## Attaching package: 'spam'
## The following objects are masked from 'package:base':
##
## backsolve, forwardsolve
## See https://github.com/NCAR/Fields for
## an extensive vignette, other supplements and source code
##
## Attaching package: 'geosphere'
## The following object is masked from 'package:spatstat.geom':
##
## perimeter
##
## Attaching package: 'tibble'
## The following object is masked from 'package:splancs':
##
## tribble
#mydata <- mydata [1:10,] # remove '#' from #mydata if you want to conduct a fast check on 10 rows.
Visually inspect variables in "dictionary.csv" and flag for risk, using the following flags:
# Direct PII: Respondent Names, Addresses, Identification Numbers, Phone Numbers
# Direct PII-team: Interviewer Names, other field team names
# Indirect PII-ordinal: Date of birth, Age, income, education, household composition.
# Indirect PII-categorical: Gender, education, ethnicity, nationality,
# occupation, employer, head of household, marital status
# GPS: Longitude, Latitude
# Small Location: Location (<100,000)
# Large Location (>100,000)
# Weight: weightVar
# Household ID: hhId,
# Open-ends: Review responses for any sensitive information, redact as necessary
# !!!No Direct PII
# !!!No Direct PII-team
!!!Include relevant variables, but check their population size first to confirm they are <100,000
locvars <- c("mid1_villagename",
"mid1_settlement",
"mid1_municipality",
"mid1_wardno",
"mid1_child_municipality",
"mid1_child_wardno",
"mid1_child_villagename",
"mid1_child_settlement")
mydata <- encode_location (variables= locvars, missing=999999)
## [1] "Frequency table before encoding"
## mid1_villagename. Villagename
## 'Ranighat .parariya /kharsal
## 7 7 4
## /Rajesh gupta aadarsa tol aadarsamani tol
## 5 3 13
## Aadarsh tole Aadarsha tol Aalau
## 6 27 70
## aarba Aarba Adalat road
## 8 4 1
## adarshnagar Adarshnagar Adarsnagar
## 5 4 4
## Alakha Road Apauni arba
## 9 19 8
## Arba Armalakot arva
## 26 15 12
## Ashok batika Ashokbatika Ashokvatika
## 6 27 3
## Atharaha Athraha badhahare tol
## 28 5 5
## bagaicha Bahuwari Bajrang tole
## 4 10 22
## Banahari Bangau Barwa
## 27 25 10
## Basant inarwa Basantpur tole Baskot
## 11 15 4
## Basudevpur Basydevpur Bawanipur
## 93 5 7
## Bayokhola bc Belanye
## 5 7 2
## Belganar Belganari Bhagawati tole
## 2 23 1
## Bhagwatitol bhakti path bhalam
## 6 1 18
## Bhalam Bhaluwahi tole bhandari dhar
## 40 1 2
## bhansartole Bhansartole bhatipath
## 5 10 1
## Bhawanipur Bhawaniyapur Bhediyahi
## 61 113 13
## Bijeynagar Bindabasini Bindawasini
## 47 15 51
## Birta Birta nursing campus Brahmpur
## 47 5 57
## Brita Nursing Campus Area Budagaun tole Capkaiya
## 3 20 7
## Centre Parseni tole Chailaheli Chailai
## 4 4 3
## Chanora parariya chanutae Chapkaiya
## 12 14 217
## Chapkaya Chappa dada Chhapkaiya
## 10 4 67
## Chhapwa dada Chitraguptnagar chowk
## 2 10 2
## Cigarette factory Dadathok Dadathok tol
## 4 7 2
## Dadrini Dasharthnager Deurali piple
## 1 4 11
## Dhadagari Dhalepipal dhanauji
## 21 6 6
## Dihi gau Dinesh sah Dryport tol
## 4 5 6
## Fulbari Furthi chook Furthichook
## 69 42 3
## Gahatera Gahawa garjathi
## 9 40 5
## garjati Gaurigau Gaushala road
## 9 6 4
## Geetanagae Geetanagar Geetnagar
## 3 199 4
## ghadgai ghadhai Ghadi
## 13 6 9
## Ghantaghar Ghariwarha Gharmikhola
## 6 41 1
## Ghoraneti Ghoraneti tol Ghorneti
## 6 3 1
## Ghurmi Ghusari tole gimirae
## 17 5 1
## Gitpur tole Golauri Golouri
## 5 3 6
## Gopal chook Gurudev ram Gyanjyoti
## 14 4 6
## Halawar Hamagara hanumanagar
## 9 6 4
## hanumannagae hanumannagar hanunam nagar
## 4 4 3
## Haripaura Harpatgaj Harpatganj
## 3 5 9
## Harpatgunj Hasnapur Hatiya
## 29 11 46
## Hatti lote Hemanagar hemja
## 5 6 66
## Hemja Himalay Himalay tole
## 48 1 38
## Himalayan tole Indarpur jagriti tole
## 6 104 4
## Jagriti tole Jailroad Jaispur
## 5 17 136
## Jaspur Jimire dil Jispur
## 12 5 6
## Jogindra Raut kurmi Jumleti tol Kachila
## 3 8 19
## Kachili Kahu kahun
## 15 9 18
## Kahun Kalakhola Kalakhola pulchok
## 8 6 3
## Kalyanpur Kanchan pur road Kanchanpurroad
## 3 1 4
## Kapadadevi karai chautari Kataha
## 10 5 15
## kaun Kawari khadha
## 52 5 6
## Khadre Khadrye khaluwatole
## 4 12 5
## Khaluwatole khaluwatole sirsiya Khaluwatole Sirsiya
## 9 7 5
## Khalwa tol Khardye Kharsal
## 5 5 82
## Kharsal purnipokhari Kharsal tole Khas karandoo
## 8 7 6
## Khas karkandoo khastar khaster
## 88 5 7
## Khumkhane Kimdi Kirana line
## 23 5 33
## kristi Kristi Kulayen marga
## 49 40 6
## Kumartole Kumhal tol Kuwari
## 10 10 7
## Kwangi Kwonagi Kwonig
## 17 1 1
## Lachhamamu Lachhamanu Lachhumanu
## 13 24 6
## Lalmateya Lamachaur lamachaure
## 5 5 10
## Lamidada Lamidamar Lilja tole
## 3 3 5
## Madhumaya thapa Main road Mainroad
## 1 9 8
## Maisthaan Maisthan Mandannagar
## 16 67 8
## Mangalpur Manihari Manikapur
## 31 43 106
## Matera tole Mathalno halwar Maujetole
## 4 4 5
## maula tol bikas Mohanpur Mohon pur tol
## 1 5 5
## Moteratole Mulibhagaicha Mulkot tol
## 4 1 6
## Murli Murli Bagaicha Murlibagaicha
## 41 6 18
## Musilamtol Muslimtol Nabin chook
## 17 11 4
## Nagarpalika road Naguwa Nagwa
## 4 26 10
## Naule tol Naulpur Naya gaun
## 4 11 6
## Naya tole Nayabasti shreepur Nayagaun
## 3 5 13
## Nayatole murli nirmal pkhari nirmal pokhari
## 16 1 28
## Nirmal pokhari nirmalpokhari Nirmalpokhari
## 10 5 30
## padam pokhari padampokhari Paddha
## 18 4 12
## padhali Padham pokhare pain tanki
## 10 5 4
## Pani tanki Panitanki Parariya
## 1 4 13
## Parasanagar Parasnagar Paraspur
## 4 6 134
## Parsauni Parseni bajar tole Parwanipur
## 28 4 82
## Paschim rampur Patahani Patariya
## 25 23 8
## pateheni Pathani patihani
## 5 5 29
## Patihani patihani town patlahara
## 110 12 20
## Piara Pipara Piple
## 21 50 3
## Pipra,awash,ariya Piprahwa Pirgau
## 5 115 1
## Pokheral tole Pokhrel tole Pragatinagar
## 5 3 3
## Prasauni Puaina Puaraina
## 75 5 6
## pullar Pumbdi Pumdi
## 7 5 15
## Pumdi bhumdi Pumdi vumdi Pumdibhumdi
## 5 17 8
## Pumdikot Pundgi pundi vundi
## 4 6 4
## pundivundi Puraina Puraini
## 3 135 118
## Purnipokhari Raam tole Raampur
## 3 10 14
## Radha devi gurung Radhemai Rahamatpur
## 1 31 9
## Raikhalyan Rajbiraj Rajdevi road
## 5 196 3
## Rajdevi tole Rajhena Rakbiraj
## 41 3 4
## Ram,gaduwa Ramgaduwa Ramgadwa
## 5 107 14
## Rampur Ranighat Ranighat tol
## 5 79 4
## Ranighat,gashuwara road Resamkoti Resham kothi
## 6 1 12
## Reshamkhoti ReshamKothi Reshamkoti
## 3 5 34
## Ryale patle Sabathuwa Sabitawa
## 13 9 13
## sahardhar Sai krishna tola Sajha tol
## 4 1 12
## santipur sarangkot Sarangkot
## 4 16 10
## Sarankot Saranpur Saraswati tole
## 4 32 2
## Sarboday tole Sarbodey tole Sardar tole
## 3 4 3
## sardhar sardhgar Sarswati tole
## 6 7 4
## Shanti tole Shimra gau tol Shiromanar
## 11 7 5
## Shiromaninagar shiva nagar Shiva shakti
## 10 7 2
## Shivaghat shivanagar Shivanagar
## 5 27 99
## Shivnagar Shreepur Shreepur,ranighat
## 16 57 7
## Simlegaire Sirha rod Siromaninagar
## 6 4 7
## Sirshiya Sirshyia Sirsiya
## 60 7 19
## Sisobari Sitalpur Siva shakti tole
## 17 5 5
## Sivanagar Sreepur Srswati tole
## 37 23 16
## Sugauli SUGAULI Sugauli birta
## 35 6 56
## Sukarua Sukaura Sunderbasti
## 5 5 13
## Surya nagar Swarn Swarn tole
## 8 4 14
## swikhet Talno halwar tol Tarigau
## 1 4 80
## Tarigau Basbot Tarigaun Tatrigachi
## 1 17 5
## Tejaratole Tetari gachhi Tetri gachi
## 18 10 5
## Tetri tole Tetrigachi Thangachi
## 7 5 4
## Thapa tol themja Thulo,pipra
## 3 4 4
## Tuhure pasal Uadayapur Udaepur ghurmi
## 4 16 8
## Udahapur Udayapur Udaypue
## 10 90 6
## Udaypur Udaypur bhurmi Udaypur ghurmi
## 29 5 14
## Udaypur Gurmi Udaypur,ghurmi Urahari
## 7 4 12
## Uttar sukaura valam Valam
## 3 16 16
## Vishwa West Rampur Yamdi
## 10 4 2
## yandi tol
## 3
## [1] "Frequency table after encoding"
## mid1_villagename. Villagename
## 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653
## 33 16 7 7 3 1 21 13 5 2 7 17 13 4 11 5 5 3
## 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671
## 7 104 5 5 46 1 4 3 5 66 12 3 40 17 22 113 18 4
## 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689
## 6 9 11 2 1 5 57 6 6 4 7 26 12 8 70 2 4 14
## 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707
## 2 6 27 1 12 4 5 4 47 6 3 9 28 5 5 5 9 5
## 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725
## 23 2 31 18 4 8 32 82 57 4 11 4 10 134 18 6 10 48
## 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743
## 82 1 21 5 10 8 8 9 7 4 3 13 61 4 15 3 118 5
## 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761
## 4 4 5 4 12 199 5 8 75 5 17 1 1 6 5 3 5 60
## 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779
## 14 37 10 110 4 10 20 12 4 10 51 43 1 9 136 38 27 19
## 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797
## 18 27 6 28 5 7 4 1 107 1 16 16 7 3 42 4 115 13
## 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815
## 3 13 15 4 4 4 3 5 5 3 6 4 4 16 7 3 4 7
## 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833
## 6 41 3 52 6 3 5 3 10 5 4 4 26 29 8 10 17 11
## 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851
## 6 5 4 41 4 6 7 5 5 1 25 15 18 5 3 5 5 16
## 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869
## 3 35 4 6 1 4 196 4 8 11 1 40 1 106 13 3 34 3
## 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887
## 6 4 8 13 15 50 4 7 49 12 6 31 6 93 79 9 17 1
## 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905
## 40 10 9 6 1 1 3 7 1 3 4 7 3 5 13 6 7 4
## 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923
## 4 15 7 14 2 6 217 5 25 12 4 16 3 3 10 23 7 5
## 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941
## 5 5 6 5 67 5 4 5 10 3 6 4 4 5 14 3 12 5
## 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959
## 4 6 7 29 80 4 14 5 2 5 5 47 27 8 4 16 4 5
## 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977
## 9 41 7 88 10 1 9 30 3 10 5 5 4 6 1 2 5 135
## 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995
## 20 17 1 28 67 23 10 5 5 29 17 69 10 15 6 99 16 12
## 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013
## 90 6 6 4 10 8 6 6 10 5 5 5 56 24 14 19 19 9
## 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031
## 2 5 9 1 23 11 10 8 13 6 6 4 4 6 4 5 1 3
## 1032
## 1
## [1] "Frequency table before encoding"
## mid1_settlement.
## aadarsa mani aadarsa pokhrel tol aadarsa tol
## 7 6 9
## aadarsamani tol Aadarsh tole Aalau
## 6 6 70
## Aanapurna Tol Adalat road Adarsa tol
## 5 1 6
## adarshnagar Adarshnagar Adarsnagar
## 5 4 4
## Adhikari gaun Agree gaurishankar Ahmad pur
## 5 6 6
## Aklekhet Alakha Road Alanagar
## 4 9 12
## Amar Ammarbasti Anapurna Tol
## 4 12 6
## annapurna tol Apauni Armalakot
## 3 28 15
## Ashok batika Ashokbatika Ashokvatika
## 6 27 3
## Atharaha Athraha Babu gaun
## 28 5 29
## Babugaun Badahare badhahare
## 20 4 5
## Badhare bagaicha Bagbani tol
## 4 4 2
## Baghakholi tol Bagyasworitol Bahaun tol
## 7 4 4
## bahu khola Bahuhori Bahuwari
## 5 21 10
## Bahyekhola Bajrang tole Bajrangi tole
## 3 5 42
## Bale gaun Balegaun Banahari
## 23 47 10
## Band tole Bandh tole Banjare gaau
## 3 5 21
## bankatta baralthar Barampuri
## 9 1 8
## Barauji Barewa Barwa
## 13 5 5
## Basan purawa Basantpur Basbot
## 8 15 6
## baseri tol Baskot baspani
## 5 4 4
## Baya khola Bayokhola bc
## 4 5 7
## Belanye.tol besi gidhri khola Besigidari
## 2 4 4
## bhadgau bhadhahara bhadhara
## 3 1 4
## Bhagaerithana Bhagari than Bhagawanpur
## 3 6 4
## Bhagawati tole Bhagwatitol bhakti path
## 1 6 1
## bhalam Bhaluwae Bhaluwahi nadhi
## 11 8 1
## bhandari dhar Bhandaridahar Bhandarigaun
## 2 5 5
## Bhansartole bhanshartole Bhata tole
## 10 5 5
## bhatipath Bhawani tol Bhawanipur
## 1 12 22
## Bhayapur Bhediyahi BhgawotiTol
## 10 13 6
## Bhitri road Bhola chowk Bhujaigaun
## 30 5 22
## Bhujigaun Bhuwanpur Bijaya tole
## 23 4 6
## Bijeynagar Bijeynagar bazar Bijeynagar dairy
## 4 4 8
## Bijeynagar,way to haraiya Bindawasini Bindraban
## 4 56 6
## Birta Birtakhet Bishanu
## 124 1 3
## Bishnupur Bokati botetol
## 15 5 14
## Budagau Budagaun Chailahe
## 12 8 4
## Chamartol and dhobitol chanauta chanaute
## 4 6 7
## Chanora parariya chanutae Chapkaiya bazar
## 12 1 1
## Chapkaiya tole Chathghat chauntae
## 6 10 6
## Chauthari tol Chhapkaiya Chiranjivi chowk
## 3 1 7
## Chitagupt nagar Chitraguptnagar Chock bajar
## 7 20 4
## Choudhaghare chowk Cigarette factory
## 13 2 8
## Cigarette factory area Cold store Dadathok
## 4 11 3
## Dadathok tol Dadathok tole Dadre
## 4 2 7
## Dadrini tol Dahara Dakshin tole
## 1 3 2
## Dakshina tole Darai tole Darsa nager
## 1 4 5
## Dasarath nager Deurali Devi chook
## 4 4 10
## Devnagar Devthan Devthan tlo
## 23 10 4
## Devthan tol dhakalthar Dhale Pipal
## 5 4 3
## Dhalepipal dhanauji Dharahi tol
## 6 11 5
## Dharahi tol (purbi) Dharai tol Dhore gaun
## 5 5 34
## Dihi Dihi gau Dihi tol
## 4 11 5
## Driport Driport Tol Dryport tol
## 12 4 6
## Duhar tole Dumari Dumri
## 6 9 48
## Duwar tole Fulbari Furhi chook
## 9 13 3
## Furthi chook Furthi chook bazer Futaha
## 22 6 7
## Gahatera Ganesh chok Ganeshgunj
## 9 9 9
## Ganganaga Ganganagar Gangapur
## 5 51 11
## Gapalgunj garjati Gauri gaun
## 8 14 1
## Gauri shanker tol Gayarjati Geeta mandir
## 3 4 16
## Geetanagar Geetanagar bazar ghadgai
## 12 6 22
## Ghariwarha ghimire chok tol Ghimire tol
## 41 12 8
## Ghoraneti Ghorneti Ghumtichook
## 9 1 5
## Ghurali tol Ghurmi Ghurmi udayapur
## 5 53 4
## Ghusakpur Ghusari Ghusukpur
## 10 5 18
## gimire Gitpur Gopal chook
## 1 5 9
## Gopalgunj Gorkhali Gorkhali tole
## 11 27 23
## Goswara road Gouri purwa Gouriipurwa
## 6 8 5
## Gouripurwa Govind chok Gumba chour
## 5 8 3
## Gurmi Gurung gau Gurung tol
## 7 4 5
## Gurungchowk Gyaneshwor chowk Gyanjyoti
## 6 7 6
## gyarjyoti Hal pachadi Halawar
## 3 26 3
## Halwar hanuman nagar Hanuman nagar tole
## 12 3 5
## hanumannagar Haraiya Haripaura
## 19 4 4
## Haripauri Harpatganj Harpatgunj
## 10 5 29
## Hatiya Hema Nagar tol Hemja
## 51 6 4
## Himal Himalay tole Himalaya
## 8 29 4
## Himalayan tole Himalsy tole Himaly tole
## 6 9 1
## Inaruwa Inaruwamaniyari Inarwa
## 7 17 11
## Indargaau Indrapuri Indrapuri chok
## 17 5 7
## jagarit tol Jagriri jagriti
## 3 5 9
## Jagriti jagriti tol Jagriti tol
## 18 3 5
## Jagriti Tol Jagritinagar Jailroad
## 5 7 17
## Jaispur Jamnaha Janajagran tol
## 142 52 5
## Janajagrati janajagriti tol Janakeswori
## 5 1 6
## janjagriti tol Jaspur Jayanagar
## 7 1 30
## Jhakaruwa Jhakrawathuti tol Jhanjhane
## 6 5 6
## Jhumaryathuti tol Jhumaryatol Jimire dil
## 4 5 5
## Jodhapurwa Kabhre tole, Indrachowk Kabhreghat
## 19 6 11
## Kachili Kalakhola Kalayanpur bazer
## 7 9 3
## kalika tol Kalwatole Kalyankari tol
## 5 7 4
## kamere pani Kanchanpur road Kanchanpurtole
## 7 4 4
## Kanchi chok Kanthipur Kantipur
## 8 24 1
## Kapadadevi karai chautari Karkandoo
## 5 5 20
## Karkichok Karkichowk karkigsum
## 4 3 5
## Karmohna Kasarbag kasari
## 6 6 3
## Kaseri Kaseri dumre kastan
## 3 4 4
## Katahasami tol Katilya Katulya
## 2 5 4
## kauntol Kawari Kehuniya
## 1 5 10
## Kepa chock kesari Kesharbag
## 4 1 22
## khadha thare Khadrye Khalla Puraini
## 6 4 24
## khalutole Khaluwatole khaluwatole sirsiya
## 6 5 1
## Khaluwatole sirsiya khaluwatolw khalwa tole
## 14 5 7
## Khalwatole Kharsal Kharsal dev tole
## 20 38 5
## Kharsal tole khaster Khatri tol
## 33 8 4
## Khatsal tole Khayarghari Khayarghari chowki
## 2 6 9
## Khittari khlwatole Khumkhane
## 2 7 23
## Kigrinpurwa Kirana line Kodi
## 26 20 6
## Kohadi Koiri tole Kulain
## 9 10 4
## Kulani tole kulayan marga Kulayen marga
## 3 5 6
## Kumartole Kumeya Kumhal tol
## 10 5 10
## Kumhal tole Kumhaltole Kusanchour
## 6 1 8
## Kuwari Lachhamanu Lagdhawa
## 7 43 29
## Lalapurwa laliguras tol Laliguras tol
## 27 16 5
## Lalmatya tol Lamachowk Lamakhet
## 3 5 4
## Lamidada tol Lamidamar lampata
## 3 3 2
## Laptanchwok Lilja tole Lodhai
## 5 5 5
## Lodhai gau Lodhaigau Lodhayi goun
## 3 10 5
## Lonionpurawa Loniyanpurwa Lukunsawara
## 5 7 8
## machapuchare Machhapucher tol Madjid tol
## 5 5 13
## Magar tole Magartole Mahajid Tol
## 1 4 6
## Mahapurwa Maheswor tol Mainroad
## 16 1 17
## Maisthan Majdada Malpot tole
## 42 5 6
## Manahari Manakamana chowk Mandannagar
## 3 1 8
## Mangalpur bazer Mangalpur bazer vitra Manihari
## 5 4 38
## Maniyadanda tol Masjid tol Masjid tole
## 2 26 8
## Maszid tole Matera Maujetole
## 8 4 10
## maula tol Melijuli tol methlang
## 2 6 1
## Milan tol Milantol Milijulichowk
## 19 17 5
## Mohanpur Mohanpur tol Mohonpur
## 64 5 5
## Motera Mulkot murli
## 4 6 1
## Murli Murlibagaicha MurliBagaicha
## 42 14 6
## Murlubagaicha Musilamtol Muslimtol
## 5 11 11
## Musulamtol Nabin chook Nachne chaur
## 6 11 4
## nachnechaur Nadai gaun Nadaigaun
## 14 5 15
## Naditole Nagarpalika road Naguwa
## 14 4 16
## Nagwa Naharpurwa Namuna tol
## 10 23 3
## Namunatol Natanpurwa Naulpur tol
## 3 29 1
## Naya Basti Nayabasti Nayagaun
## 8 14 11
## Nayak tol Nayatole murli Neta chowk
## 9 16 4
## Neuli Neuli tol nirmal pokhari
## 6 6 13
## Nirmal pokhari Nirmal pokhri Paan mandi
## 1 5 4
## Paangaali Pabitra tol Pachhim sukaura
## 6 8 5
## padam pokhari padampokhari Padampokhari
## 7 15 10
## Paddha Pade ghumti padeli
## 5 6 1
## padhali Padham pokhare Pain tanki
## 10 5 4
## Pakaudi Pani tanki Panitanki
## 14 1 4
## Parajuli chok Parariya Parasapur
## 10 28 5
## Parasnagar Paraspur Parbatinagar
## 7 67 19
## Parsanpurawa Parsauni Parseni
## 10 28 12
## Parwanipur Pasupati Patelnagar
## 23 5 5
## Patelnager patihani patihani town
## 14 6 12
## Patihani town patlahara Patle
## 9 17 6
## Phoolwari Tol Pipaldali Pipara
## 1 5 18
## Piple Pipra Pirgau
## 3 5 2
## Pokhari tol Pokheral tole Pokhreal tole
## 5 14 4
## Pokhrel Tole Pothedarpurwa Pragatinagar
## 3 13 11
## Prasauni Profhesar koloni pullar
## 75 6 7
## Pullar Pumdi kot Pumdikot
## 5 3 9
## Puraina Puraini Purnipokhari
## 45 19 11
## Raam tole Raampur Raamur
## 10 7 7
## Radha krishna Radha krishna Tol radhakrishna tol
## 5 8 3
## Radhakrishna tol radhakrisna tol Radhakrisna tole
## 17 7 7
## Radhapur Radhemai Rahamatpur
## 55 31 9
## Rajdevi Rajdevi road Rajdevi tole
## 5 3 24
## Rajhana tol Rajhanatol Rajhena tharugau
## 5 7 3
## Rajheni tol Ram Ram tol
## 5 4 4
## Rameshorpurwa Ramgaduwa Ramgadwa
## 64 107 14
## Ramghadwa Ramtole Ramwapur
## 5 12 60
## Ranighat Resamkoti Resham kothi
## 104 1 11
## Reshamkhoti Reshamkothi Reshamkoti
## 2 6 34
## Reshan kothi Risinge tole Road tol
## 1 3 6
## Sabaithuwa Sabitawa Sai krishna tole
## 9 13 6
## Saja sajha sidhartha sajha tol
## 4 6 6
## Sajha tol Sangamtol Sanoganesh gunj
## 12 4 2
## Santi chook Santi tole santipur
## 4 3 4
## Saraswati tole Sarboday tole Sarbodeytole
## 4 3 4
## Sardar tole sardhar Sarswati tole
## 3 13 1
## saudaha saudaha chautara Saudahachautara
## 6 1 5
## Sauraha School road/ malpot road Shanti
## 28 7 10
## Shanti tol Shanti tole Shantichowk
## 9 11 14
## Shantitol shardhar Shimragau
## 19 4 7
## Shiromani Shiromaninagar Shiva chock
## 5 15 6
## Shiva Shakti tol Shivaghat aagadi Shivanagar
## 2 5 41
## shivasakti marga Shivashakti tol shivasundar tol
## 3 4 4
## Shivnagar Shivthan Shreepur
## 11 19 59
## sibalaya Sibalaya Sibasundar tol
## 9 6 6
## Sibsundar simalchair simalchaur
## 6 4 9
## Simalchaur simalchaur tol Simlegaire
## 5 3 6
## Siraha road Sirha rod Sirisiya khalwa
## 4 4 5
## Siromaninagar Sirsiya Sisobari
## 7 19 17
## Sitalpur Sreepur Srswati tole
## 19 3 4
## Srswatitole Sugauli birta suikhet
## 12 65 10
## Suikhet Suiya Sukaura tol
## 12 32 5
## Sukidaha Sunaulo tol Sunaulo tol
## 3 6 4
## Sundada sundada khet Sundada khet
## 10 7 5
## Sundarchok Sunder basti Sunderbasti
## 4 4 32
## surkhet Surya nagar Suryanagar
## 6 5 3
## Swahara Swara swaraha
## 1 5 4
## Swarn tole Swarna tole swekhet
## 18 4 10
## swethet swikhet swikot
## 4 3 4
## Syalghari Taajpur Tanga tole
## 12 30 8
## Tangpasri Tarigai tharugaun Tarigain
## 42 4 6
## Tejaratole Telipatti Telipatti mas
## 18 15 7
## Teliyanpur Tetari gachhi Tetarigachi
## 11 9 1
## Tetri chok Tetri gachi Tetri tole
## 4 2 11
## Tetrihi tole Thangaxi thapa
## 5 4 3
## Thapa gau Thapa tol thulachaur
## 3 13 3
## Thulachaur Thulachawor Thulachhaur
## 4 4 5
## Thulo ghadi Thulo pipara Thulo,pipra
## 9 27 4
## Thulobesi marga Thutitol Timalchour
## 8 3 5
## Treebenitol Tuhure pasal Tulo pipara
## 3 4 5
## Udayapur Udaypur bhurmi Udaypur ghurmi
## 6 5 5
## Udaypur Gurmi Ujalnagar Ujjewalnagar
## 7 4 4
## Ujjwalnagar Urahari Urahari mainroad tol
## 55 1 1
## Urahari rajmarg tol Utarbari yadav tile Uttar sukaura
## 5 8 3
## Uttarsukaura Valuwahi Valuwahi kath
## 5 1 1
## Vangushara Vatha tole Vawanpur
## 5 4 5
## Vhagabati Vhagawanpur Vidhyapith
## 3 8 7
## vimsennagar vimshen nagar vimshennagar
## 6 7 10
## Vishwa word office yamdi
## 10 4 13
## Yamdi Yamdi Tol Yatimkhana tol
## 4 2 21
## Yekle sal
## 1
## [1] "Frequency table after encoding"
## mid1_settlement.
## 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543
## 5 5 41 2 4 23 4 4 1 1 3 7 12 5 6 6 4 5
## 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561
## 3 4 8 30 28 14 30 9 4 6 6 41 4 5 3 1 21 5
## 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579
## 11 3 6 4 6 4 5 23 6 5 2 4 3 6 18 3 7 8
## 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597
## 4 4 4 4 12 7 14 19 4 8 14 55 10 4 3 3 17 6
## 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615
## 15 12 4 7 7 6 29 4 19 23 10 1 42 5 3 7 6 10
## 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633
## 4 5 4 5 2 4 11 5 4 6 24 15 8 34 11 6 9 5
## 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651
## 5 6 5 52 2 6 5 8 6 4 9 1 5 1 38 13 5 3
## 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669
## 4 6 5 5 4 15 6 8 7 4 7 3 7 29 2 14 8 1
## 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687
## 13 9 5 13 3 3 8 13 5 8 6 5 11 5 4 38 56 5
## 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705
## 4 5 5 32 4 3 6 7 12 11 3 32 4 3 17 11 3 1
## 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723
## 3 5 3 5 4 26 2 9 16 8 4 7 2 13 1 22 9 43
## 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741
## 11 4 20 5 5 28 4 5 28 5 5 75 20 20 8 7 6 6
## 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759
## 3 4 5 42 6 1 5 4 64 6 14 4 2 3 8 13 9 15
## 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777
## 11 5 6 5 3 13 17 5 6 13 4 4 4 9 4 8 51 23
## 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795
## 1 6 10 5 5 4 4 1 5 10 5 10 7 5 7 10 3 34
## 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813
## 4 6 2 6 1 5 3 59 4 4 11 3 9 8 1 19 10 6
## 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831
## 47 5 12 6 5 5 5 3 1 4 4 5 2 23 6 7 29 1
## 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849
## 4 4 4 5 29 4 7 16 10 5 14 5 4 8 1 5 10 9
## 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867
## 1 26 4 18 7 3 5 7 6 4 1 12 8 2 1 142 1 5
## 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885
## 1 124 7 5 65 4 1 9 5 11 10 5 53 29 5 20 21 18
## 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903
## 4 1 7 8 3 26 1 16 27 3 5 1 5 9 3 16 10 6
## 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921
## 1 4 7 6 17 5 70 5 4 5 4 17 4 4 3 7 22 6
## 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939
## 6 4 24 5 9 5 51 2 6 12 4 6 6 4 2 5 3 9
## 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957
## 27 9 7 5 27 5 8 9 10 7 104 4 3 5 8 10 48 17
## 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975
## 12 5 6 19 2 5 15 19 3 60 5 3 6 20 6 4 6 4
## 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993
## 4 13 5 9 1 14 4 15 7 1 6 6 9 5 4 4 1 1
## 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011
## 6 5 1 12 4 6 10 11 1 3 22 7 23 5 3 18 6 7
## 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029
## 4 11 1 6 22 9 15 8 1 6 8 1 4 1 4 2 3 30
## 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047
## 10 10 10 1 8 4 3 1 28 14 4 3 5 11 9 4 3 4
## 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065
## 5 8 3 5 18 5 3 4 2 5 17 11 5 1 7 10 11 5
## 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083
## 12 1 16 6 9 9 8 5 6 9 23 6 10 4 4 42 6 10
## 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101
## 6 1 5 55 4 6 12 5 7 1 8 7 4 10 10 28 4 14
## 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119
## 5 5 3 4 31 3 24 3 9 6 5 7 3 4 1 5 5 19
## 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137
## 4 11 19 7 1 19 4 5 5 6 14 5 7 3 10 107 6 45
## 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155
## 5 67 6 2 12 3 6 12 17 4 7 4 3 12 6 4 11 5
## 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173
## 3 7 3 19 11 10 5 5 13 7 11 4 3 22 4 64 21 33
## 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191
## 6 2 6 5 42 5 14 5 6 27 6 5 13 4 5 9 12 12
## 1192 1193 1194 1195 1196 1197 1198
## 7 6 3 14 10 4 10
## [1] "Frequency table before encoding"
## mid1_municipality.
## 1 2 3 4 5 6
## 1073 2372 1292 893 708 620
## [1] "Frequency table after encoding"
## mid1_municipality.
## 747 748 749 750 751 752
## 1292 620 893 2372 1073 708
## [1] "Frequency table before encoding"
## mid1_wardno.
## 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
## 202 231 176 97 79 139 96 88 105 116 27 145 195 158 179 269 273 362 349 415 369 347
## 23 24 25 26 27 28 29 30
## 309 355 302 382 410 407 274 102
## [1] "Frequency table after encoding"
## mid1_wardno.
## 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
## 97 407 27 145 415 202 273 195 269 309 349 79 302 231 176 347 179 158 102 410 369 88
## 133 134 135 136 137 138 139 140
## 355 382 96 116 274 105 362 139
## [1] "Frequency table before encoding"
## mid1_child_municipality. select the municipality where this household is located
## 1 2 3 4 5 6 <NA>
## 16 5 11 28 13 3 6882
## [1] "Frequency table after encoding"
## mid1_child_municipality. select the municipality where this household is located
## 497 498 499 500 501 502 <NA>
## 5 3 13 16 11 28 6882
## [1] "Frequency table before encoding"
## mid1_child_wardno. Ward No.
## 1 3 5 6 7 9 10 15 16 18 19 20 21 22 24 25 26 27
## 5 3 3 3 2 1 1 5 1 4 3 1 12 8 2 1 2 7
## 28 29 <NA>
## 9 3 6882
## [1] "Frequency table after encoding"
## mid1_child_wardno. Ward No.
## 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851
## 4 5 3 12 1 2 3 3 1 5 9 3 1 8 7 1 1 2
## 852 853 <NA>
## 3 2 6882
## [1] "Frequency table before encoding"
## mid1_child_villagename. Name of the village/ community
## Aadarsha tol Aarba Arba Armalakot arva
## 6882 1 1 1 2 1
## Basudevpur Bhawanipur Budagaun tole Chapkaiya Deurali piple Dihi gau
## 1 1 1 5 2 1
## Fulbari Furthichook Geetanagar Geetnagar ghadgai hemja
## 2 1 4 1 1 3
## Hemja Himalay tole Jaispur Jimire dil Kahu kahun
## 3 1 4 1 2 1
## kaun Kharsal kristi Kristi Kulayen marga Mandannagar
## 3 5 1 1 1 2
## Mangalpur Moteratole Paraspur Patahani patihani Patihani
## 2 2 1 1 1 2
## patihani town Rajbiraj Rajdevi tole Ryale patle Udayapur
## 1 4 1 3 4
## [1] "Frequency table after encoding"
## mid1_child_villagename. Name of the village/ community
## 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658
## 1 1 1 1 1 1 2 1 2 1 3 5 1 4 1 4 4 1
## 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676
## 3 3 1 1 2 1 1 6882 1 3 1 4 2 2 5 2 2 1
## 677 678 679 680 681
## 1 1 1 2 1
## [1] "Frequency table before encoding"
## mid1_child_settlement. Name of the Settlements
## Armalakot Badahare Badhare
## 6882 2 1 1
## Bale gaun bankatta Bhaluwae Budagaun
## 1 1 2 1
## Dadre Devnagar Dihi Dihi gau
## 3 3 1 1
## Dumri Furthi chook Futaha ghadgai
## 1 1 1 1
## ghimire chok tol Gopalgunj Gorkhali Gurung gau
## 3 1 1 1
## Gurung tol Himalay tole Indrapuri chok Jaispur
## 1 1 1 4
## Jimire dil Kharsal Kulain Kulani tole
## 1 5 1 1
## Kulayen marga Lalapurwa laliguras tol Laptanchwok
## 1 3 1 1
## Lodhaigau Machhapucher tol Mandannagar Mangalpur bazer vitra
## 1 1 2 2
## Motera Padampokhari Paraspur Parbatinagar
## 2 1 1 5
## patihani town Patihani town Rajdevi tole sajha tol
## 1 1 1 1
## Simalchaur Sundada Sunderbasti swekhet
## 1 1 1 1
## Syalghari Thulachaur Ujjwalnagar yamdi
## 1 1 1 2
## [1] "Frequency table after encoding"
## mid1_child_settlement. Name of the Settlements
## 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
## 1 1 1 5 2 3 2 1 1 1 1 1 1 1 1 1 1 1
## 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
## 1 1 2 1 1 1 2 1 1 1 1 1 1 1 1 5 1 2
## 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
## 1 1 3 3 1 1 2 1 1 6882 1 1 3 1 1 4
# Focus on variables with a "Lowest Freq" of 10 or less.
mydata <- top_recode ("mid1_s3q3", break_point=80, missing=999999) # Topcode cases age 80 or older
## [1] "Frequency table before encoding"
## mid1_s3q3. Age in completed years at the time of survey:
## 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
## 27 40 83 87 112 128 171 175 184 168 191 143 228 196 193 165 201 141
## 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
## 169 116 87 61 75 48 47 101 100 43 92 83 131 91 110 88 70 192
## 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
## 146 76 94 63 163 87 64 50 26 118 66 25 35 27 77 37 37 24
## 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
## 21 60 41 16 25 15 61 19 23 26 11 61 29 14 13 13 44 28
## 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 90 91
## 13 18 9 17 6 3 7 2 11 9 3 2 5 3 1 3 1 2
## 93 95 97 100 <NA>
## 1 1 1 2 766
## [1] "Frequency table after encoding"
## mid1_s3q3. Age in completed years at the time of survey:
## 0 1 2 3 4 5 6 7
## 27 40 83 87 112 128 171 175
## 8 9 10 11 12 13 14 15
## 184 168 191 143 228 196 193 165
## 16 17 18 19 20 21 22 23
## 201 141 169 116 87 61 75 48
## 24 25 26 27 28 29 30 31
## 47 101 100 43 92 83 131 91
## 32 33 34 35 36 37 38 39
## 110 88 70 192 146 76 94 63
## 40 41 42 43 44 45 46 47
## 163 87 64 50 26 118 66 25
## 48 49 50 51 52 53 54 55
## 35 27 77 37 37 24 21 60
## 56 57 58 59 60 61 62 63
## 41 16 25 15 61 19 23 26
## 64 65 66 67 68 69 70 71
## 11 61 29 14 13 13 44 28
## 72 73 74 75 76 77 78 79
## 13 18 9 17 6 3 7 2
## 80 or more <NA>
## 45 766
mydata <- top_recode ("mid1_s4q7", break_point=60, missing=999999) # Topcode cases with 60 or farther
## [1] "Frequency table before encoding"
## mid1_s4q7. How far is the school from home?
## 0 1 2 3 4 5 6 7 8 10 11 12 13 15 17 20 25 30
## 99 847 308 143 42 51 17 13 10 5 1 1 3 5 1 3 1 2
## 36 60 115 215 220 350 1230 <NA>
## 1 1 1 1 1 1 1 5399
## [1] "Frequency table after encoding"
## mid1_s4q7. How far is the school from home?
## 0 1 2 3 4 5 6 7
## 99 847 308 143 42 51 17 13
## 8 10 11 12 13 15 17 20
## 10 5 1 1 3 5 1 3
## 25 30 36 60 or more <NA>
## 1 2 1 6 5399
mydata <- top_recode ("mid1_child_nhhmmbrs", break_point=10, missing=999999) # Topcode cases with 10 or more members
## [1] "Frequency table before encoding"
## mid1_child_nhhmmbrs.
## 2 3 4 5 6 7 8 9 11 14 <NA>
## 3 11 19 11 13 9 2 2 1 5 6882
## [1] "Frequency table after encoding"
## mid1_child_nhhmmbrs. 10
## 2 3 4 5 6 7 8 9
## 3 11 19 11 13 9 2 2
## 10 or more <NA>
## 6 6882
mydata <- top_recode ("mid1_s17q7", break_point=60, missing=999999) # Topcode cases with 60 or farther
## [1] "Frequency table before encoding"
## mid1_s17q7. How far is the school from home?
## 0 1 2 3 4 5 6 7 8 9 10 12 13 15 17 20 22 30
## 112 732 280 78 36 42 23 12 2 2 7 3 2 8 1 2 1 2
## 110 115 230 <NA>
## 1 2 2 5608
## [1] "Frequency table after encoding"
## mid1_s17q7. How far is the school from home?
## 0 1 2 3 4 5 6 7
## 112 732 280 78 36 42 23 12
## 8 9 10 12 13 15 17 20
## 2 2 7 3 2 8 1 2
## 22 30 60 or more <NA>
## 1 2 5 5608
mydata <- top_recode ("mid1_s4q8", break_point=60, missing=999999) # Topcode cases with 60 or longer
## [1] "Frequency table before encoding"
## mid1_s4q8. How long does it take to get to this school?
## 0 1 2 3 4 5 10 12 15 18 20 22 25 26 28 30 35 40
## 6 8 25 9 4 264 413 1 355 5 364 2 136 1 3 344 13 20
## 45 50 60 90 95 100 120 150 153 180 <NA>
## 46 8 59 2 1 1 4 8 1 2 4853
## [1] "Frequency table after encoding"
## mid1_s4q8. How long does it take to get to this school?
## 0 1 2 3 4 5 10 12
## 6 8 25 9 4 264 413 1
## 15 18 20 22 25 26 28 30
## 355 5 364 2 136 1 3 344
## 35 40 45 50 60 or more <NA>
## 13 20 46 8 78 4853
# !!!Include relevant variables in list below
indirect_PII <- c("mid1_occup0",
"mid1_s5q6c",
"mid1_occup1",
"mid1_s19q4c",
"mid1_ind0",
"mid1_s5q6_2c",
"mid1_ind1",
"mid1_s19q4bc",
"mid1_nhhmmbrs",
"mid1_s11q7",
"mid1_s3q4",
"mid1_s3q7",
"mid1_s3q8",
"mid1_s3q9a",
"mid1_s3q9d",
"mid1_s4q1",
"mid1_s4q2",
"mid1_s4q4",
"mid1_s4q6_8",
"mid1_s4q6_96",
"mid1_s4q9",
"mid1_s4q9_5",
"mid1_s4q9other",
"mid1_s4q11",
"mid1_s5q4b",
"mid1_s5q4c",
"mid1_s5q4d",
"mid1_s5q4f",
"mid1_s5q4g",
"mid1_s5q4i",
"mid1_s5q5",
"mid1_s5q6a",
"mid1_s5q11",
"mid1_s5q16",
"mid1_s5q18",
"mid1_s6q2",
"mid1_s6q7",
"mid1_s6q8",
"mid1_s17q6_8",
"mid1_s17q6_96",
"mid1_s17q8",
"mid1_s17q8_5",
"mid1_s17q9",
"mid1_s19q2d",
"mid1_s19q2e",
"mid1_s19q2f",
"mid1_s19q2h",
"mid1_s19q2i",
"mid1_s19q4a",
"mid1_s19q10_6",
"mid1_s19q10_12",
"mid1_s19q12",
"mid1_s19q13",
"mid1_s19q14",
"mid1_s20q2",
"mid1_s20q5",
"mid1_s20q7",
"mid1_s20q8",
"mid1_CLC5_11",
"mid1_CLC12_13",
"mid1_CLP5_11")
capture_tables (indirect_PII)
# Recode those with very specific values
# Removed, as verbatim responses are partially or entirely in Nepali.
dropvars <- c("mid1_occup0", "mid1_occup1", "mid1_ind0", "mid1_ind1")
mydata <- mydata[!names(mydata) %in% dropvars]
# Top code household composition variables with large and unusual numbers
mydata <- top_recode ("mid1_nhhmmbrs", break_point=10, missing=c(999999)) # Topcode cases with 10 or more members
## [1] "Frequency table before encoding"
## mid1_nhhmmbrs.
## 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 19
## 10 132 765 1315 1568 1237 659 478 145 195 112 137 62 30 40 18 1 34
## 26
## 20
## [1] "Frequency table after encoding"
## mid1_nhhmmbrs. 10
## 1 2 3 4 5 6 7 8
## 10 132 765 1315 1568 1237 659 478
## 9 10 or more
## 145 649
mydata <- top_recode ("mid1_numhhmbrs", break_point=10, missing=c(999999)) # Topcode cases with 10 or more members
## [1] "Frequency table before encoding"
## mid1_numhhmbrs.
## 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
## 175 46 477 1092 1425 1212 658 624 378 210 176 156 130 42 30 16 34 36
## 20 21
## 20 21
## [1] "Frequency table after encoding"
## mid1_numhhmbrs. 10
## 1 2 3 4 5 6 7 8
## 175 46 477 1092 1425 1212 658 624
## 9 10 or more
## 378 871
# Based on dictionary inspection, select variables for creating sdcMicro object
# See: https://sdcpractice.readthedocs.io/en/latest/anon_methods.html
# All variable names should correspond to the names in the data file
# selected categorical key variables: gender, occupation/education and age
mydata$sex <- mydata$mid1_s3q2
mydata$sex [is.na(mydata$sex)] <- mydata$mid1_s3q2a[is.na(mydata$sex)]
selectedKeyVars = c('sex', 'mid1_s3q8', 'mid1_s3q3') ##!!! Replace with candidate categorical demo vars
# weight variable
# !!! No weight
# selectedWeightVar = c('projwt') ##!!! Replace with weight var
# household id variable (cluster)
selectedHouseholdID = c('hhid')
# creating the sdcMicro object with the assigned variables
sdcInitial <- createSdcObj(dat = mydata,
keyVars = selectedKeyVars,
hhId = selectedHouseholdID)
sdcInitial
## The input dataset consists of 6958 rows and 568 variables.
## --> Categorical key variables: sex, mid1_s3q8, mid1_s3q3
## --> Cluster/Household-Id variable: hhid
## ----------------------------------------------------------------------
## Information on categorical key variables:
##
## Reported is the number, mean size and size of the smallest category >0 for recoded variables.
## In parenthesis, the same statistics are shown for the unmodified data.
## Note: NA (missings) are counted as seperate categories!
## Key Variable Number of categories Mean size Size of smallest (>0)
## sex 3 (3) 3094.500 (3094.500) 3039 (3039)
## mid1_s3q8 10 (10) 648.444 (648.444) 5 (5)
## mid1_s3q3 82 (82) 76.444 (76.444) 2 (2)
## ----------------------------------------------------------------------
## Infos on 2/3-Anonymity:
##
## Number of observations violating
## - 2-anonymity: 161 (2.314%)
## - 3-anonymity: 317 (4.556%)
## - 5-anonymity: 797 (11.454%)
##
## ----------------------------------------------------------------------
Show values of key variable of records that violate k-anonymity
notAnon <- sdcInitial@risk$individual[,2] < 2 # for 2-anonymity
as.data.frame(mydata[notAnon,selectedKeyVars])
## sex mid1_s3q8 mid1_s3q3
## 1 1 5 42
## 2 0 3 9
## 3 1 98 26
## 4 0 0 64
## 5 0 1 49
## 6 0 1 59
## 7 0 1 72
## 8 1 4 52
## 9 0 3 80
## 10 1 2 44
## 11 1 2 50
## 12 1 98 19
## 13 0 3 71
## 14 0 98 6
## 15 1 99 41
## 16 1 2 74
## 17 0 5 73
## 18 1 5 49
## 19 0 2 53
## 20 1 2 8
## 21 0 4 11
## 22 0 1 77
## 23 1 98 68
## 24 1 1 72
## 25 1 1 64
## 26 1 6 23
## 27 1 98 29
## 28 0 2 68
## 29 1 6 9
## 30 0 0 79
## 31 1 4 48
## 32 0 6 9
## 33 0 3 75
## 34 1 2 68
## 35 1 4 44
## 36 1 1 68
## 37 1 98 61
## 38 0 6 13
## 39 0 2 80
## 40 1 98 56
## 41 1 3 11
## 42 1 6 50
## 43 0 4 47
## 44 0 6 68
## 45 1 6 15
## 46 1 5 10
## 47 0 5 78
## 48 0 2 61
## 49 0 5 18
## 50 1 5 18
## 51 0 6 12
## 52 0 98 37
## 53 0 5 23
## 54 0 2 78
## 55 1 3 65
## 56 1 98 18
## 57 0 4 70
## 58 0 0 24
## 59 0 2 24
## 60 0 6 11
## 61 1 6 10
## 62 0 5 28
## 63 0 3 12
## 64 0 1 42
## 65 0 0 74
## 66 0 3 69
## 67 0 4 74
## 68 0 4 57
## 69 0 4 80
## 70 1 98 33
## 71 1 2 45
## 72 1 2 63
## 73 0 98 15
## 74 0 98 13
## 75 0 1 23
## 76 0 1 76
## 77 1 5 32
## 78 0 5 58
## 79 1 3 48
## 80 0 0 57
## 81 0 2 75
## 82 1 1 60
## 83 0 5 49
## 84 1 1 44
## 85 0 98 57
## 86 1 98 57
## 87 0 2 8
## 88 1 1 23
## 89 0 5 62
## 90 1 5 38
## 91 0 3 59
## 92 0 2 34
## 93 1 6 26
## 94 1 6 21
## 95 0 4 49
## 96 0 3 57
## 97 1 6 33
## 98 0 98 69
## 99 0 98 65
## 100 0 1 57
## 101 0 1 44
## 102 0 4 69
## 103 1 2 59
## 104 0 1 48
## 105 1 3 45
## 106 0 1 73
## 107 0 6 17
## 108 0 4 46
## 109 0 1 64
## 110 1 1 71
## 111 1 0 79
## 112 1 3 63
## 113 0 4 63
## 114 0 2 9
## 115 1 2 60
## 116 1 6 5
## 117 0 98 80
## 118 0 99 48
## 119 1 99 45
## 120 0 2 7
## 121 1 3 12
## 122 1 98 28
## 123 0 99 37
## 124 1 99 15
## 125 0 98 36
## 126 1 98 80
## 127 1 98 6
## 128 0 5 64
## 129 0 2 67
## 130 1 4 14
## 131 0 0 14
## 132 1 6 17
## 133 0 1 61
## 134 0 98 17
## 135 1 98 64
## 136 0 0 23
## 137 1 3 62
## 138 0 3 64
## 139 1 1 52
## 140 1 6 38
## 141 1 1 51
## 142 1 98 59
## 143 0 98 60
## 144 1 98 41
## 145 1 1 58
## 146 1 3 46
## 147 0 98 29
## 148 1 5 40
## 149 0 4 75
## 150 1 1 54
## 151 1 5 27
## 152 1 4 42
## 153 1 1 48
## 154 1 98 9
## 155 1 2 52
## 156 1 6 24
## 157 1 2 21
## 158 1 2 47
## 159 1 6 11
## 160 1 2 72
## 161 1 6 25
sdcFinal <- localSuppression(sdcInitial)
# Recombining anonymized variables (exclude children, as critical for analysis)
extractManipData(sdcFinal)[notAnon,selectedKeyVars] # manipulated variables HH
## Warning in if (cc != class(v_p)) {: the condition has length > 1 and only the first element
## will be used
## Warning in if (cc != class(v_p)) {: the condition has length > 1 and only the first element
## will be used
## Warning in if (cc != class(v_p)) {: the condition has length > 1 and only the first element
## will be used
## sex mid1_s3q8 mid1_s3q3
## 3 1 5 NA
## 4 0 3 NA
## 59 1 98 NA
## 70 0 0 NA
## 124 0 1 NA
## 153 0 1 NA
## 174 0 1 NA
## 229 1 4 NA
## 233 0 3 NA
## 261 1 2 NA
## 357 1 2 NA
## 369 1 98 NA
## 374 0 3 NA
## 476 0 98 NA
## 546 1 99 NA
## 559 1 2 NA
## 667 0 5 NA
## 668 1 5 NA
## 734 0 2 NA
## 823 1 2 NA
## 920 0 4 NA
## 948 0 1 NA
## 1113 1 98 NA
## 1133 1 1 NA
## 1163 1 1 NA
## 1171 1 6 NA
## 1306 1 98 NA
## 1354 0 2 NA
## 1389 1 6 NA
## 1444 0 0 NA
## 1449 1 4 NA
## 1532 0 6 NA
## 1549 0 3 NA
## 1551 1 2 NA
## 1566 1 4 NA
## 1574 1 1 NA
## 1615 1 98 NA
## 1640 0 6 NA
## 1665 0 2 NA
## 1908 1 98 NA
## 1987 1 3 NA
## 2122 1 6 NA
## 2144 0 4 NA
## 2212 0 6 NA
## 2217 1 6 NA
## 2299 1 5 NA
## 2349 0 5 NA
## 2360 0 2 NA
## 2424 0 5 NA
## 2425 1 5 NA
## 2576 0 6 NA
## 2600 0 98 NA
## 2662 0 5 NA
## 2686 0 2 NA
## 2724 1 3 NA
## 2841 1 98 NA
## 2884 0 4 NA
## 2910 0 0 NA
## 3012 0 2 NA
## 3051 0 6 NA
## 3056 1 6 NA
## 3071 0 5 NA
## 3166 0 3 NA
## 3167 0 1 NA
## 3189 0 0 NA
## 3261 0 3 NA
## 3298 0 4 NA
## 3344 0 4 NA
## 3380 0 4 NA
## 3384 1 98 NA
## 3404 1 2 NA
## 3519 1 2 NA
## 3634 0 98 NA
## 3638 0 98 NA
## 3645 0 1 NA
## 3730 0 1 NA
## 3736 1 5 NA
## 3738 0 5 NA
## 3741 1 3 NA
## 3910 0 0 NA
## 3916 0 2 NA
## 3970 1 1 NA
## 3977 0 5 NA
## 4024 1 1 NA
## 4085 0 98 NA
## 4087 1 98 NA
## 4093 0 2 NA
## 4137 1 1 NA
## 4242 0 5 NA
## 4243 1 5 NA
## 4262 0 3 NA
## 4315 0 2 NA
## 4350 1 6 NA
## 4351 1 6 NA
## 4372 0 4 NA
## 4378 0 3 NA
## 4387 1 6 NA
## 4394 0 98 NA
## 4430 0 98 NA
## 4455 0 1 NA
## 4458 0 1 NA
## 4483 0 4 NA
## 4490 1 2 NA
## 4502 0 1 NA
## 4522 1 3 NA
## 4561 0 1 NA
## 4624 0 6 NA
## 4627 0 4 NA
## 4724 0 1 NA
## 4836 1 1 NA
## 4857 1 0 NA
## 4870 1 3 NA
## 4875 0 4 NA
## 4887 0 2 NA
## 5032 1 2 NA
## 5045 1 6 NA
## 5065 0 98 NA
## 5144 0 99 NA
## 5147 1 99 NA
## 5158 0 2 NA
## 5159 1 3 NA
## 5168 1 98 NA
## 5170 0 99 NA
## 5242 1 99 NA
## 5261 0 98 NA
## 5390 1 98 NA
## 5405 1 98 NA
## 5419 0 5 NA
## 5480 0 2 NA
## 5543 1 4 NA
## 5570 0 0 NA
## 5581 1 6 NA
## 5607 0 1 NA
## 5614 0 98 NA
## 5664 1 98 NA
## 5729 0 0 NA
## 5775 1 3 NA
## 5794 0 3 NA
## 5860 1 1 NA
## 5883 1 6 NA
## 5943 1 1 NA
## 5986 1 98 NA
## 5992 0 98 NA
## 6024 1 98 NA
## 6058 1 1 NA
## 6078 1 3 NA
## 6084 0 98 NA
## 6272 1 5 NA
## 6273 0 4 NA
## 6379 1 1 NA
## 6404 1 5 NA
## 6521 1 4 NA
## 6553 1 1 NA
## 6576 1 98 NA
## 6612 1 2 NA
## 6699 1 6 NA
## 6739 1 2 NA
## 6798 1 2 NA
## 6822 1 6 NA
## 6874 1 2 NA
## 6937 1 6 NA
mydata [notAnon & mydata$mid1_s3q3 >17,"mid1_s3q3"] <- NA
#Check that 2-anonimity is now maintained
createSdcObj(dat = mydata, keyVars = selectedKeyVars, hhId = selectedHouseholdID)
## The input dataset consists of 6958 rows and 568 variables.
## --> Categorical key variables: sex, mid1_s3q8, mid1_s3q3
## --> Cluster/Household-Id variable: hhid
## ----------------------------------------------------------------------
## Information on categorical key variables:
##
## Reported is the number, mean size and size of the smallest category >0 for recoded variables.
## In parenthesis, the same statistics are shown for the unmodified data.
## Note: NA (missings) are counted as seperate categories!
## Key Variable Number of categories Mean size Size of smallest (>0)
## sex 3 (3) 3094.500 (3094.500) 3039 (3039)
## mid1_s3q8 10 (10) 648.444 (648.444) 5 (5)
## mid1_s3q3 81 (81) 75.763 (75.763) 2 (2)
## ----------------------------------------------------------------------
## Infos on 2/3-Anonymity:
##
## Number of observations violating
## - 2-anonymity: 0 (0.000%)
## - 3-anonymity: 5 (0.072%)
## - 5-anonymity: 39 (0.561%)
##
## ----------------------------------------------------------------------
mydata <- mydata[!names(mydata) %in% "sex"]
# !!! Identify open-end variables here:
open_ends <- c("mid1_s9q1_1other",
"mid1_s9q2_2other",
"mid1_s9q2_1other",
"mid1_s9q1_2other",
"mid1_s9q5other",
"mid1_s9q6other",
"mid1_s10q3other",
"mid1_s10q5other",
"mid1_s10q8other",
"mid1_s10q10other",
"mid1_s11q3other",
"mid1_s11q6other",
"mid1_s13q1other",
"mid1_s3q1other",
"mid1_s3q5other",
"mid1_s4q6other",
"mid1_s4q9other",
"mid1_s4q11other",
"mid1_s5q6",
"mid1_s5q6_2",
"mid1_s5q14other",
"mid1_s17q6other",
"mid1_s17q9other",
"mid1_s18q3other",
"mid1_s19q4",
"mid1_s19q4b")
report_open (list_open_ends = open_ends)
# Review "verbatims.csv". Identify variables to be deleted or redacted and their row number
mydata <- mydata[!names(mydata) %in% open_ends] # SDC risk could not be ascertained as all verbatims are partially or completely in Nepali.
# !!! No GPS data.
Adds "_PU" (Public Use) to the end of the name
haven::write_dta(mydata, paste0(filename, "_PU.dta"))
haven::write_sav(mydata, paste0(filename, "_PU.sav"))
#Add report title dynamically
title_var <- paste0("DOL-ILAB SDC - ", filename)