rm(list=ls(all=t))

Setup filenames

filename <- "Section_5" # !!!Update filename
functions_vers <-  "functions_1.8.R" # !!!Update helper functions file

Setup data, functions and create dictionary for dataset review

source (functions_vers)

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 

Direct PII: variables to be removed

mydata$household_id <- zap_labels(mydata$household_id)

Direct PII-team: Encode field team names

# !!!No Direct PII - team

Small locations: Encode locations with pop <100,000 using random large numbers

# !!!No Small locations

Indirect PII - Ordinal: Global recode or Top/bottom coding for extreme values

# Top code high income to the 99.5 percentile

percentile_99.5 <- floor(quantile(na.exclude(mydata$m_s5q4)[na.exclude(mydata$m_s5q4)!=999999], probs = c(0.995)))
mydata <- top_recode (variable="m_s5q4", break_point=percentile_99.5, missing=999999)
## [1] "Frequency table before encoding"
## m_s5q4. sEq4: How much cash did you receive?  Magkano ang perang inyong natanggap?
##  -998   500   600  1000  1600  1800  2200  2280  2400  2500  2600  2800  3000  3600  3800  4000  4300  4400  4600  4800  5000  5200  5400  5500  5600  6000  6200  6300  6400  6600  6800  6900 
##    41     1     1     1     1     1     1     1     4     1     1     1     1     2     1     3     1     3     2     4     4     1     1     2     1    11     4     1     5     7     3     1 
##  7000  7100  7200  7400  7500  7600  7700  7800  7900  8000  8200  8300  8400  8600  8700  8800  8900  9000  9100  9200  9300  9400  9500  9600  9680  9700  9800  9900 10000 10100 10146 10175 
##     1     1    15     3     1     8     3     9     1    11     6     2    11     5     2    15     4    16     3     5     3     3     4    48     1     2     7     1    13     4     1     1 
## 10200 10300 10400 10500 10600 10700 10800 10900 11000 11100 11200 11400 11500 11600 11700 11800 11900 12000 12100 12200 12300 12400 12500 12600 12700 12800 12900 13000 13100 13200 13300 13400 
##    21     6    10     3    14     6    50     3    19     4    17    20     1    19     1    12     2    43     3     9     7     9     3    23     3    20     4    14     2    94     7     6 
## 13500 13600 13700 13800 13900 14000 14100 14108 14200 14270 14300 14400 14500 14600 14700 14800 14900 15000 15100 15200 15300 15400 15500 15600 15700 15800 16000 16100 16200 16300 16400 16500 
##     2    18     5    38     1     9     1     1    25     1     5    51     3    11     6    32     3    36     3    18     6     8     3    49     5    26    12     2    30     8     6     7 
## 16520 16600 16700 16800 16900 17000 17100 17200 17300 17400 17600 17700 17800 17900 18000 18100 18200 18300 18400 18500 18600 18700 18800 19000 19100 19200 19300 19400 19500 19600 19700 19800 
##     1    18     3    99     1     4     2    17     2    23     7     1    21     2    43     1    11     2     8     1    26     2    17    10     1    59     2    10     1     6     1    28 
## 19900 20000 20100 20200 20300 20400 20500 20600 20700 20800 20900 21000 21200 21300 21400 21600 21700 21800 22000 22200 22300 22400 22600 22700 22800 22900 23200 23400 23600 23700 23800 24000 
##     4     3     2     9     2    51     5     3     2    18     1    31     2     1     2    29     2     6     3    11     2     1     6     2    31     1     3    14     1     2     3    14 
## 24200 24500 24600 24800 25000 25200 25600 25700 25800 26400 27000 27600 28200 28600 29200 30000 36000 44400 62800 71600  <NA> 
##     1     1     4     1     2    12     1     1     6     4     1     2     2     1     1     1     1     1     1     1   334

