rm(list=ls(all=t))
filename <- "ecsection4_relabelled" # !!!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/Usuario/Documents/R/win-library/3.6/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/Usuario/Documents/R/win-library/3.6/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/Usuario/Documents/R/win-library/3.6/rgdal/proj
## Loading required package: spatstat.data
## Loading required package: spatstat.geom
## spatstat.geom 2.1-0
##
## 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.1-2
## Loading required package: spatstat.linnet
## spatstat.linnet 2.1-1
##
## spatstat 2.1-0 (nickname: 'Comedic violence')
## 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-5
## 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
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
dropvars <- c("dise")
mydata <- mydata[!names(mydata) %in% dropvars]
locvars <- c("q002_blckid", "q003_vill_id")
mydata <- encode_location (variables= locvars, missing=999999)
## [1] "Frequency table before encoding"
## q002_blckid. 002 Unique block ID
## 1 2 3 4 5 6 7 8 9
## 206 167 188 412 96 192 158 424 544
## [1] "Frequency table after encoding"
## q002_blckid. 002 Unique block ID
## 279 280 281 282 283 284 285 286 287
## 206 544 167 424 96 188 412 158 192
## [1] "Frequency table before encoding"
## q003_vill_id. 003 Village ID
## 1 2 3 4 5 6 7 8 9 10 11 12 13 15 16 17 18
## 17 16 17 16 20 29 29 16 15 13 17 26 24 14 18 21 18
## 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
## 18 20 30 23 18 18 32 25 27 17 14 13 24 26 21 16 28
## 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
## 19 15 22 27 16 16 18 16 27 21 22 21 20 17 17 17 18
## 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
## 27 25 27 19 13 21 12 24 19 17 19 18 30 16 19 21 25
## 70 71 72 73 74 75 76 77 78 80 81 82 83 84 85 87 88
## 13 16 21 16 23 22 18 23 30 30 16 21 17 17 13 18 22
## 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
## 16 19 20 18 20 14 20 24 28 21 26 17 25 20 15 19 16
## 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
## 31 13 28 22 17 21 27 15 24 20 14 24 22 21 13 13 10
## <NA>
## 1
## [1] "Frequency table after encoding"
## q003_vill_id. 003 Village ID
## 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625
## 18 16 24 20 21 16 27 13 20 18 19 17 23 17 10 21 19
## 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642
## 18 24 24 16 27 23 32 21 28 19 16 16 30 25 21 20 27
## 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659
## 21 28 18 29 25 25 16 17 20 24 17 31 15 21 17 13 26
## 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676
## 26 22 30 12 14 18 27 14 15 17 23 21 24 22 22 20 21
## 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693
## 21 27 17 16 30 13 24 19 20 18 17 16 16 29 16 21 22
## 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710
## 18 16 14 16 19 18 17 28 19 25 13 13 21 13 17 15 20
## 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727
## 22 27 30 22 16 13 14 20 26 17 19 18 18 15 18 17 13
## <NA>
## 1
!!! No action as variables are critical for analysis #Indirect PII - Categorical: Recode, encode, or Top/bottom coding for extreme values
indirect_PII <- c("q401_wrkdne_bfresunrise",
"q402_prob_inadqlight",
"q403_loudnoise_wrk",
"q404_wrk_extrmtemp",
"q405_wrk_brickcement",
"q406_wrk_stonebk_crush",
"q407_polish_gntestone",
"q408_wrk_construction",
"q409_wrk_carryhvy_load",
"q410_wrk_opertmachine",
"q411_wrk_injured",
"q412_wrk_hndlchemicls",
"q413_wrk_werglovmsk",
"q414_health_inwrk",
"q415_wrk_danger",
"q416_wrk_whodecids",
"q417_descrb_wrksite",
"q418_wrk_wrksite_lst12m",
"q419_dayoff_ifnotwell",
"q420_refdngtask_atwrk",
"q421_leavwrk_ifwanted",
"q422a_wrkng_offdebt",
"q422b_parent_punish",
"q422c_emplr_punish",
"q422d_noothwrk_avble",
"q422e_notengh_mny",
"q422f_dk_whrtogo",
"q422g_resp_eldrdecisn",
"q422h_fear_parents",
"q422i_parent_illness",
"q422j_finshrtg_hh",
"q422k_helpmthr",
"q422l_bczmthr_wrks",
"q422m_lovefor_wrk",
"q422n_noone_wrkathome",
"q422o_eldsib_athome",
"q422p_noone_infmly_gvemny",
"q422q_dkntwnt_leav",
"q422r_noone_athome",
"q422s_toern_mnysupp_edu",
"q422t_erntofeed_cattle",
"q422u_assist_sis",
"q422v_others",
"q423_hrswrk_lst12m",
"q424a_cash",
"q424b_newskill",
"q424c_education",
"q424d_shelter_foodcloths",
"q424e_medicalsupp",
"q424f_nothing",
"q424g_toys",
"q424h_fruits_veg",
"q424i_chocolate",
"q424j_dryfruit",
"q424k_bangles",
"q424l_jewellery",
"q424m_breakfast",
"q424n_utensils",
"q424o_snacks",
"q425_emplr_ben_parent",
"q426_earn_inaweek")
capture_tables (indirect_PII)
!!! No action as variables are critical for analysis #Open-ends: review responses for any sensitive information, redact as necessary !!! No open-ends
# Drop all, as actually verbatim data in Hindi
mydata <- mydata[!names(mydata) %in% "q416_whether_oth"]
mydata <- mydata[!names(mydata) %in% "q417_desc_site_oth"]
!!! No GPS data
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)