## [1] "Frequency table after encoding"
## m_s5q4. sEq4: How much cash did you receive?  Magkano ang perang inyong natanggap?
##          -998           500           600          1000          1600          1800          2200          2280          2400          2500          2600          2800          3000 
##            41             1             1             1             1             1             1             1             4             1             1             1             1 
##          3600          3800          4000          4300          4400          4600          4800          5000          5200          5400          5500          5600          6000 
##             2             1             3             1             3             2             4             4             1             1             2             1            11 
##          6200          6300          6400          6600          6800          6900          7000          7100          7200          7400          7500          7600          7700 
##             4             1             5             7             3             1             1             1            15             3             1             8             3 
##          7800          7900          8000          8200          8300          8400          8600          8700          8800          8900          9000          9100          9200 
##             9             1            11             6             2            11             5             2            15             4            16             3             5 
##          9300          9400          9500          9600          9680          9700          9800          9900         10000         10100         10146         10175         10200 
##             3             3             4            48             1             2             7             1            13             4             1             1            21 
##         10300         10400         10500         10600         10700         10800         10900         11000         11100         11200         11400         11500         11600 
##             6            10             3            14             6            50             3            19             4            17            20             1            19 
##         11700         11800         11900         12000         12100         12200         12300         12400         12500         12600         12700         12800         12900 
##             1            12             2            43             3             9             7             9             3            23             3            20             4 
##         13000         13100         13200         13300         13400         13500         13600         13700         13800         13900         14000         14100         14108 
##            14             2            94             7             6             2            18             5            38             1             9             1             1 
##         14200         14270         14300         14400         14500         14600         14700         14800         14900         15000         15100         15200         15300 
##            25             1             5            51             3            11             6            32             3            36             3            18             6 
##         15400         15500         15600         15700         15800         16000         16100         16200         16300         16400         16500         16520         16600 
##             8             3            49             5            26            12             2            30             8             6             7             1            18 
##         16700         16800         16900         17000         17100         17200         17300         17400         17600         17700         17800         17900         18000 
##             3            99             1             4             2            17             2            23             7             1            21             2            43 
##         18100         18200         18300         18400         18500         18600         18700         18800         19000         19100         19200         19300         19400 
##             1            11             2             8             1            26             2            17            10             1            59             2            10 
##         19500         19600         19700         19800         19900         20000         20100         20200         20300         20400         20500         20600         20700 
##             1             6             1            28             4             3             2             9             2            51             5             3             2 
##         20800         20900         21000         21200         21300         21400         21600         21700         21800         22000         22200         22300         22400 
##            18             1            31             2             1             2            29             2             6             3            11             2             1 
##         22600         22700         22800         22900         23200         23400         23600         23700         23800         24000         24200         24500         24600 
##             6             2            31             1             3            14             1             2             3            14             1             1             4 
##         24800         25000         25200         25600         25700         25800         26400         27000 27600 or more          <NA> 
##             1             2            12             1             1             6             4             1            11           334

percentile_99.5 <- floor(quantile(na.exclude(mydata$m_s5q5)[na.exclude(mydata$m_s5q5)!=999999], probs = c(0.995)))
mydata <- top_recode (variable="m_s5q5", break_point=percentile_99.5, missing=999999)
## [1] "Frequency table before encoding"
## m_s5q5. sEq5: What was the value of the in-kind transfer?  Ano ang halaga ng hindi pera 
##  200  300  500  600  800 1000 1200 2000 3000 3600 5000 6400 8900 9000 <NA> 
##    1    2    2    2    1    1    1    2    1    1    1    1    1    1 2267

## [1] "Frequency table after encoding"
## m_s5q5. sEq5: What was the value of the in-kind transfer?  Ano ang halaga ng hindi pera 
##          200          300          500          600          800         1000         1200         2000         3000         3600         5000         6400         8900 8991 or more 
##            1            2            2            2            1            1            1            2            1            1            1            1            1            1 
##         <NA> 
##         2267

percentile_99.5 <- floor(quantile(na.exclude(mydata$m_s5q9)[na.exclude(mydata$m_s5q9)!=999999], probs = c(0.995)))
mydata <- top_recode (variable="m_s5q9", break_point=percentile_99.5, missing=999999)
## [1] "Frequency table before encoding"
## m_s5q9. sEq9: How much cash did you receive?  Magkano ang perang inyong natanggap?
##  -998   100   150   260   500   700  1200  1500  3000  4000  5000  5115  6000  6350  7000  7500  8000 10000 13200 15000 20000  <NA> 
##     1     1     1     1     1     1     1     2     1     2    34     1     1     1     4     1     2    36     1     1     2  2189

## [1] "Frequency table after encoding"
## m_s5q9. sEq9: How much cash did you receive?  Magkano ang perang inyong natanggap?
##          -998           100           150           260           500           700          1200          1500          3000          4000          5000          5115          6000 
##             1             1             1             1             1             1             1             2             1             2            34             1             1 
##          6350          7000          7500          8000         10000         13200         15000 20000 or more          <NA> 
##             1             4             1             2            36             1             1             2          2189

percentile_99.5 <- floor(quantile(na.exclude(mydata$m_s5q10)[na.exclude(mydata$m_s5q10)!=999999], probs = c(0.995)))
mydata <- top_recode (variable="m_s5q10", break_point=percentile_99.5, missing=999999)
## [1] "Frequency table before encoding"
## m_s5q10. sEq10: What was the value of the in-kind transfer?  Ano ang halaga ng hindi pera
##  -998   130   150   168   180   200   225   240   250   270   280   300   350   500   600   900  1000  1200  1285  1500  1636  1983  2000  2500  3000  3800  5000  5320  5340  5345  5500  5556 
##     1     3     1     1     1     2     1     1     1     1     1     1     1    13     1     1     3     2     1     1     1     1     1     1     1     1     3     1     1     1     1     1 
##  6000  7884  8350 10000 10500 14000 15000 16000 17970 18230 18340 20000 28000 37000 75000  <NA> 
##     2     1     1     6     1     3     1     1     1     1     1     2     1     1     1  2209

## [1] "Frequency table after encoding"
## m_s5q10. sEq10: What was the value of the in-kind transfer?  Ano ang halaga ng hindi pera
##          -998           130           150           168           180           200           225           240           250           270           280           300           350 
##             1             3             1             1             1             2             1             1             1             1             1             1             1 
##           500           600           900          1000          1200          1285          1500          1636          1983          2000          2500          3000          3800 
##            13             1             1             3             2             1             1             1             1             1             1             1             1 
##          5000          5320          5340          5345          5500          5556          6000          7884          8350         10000         10500         14000         15000 
##             3             1             1             1             1             1             2             1             1             6             1             3             1 
##         16000         17970         18230         18340         20000         28000         37000 60750 or more          <NA> 
##             1             1             1             1             2             1             1             1          2209

percentile_99.5 <- floor(quantile(na.exclude(mydata$m_s5q12)[na.exclude(mydata$m_s5q12)!=999999], probs = c(0.995)))
mydata <- top_recode (variable="m_s5q12", break_point=percentile_99.5, missing=999999)
## [1] "Frequency table before encoding"
## m_s5q12. sEq12: How much money in pesos did your household receive in the past 12 months 
##   2000   3000   3300   4000   5000   6000   8000  13200  14400  15400  18000  19800  20000  21000  21600  21870  22000  23000  24000  26400  27500  28000  28800  30000  40800  52945  63600 
##      1      1      1      1      1      2      2      1      3      1      1      1      2      1      1      1      2      1      1      2      1      1      2      1      1      1      1 
## 120000   <NA> 
##      1   2249

## [1] "Frequency table after encoding"
## m_s5q12. sEq12: How much money in pesos did your household receive in the past 12 months 
##           2000           3000           3300           4000           5000           6000           8000          13200          14400          15400          18000          19800 
##              1              1              1              1              1              2              2              1              3              1              1              1 
##          20000          21000          21600          21870          22000          23000          24000          26400          27500          28000          28800          30000 
##              2              1              1              1              2              1              1              2              1              1              2              1 
##          40800          52945          63600 110130 or more           <NA> 
##              1              1              1              1           2249

percentile_99.5 <- floor(quantile(na.exclude(mydata$m_s5q13)[na.exclude(mydata$m_s5q13)!=999999], probs = c(0.995)))
mydata <- top_recode (variable="m_s5q13", break_point=percentile_99.5, missing=999999)
## [1] "Frequency table before encoding"
## m_s5q13. sEq13: How much did your household receive in benefits each month?  Magkano po a
##  -998  1000  1100  1200  1500  1510  1700  1800  2000  2400  2817  3337  4800  5300 10000  <NA> 
##     1     1     1     1     1     1     3     1     1     3     1     1     1     1     1  2266

## [1] "Frequency table after encoding"
## m_s5q13. sEq13: How much did your household receive in benefits each month?  Magkano po a
##         -998         1000         1100         1200         1500         1510         1700         1800         2000         2400         2817         3337         4800         5300 
##            1            1            1            1            1            1            3            1            1            3            1            1            1            1 
## 9577 or more         <NA> 
##            1         2266

percentile_99.5 <- floor(quantile(na.exclude(mydata$m_s5q15)[na.exclude(mydata$m_s5q15)!=999999], probs = c(0.995)))
mydata <- top_recode (variable="m_s5q15", break_point=percentile_99.5, missing=999999)
## [1] "Frequency table before encoding"
## m_s5q15. sEq15: What was the value of the in-kind transfer you received?  Magkano po ang 
##  -998   200   250   300   400   500   700  1000  2000  2555  2635  2650  2850  3000  4000  4300  4800  5000  5200  5400  5500  5600  5742  5782  5800  5900  5907  6000  6500  6700  6800  6900 
##     8     1     1     2     1     3     1     1     2     1     1     1     1     1     1     2     1    18     1     1     1     1     1     1     1     1     1    15     4     1     1     1 
##  6980  7000  7100  7200  7420  7500  7600  7800  7900  8000  8040  8075  8200  8273  8330  8400  8500  8920  9000  9245  9400  9500  9800  9890  9900  9935  9950  9952  9953  9954  9972 10000 
##     1    21     2     1     1     3     1     3     2    28     1     1     1     1     1     1     1     1    25     1     1     7     4     1     2     1     1     5     1     1     1   540 
## 11200 12000 15000 15600 20000 20800 21200 25800 35000  <NA> 
##     1     1     2     1     1     1     1     1     1  1535

## [1] "Frequency table after encoding"
## m_s5q15. sEq15: What was the value of the in-kind transfer you received?  Magkano po ang 
##          -998           200           250           300           400           500           700          1000          2000          2555          2635          2650          2850 
##             8             1             1             2             1             3             1             1             2             1             1             1             1 
##          3000          4000          4300          4800          5000          5200          5400          5500          5600          5742          5782          5800          5900 
##             1             1             2             1            18             1             1             1             1             1             1             1             1 
##          5907          6000          6500          6700          6800          6900          6980          7000          7100          7200          7420          7500          7600 
##             1            15             4             1             1             1             1            21             2             1             1             3             1 
##          7800          7900          8000          8040          8075          8200          8273          8330          8400          8500          8920          9000          9245 
##             3             2            28             1             1             1             1             1             1             1             1            25             1 
##          9400          9500          9800          9890          9900          9935          9950          9952          9953          9954          9972         10000         11200 
##             1             7             4             1             2             1             1             5             1             1             1           540             1 
##         12000         15000         15600         20000 20203 or more          <NA> 
##             1             2             1             1             4          1535

percentile_99.5 <- floor(quantile(na.exclude(mydata$m_s5q17)[na.exclude(mydata$m_s5q17)!=999999], probs = c(0.995)))
mydata <- top_recode (variable="m_s5q17", break_point=percentile_99.5, missing=999999)
## [1] "Frequency table before encoding"
## m_s5q17. sEq17: How much did your household receive in benefits in the last 12 months?  M
##  -998  1500  2600  3000  3600  3700  4000  4600  5000  6000  7000  7500  8563 10000 12000 15000 18000 19000 25500 28000 30000 62000  <NA> 
##     1     1     1     1     1     1     3     1     1     1     2     1     1     2     1     1     1     1     1     1     1     1  2259

## [1] "Frequency table after encoding"
## m_s5q17. sEq17: How much did your household receive in benefits in the last 12 months?  M
##          -998          1500          2600          3000          3600          3700          4000          4600          5000          6000          7000          7500          8563 
##             1             1             1             1             1             1             3             1             1             1             2             1             1 
##         10000         12000         15000         18000         19000         25500         28000         30000 58000 or more          <NA> 
##             2             1             1             1             1             1             1             1             1          2259

percentile_99.5 <- floor(quantile(na.exclude(mydata$m_s5q19)[na.exclude(mydata$m_s5q19)!=999999], probs = c(0.995)))
mydata <- top_recode (variable="m_s5q19", break_point=percentile_99.5, missing=999999)
## [1] "Frequency table before encoding"
## m_s5q19. sEq21: How much did your household receive in total from the government or NGOs 
##   -998      0    150    180    200    270    300    350    400    500    600    900   1000   1200   1500   1636   1800   2000   2400   2500   2560   2600   2800   2970   3000   3600   3700 
##     40    168      1      1      5      1      2      1      1      6      1      1      2      1      2      1      2      4      2      1      2      1      1      1      2      1      1 
##   4000   4100   4300   4400   4500   4600   4800   5000   5200   5400   5500   5900   6000   6200   6280   6400   6500   6600   6700   7000   7200   7285   7400   7500   7600   7700   7800 
##      3      1      1      1      2      3      2     12      1      1      1      1     13      3      1      4      2      4      1      9     12      1      1      1      9      2      8 
##   8000   8200   8300   8400   8500   8563   8600   8700   8800   8900   9000   9100   9200   9400   9500   9600   9700   9800   9900   9952  10000  10175  10200  10300  10400  10500  10600 
##     16      2      2     10      1      1      4      2      8      3     15      3      4      1      4     28      1      3      1      1     66      1     17      4      7      7      8 
##  10700  10740  10800  10900  11000  11100  11200  11300  11400  11500  11600  11700  11800  11900  12000  12100  12130  12200  12300  12400  12500  12600  12700  12782  12800  12900  13000 
##      2      1     22      3     15      1     11      1      9      2     10      1      7      2     27      2      1      3      5      9      5      8      1      1      9      4     13 
##  13050  13200  13300  13400  13500  13600  13700  13730  13800  13900  14000  14100  14200  14300  14400  14450  14500  14600  14700  14800  14870  15000  15100  15168  15200  15300  15400 
##      1     55      4      5      3      9      4      1     24      1      6      1      9      2     28      1      2     10      7     15      1     19      5      1     10      5      5 
##  15500  15600  15700  15800  16000  16150  16200  16300  16400  16500  16520  16600  16700  16800  16900  17000  17056  17100  17200  17300  17400  17500  17600  17700  17800  17900  17980 
##      3     36      2     14      7      1     15      9      9      4      1     13      2     45      3      7      1      4     12      2     13      1      8      4     18      3      1 
##  18000  18100  18200  18300  18400  18500  18600  18700  18800  19000  19100  19200  19250  19300  19355  19400  19450  19500  19600  19680  19700  19800  19850  20000  20100  20200  20300 
##     30      2      9      4      6      3     14      4     14     10      4     39      1      3      1      9      1      3      9      1      5     23      1     14      4     10      4 
##  20400  20500  20560  20600  20700  20800  21000  21100  21200  21275  21300  21400  21500  21554  21600  21700  21800  21900  22000  22100  22200  22250  22266  22300  22345  22400  22500 
##     26      4      1     15      6     20     15      2      7      1      2      7      2      1     26      5      6      2      5      2     14      1      1      5      1      3      2 
##  22600  22700  22800  22900  23000  23050  23100  23152  23200  23300  23400  23500  23600  23650  23700  23800  23835  23900  24000  24073  24100  24140  24200  24220  24250  24300  24400 
##     15      2     25      4     13      1      1      1     19      4      6      4      5      1      3     12      1      3     16      1      1      1      7      1      1      5     17 
##  24500  24600  24700  24752  24800  24900  25000  25100  25200  25260  25300  25400  25500  25600  25700  25730  25800  26000  26200  26300  26400  26500  26530  26550  26600  26700  26750 
##      4      3      1      1      6      2      8      5     13      1      4      5      2      7      2      1     14      2      9      4      4      1      1      1      5      2      1 
##  26800  26900  26950  27000  27100  27200  27300  27320  27350  27400  27600  27742  27800  27900  28000  28100  28200  28300  28400  28600  28700  28800  29000  29200  29250  29300  29356 
##     19      2      1      8      3      7      3      1      1      5      1      1      8      1     10      1      6      3      6     10      2      7      2     11      1      1      1 
##  29400  29500  29600  29700  29800  29900  29925  30000  30050  30100  30184  30200  30300  30400  30500  30550  30600  30688  30700  30800  31000  31100  31150  31200  31215  31257  31300 
##      5      1      2      1      2      4      1      2      1      2      1      1      1     12      2      1      2      1      2      8      4      1      2      1      1      1      1 
##  31400  31500  31600  31800  31900  32000  32120  32200  32300  32400  32600  32800  32845  32900  33200  33300  33400  33500  33550  33600  33656  33800  33900  34000  34050  34100  34300 
##      2      3      6      9      1      2      1      2      2      1      3      6      1      2      3      1      4      1      1      1      1      5      1      3      1      1      1 
##  34400  34600  34725  34800  35000  35200  35300  35400  35600  35800  35900  36000  36200  36300  36500  36600  36649  36800  36900  37100  37300  37400  37500  37600  37800  38000  38135 
##      1      2      1      2      2      3      2      1      3      5      2      4      1      2      1      1      1      1      1      2      1      1      1      1      2      1      1 
##  38156  38200  38600  38800  39200  39400  39570  39600  39800  39898  40000  40300  40500  40600  41000  41400  41600  41753  42400  43000  43500  43600  44000  44400  44800  45000  45400 
##      1      1      1      2      1      2      1      1      1      1      3      1      1      1      3      2      1      1      2      1      1      1      1      2      1      1      1 
##  45800  46000  46300  46733  46800  47400  47800  48000  48200  48450  48630  48800  49200  49400  49600  50000  50700  51000  51050  51140  52100  52400  52900  53000  53410  54000  54300 
##      1      1      1      1      1      1      1      1      1      1      1      1      1      1      1      1      1      1      1      1      1      1      1      1      1      1      1 
##  54900  55500  56400  57000  57600  62000  65400  68245  72772  73200  76800  81600  87200  88200 104200 110400 130200 186000 
##      1      1      1      1      1      1      1      1      1      1      1      1      1      1      1      1      1      1

## [1] "Frequency table after encoding"
## m_s5q19. sEq21: How much did your household receive in total from the government or NGOs 
##          -998             0           150           180           200           270           300           350           400           500           600           900          1000 
##            40           168             1             1             5             1             2             1             1             6             1             1             2 
##          1200          1500          1636          1800          2000          2400          2500          2560          2600          2800          2970          3000          3600 
##             1             2             1             2             4             2             1             2             1             1             1             2             1 
##          3700          4000          4100          4300          4400          4500          4600          4800          5000          5200          5400          5500          5900 
##             1             3             1             1             1             2             3             2            12             1             1             1             1 
##          6000          6200          6280          6400          6500          6600          6700          7000          7200          7285          7400          7500          7600 
##            13             3             1             4             2             4             1             9            12             1             1             1             9 
##          7700          7800          8000          8200          8300          8400          8500          8563          8600          8700          8800          8900          9000 
##             2             8            16             2             2            10             1             1             4             2             8             3            15 
##          9100          9200          9400          9500          9600          9700          9800          9900          9952         10000         10175         10200         10300 
##             3             4             1             4            28             1             3             1             1            66             1            17             4 
##         10400         10500         10600         10700         10740         10800         10900         11000         11100         11200         11300         11400         11500 
##             7             7             8             2             1            22             3            15             1            11             1             9             2 
##         11600         11700         11800         11900         12000         12100         12130         12200         12300         12400         12500         12600         12700 
##            10             1             7             2            27             2             1             3             5             9             5             8             1 
##         12782         12800         12900         13000         13050         13200         13300         13400         13500         13600         13700         13730         13800 
##             1             9             4            13             1            55             4             5             3             9             4             1            24 
##         13900         14000         14100         14200         14300         14400         14450         14500         14600         14700         14800         14870         15000 
##             1             6             1             9             2            28             1             2            10             7            15             1            19 
##         15100         15168         15200         15300         15400         15500         15600         15700         15800         16000         16150         16200         16300 
##             5             1            10             5             5             3            36             2            14             7             1            15             9 
##         16400         16500         16520         16600         16700         16800         16900         17000         17056         17100         17200         17300         17400 
##             9             4             1            13             2            45             3             7             1             4            12             2            13 
##         17500         17600         17700         17800         17900         17980         18000         18100         18200         18300         18400         18500         18600 
##             1             8             4            18             3             1            30             2             9             4             6             3            14 
##         18700         18800         19000         19100         19200         19250         19300         19355         19400         19450         19500         19600         19680 
##             4            14            10             4            39             1             3             1             9             1             3             9             1 
##         19700         19800         19850         20000         20100         20200         20300         20400         20500         20560         20600         20700         20800 
##             5            23             1            14             4            10             4            26             4             1            15             6            20 
##         21000         21100         21200         21275         21300         21400         21500         21554         21600         21700         21800         21900         22000 
##            15             2             7             1             2             7             2             1            26             5             6             2             5 
##         22100         22200         22250         22266         22300         22345         22400         22500         22600         22700         22800         22900         23000 
##             2            14             1             1             5             1             3             2            15             2            25             4            13 
##         23050         23100         23152         23200         23300         23400         23500         23600         23650         23700         23800         23835         23900 
##             1             1             1            19             4             6             4             5             1             3            12             1             3 
##         24000         24073         24100         24140         24200         24220         24250         24300         24400         24500         24600         24700         24752 
##            16             1             1             1             7             1             1             5            17             4             3             1             1 
##         24800         24900         25000         25100         25200         25260         25300         25400         25500         25600         25700         25730         25800 
##             6             2             8             5            13             1             4             5             2             7             2             1            14 
##         26000         26200         26300         26400         26500         26530         26550         26600         26700         26750         26800         26900         26950 
##             2             9             4             4             1             1             1             5             2             1            19             2             1 
##         27000         27100         27200         27300         27320         27350         27400         27600         27742         27800         27900         28000         28100 
##             8             3             7             3             1             1             5             1             1             8             1            10             1 
##         28200         28300         28400         28600         28700         28800         29000         29200         29250         29300         29356         29400         29500 
##             6             3             6            10             2             7             2            11             1             1             1             5             1 
##         29600         29700         29800         29900         29925         30000         30050         30100         30184         30200         30300         30400         30500 
##             2             1             2             4             1             2             1             2             1             1             1            12             2 
##         30550         30600         30688         30700         30800         31000         31100         31150         31200         31215         31257         31300         31400 
##             1             2             1             2             8             4             1             2             1             1             1             1             2 
##         31500         31600         31800         31900         32000         32120         32200         32300         32400         32600         32800         32845         32900 
##             3             6             9             1             2             1             2             2             1             3             6             1             2 
##         33200         33300         33400         33500         33550         33600         33656         33800         33900         34000         34050         34100         34300 
##             3             1             4             1             1             1             1             5             1             3             1             1             1 
##         34400         34600         34725         34800         35000         35200         35300         35400         35600         35800         35900         36000         36200 
##             1             2             1             2             2             3             2             1             3             5             2             4             1 
##         36300         36500         36600         36649         36800         36900         37100         37300         37400         37500         37600         37800         38000 
##             2             1             1             1             1             1             2             1             1             1             1             2             1 
##         38135         38156         38200         38600         38800         39200         39400         39570         39600         39800         39898         40000         40300 
##             1             1             1             1             2             1             2             1             1             1             1             3             1 
##         40500         40600         41000         41400         41600         41753         42400         43000         43500         43600         44000         44400         44800 
##             1             1             3             2             1             1             2             1             1             1             1             2             1 
##         45000         45400         45800         46000         46300         46733         46800         47400         47800         48000         48200         48450         48630 
##             1             1             1             1             1             1             1             1             1             1             1             1             1 
##         48800         49200         49400         49600         50000         50700         51000         51050         51140         52100         52400         52900         53000 
##             1             1             1             1             1             1             1             1             1             1             1             1             1 
##         53410         54000         54300         54900         55500         56400         57000         57600         62000 63971 or more 
##             1             1             1             1             1             1             1             1             1            12

Indirect PII - Categorical: Recode, encode, or Top/bottom coding for extreme values

# !!!Include relevant variables in list below (Indirect PII - Categorical, and Ordinal if not processed yet)

indirect_PII <- c("m_s5q2",
                  "m_s5q3",
                  "m_s5q6",
                  "m_s5q8",
                  "m_s5q11",
                  "m_s5q14",
                  "m_s5q16",
                  "m_s5q18",
                  "m_s5q21")

capture_tables (indirect_PII)

# Recode those with very specific values. 
# !!!No very specific values

Matching and crosstabulations: Run automated PII check

Open-ends: review responses for any sensitive information, redact as necessary

# !!! Identify open-end variables here: 
open_ends <- c("m_s5q20",
              "m_s5q20_other",
              "m_endnote5")

report_open (list_open_ends = open_ends)


# Review "verbatims.csv". Identify variables to be deleted or redacted and their row number 

mydata$m_s5q20[122] <- "Other"
mydata$m_s5q20[425] <- "Other"
mydata$m_s5q20[654] <- "Other"
mydata$m_s5q20[755] <- "Other"
mydata$m_s5q20[791] <- "Other"
mydata$m_s5q20[847] <- "Other"
mydata$m_s5q20[1003] <- "Other"
mydata$m_s5q20[1730] <- "Other"

mydata$m_endnote5[41] <- "4Ps benefits were received by [name] and he'll be the one to distribute it to his siblings who's studying in high school. So the respondent does not have an idea about the amount."
mydata$m_endnote5[63] <- "Only one student is beneficiary of 4Ps, that's why they only received a small amount. While the items from DOLE were left to [name 1] (other DOLE benefeciary)by [name 2] when sh's gone to Manila to worked. And [name 3] is the one who gets the money of the sold items."
mydata$m_endnote5[94] <- "[name] also conducted training regarding livelihood"
mydata$m_endnote5[303] <- "[Tagalog]"
mydata$m_endnote5[380] <- "[Tagalog]"
mydata$m_endnote5[854] <- "[Tagalog]"
mydata$m_endnote5[1075] <- "[Tagalog]"
mydata$m_endnote5[1764] <- "[Tagalog]"
mydata$m_endnote5[126] <- "The responses pertaining to 4Ps benefits were  answered by respondent's wife, [name]"
mydata$m_endnote5[165] <- "The ATM is in his daughter [name] living in [small location]. He dont know how much they received in 4Ps."
mydata$m_endnote5[185] <- "Respondent is not a 4Ps member but her 3 step children ([name], [name] and [name]) received a cash benefits from the 4Ps because they were covered from their aunt who was a member of 4Ps. She dont know how much did they received because of some family conflict between her and the aunt."
mydata$m_endnote5[214] <- "Beforethe respondent's father-in-law died, [name], got hospitalized. And the bill amounting to 4000 had been paid by his Senior Citizen membership axcording to the respondent. While the respondent had attended 4 times to a DoLE meeting and until now she's waiting for the 10000 worth of grocery items."
mydata$m_endnote5[330] <- "He is 4ps beneficiary but he did not get the pay out for the past months because he said he is far from Brgy [small location]"
mydata$m_endnote5[352] <- "In this section their family recieved benefits from 4P's, SLP she used to buy 2 piglets and groceries or relief goods from Local Government Unit of [small location], from Brgy. [small location] and  UNICEF."
mydata$m_endnote5[1035] <- "Street vendor [language]"
mydata$m_endnote5[1067] <- "They received a grocery last Decmber 2016 from the [small location] local government."
mydata$m_endnote5[1075] <- "[name] receive educ asst at [small location] municipality"
mydata$m_endnote5[1124] <- "[name] from 4Ps, household also received a 4pcs. Of plywood from [small location] local gov't. But respondent does not know its amount."
mydata$m_endnote5[1220] <- "Household received 10000(in kind) from DOLE, 9800 from 4Ps and another 15000 from [small location] government as educational assistance for [name] and [name], and another 5000 from [small location] brgy. Government. In total, they received a 39800 of benefits for the last 12 months."
mydata$m_endnote5[1382] <- "[name] from 4Ps, [name] also receiving 5000 as an educational assistance for her study."
mydata$m_endnote5[1468] <- "Up [small location] have more help in the household than dept of agriculture."
mydata$m_endnote5[1477] <- "[small location]"
mydata$m_endnote5[1479] <- "DOLE conducted seminar on how  to manage business which held at the municipal of [small location]"
mydata$m_endnote5[1514] <- "DOLE conducted seminars on how to manage a sari sari store held at Municpality of [small location].  They claimed lum sum in SSS and the monthly pension will start on 2018, monthly pension is 3,337"
mydata$m_endnote5[1727] <- "The respondents of barangay [small location] received a motorboat amounted to 35,000 from DOLE.the motorboat leader has a policy for the members,.. One person for one week."
mydata$m_endnote5[1764] <- "[language]"
mydata$m_endnote5[2239] <- "4Ps Scholarship [name]"

GPS data: Displace

# !!!No GPS data

Save processed data in Stata and SPSS format

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)