rm(list=ls(all=t))

Setup filenames

filename <- "Section_11" # !!!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

# !!!No Direct PII 

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

# Focus on variables with a "Lowest Freq" in dictionary of 30 or less. 

# Top code high income to the 99.5 percentile

percentile_99.5 <- floor(quantile(na.exclude(mydata$eh_s11q3)[na.exclude(mydata$eh_s11q3)!=999999], probs = c(0.995)))
mydata <- top_recode (variable="eh_s11q3", break_point=percentile_99.5, missing=999999)
## [1] "Frequency table before encoding"
## eh_s11q3. Q795: What is the total amount of the loan? If your household has had multiple l
##   -998      0   2000   3000   5000   6000   6500   7000   8000   9000  10000  11000  12000  14000  15000  17000 
##      2      1      3      1      6      3      1      2      5      1      4      1      3      1     11      1 
##  19000  20000  25000  30000  38000  40000  45000  50000  60000  70000  80000  85000  90000  1e+05 110000 140000 
##      1      5      2      3      1      1      2      4      1      1      2      1      2      2      1      1 
## 150000  3e+05 350000   <NA> 
##      1      1      1   2209

## [1] "Frequency table after encoding"
## eh_s11q3. Q795: What is the total amount of the loan? If your household has had multiple l
##           -998              0           2000           3000           5000           6000           6500 
##              2              1              3              1              6              3              1 
##           7000           8000           9000          10000          11000          12000          14000 
##              2              5              1              4              1              3              1 
##          15000          17000          19000          20000          25000          30000          38000 
##             11              1              1              5              2              3              1 
##          40000          45000          50000          60000          70000          80000          85000 
##              1              2              4              1              1              2              1 
##          90000          1e+05         110000         140000         150000          3e+05 330500 or more 
##              2              2              1              1              1              1              1 
##           <NA> 
##           2209

percentile_99.5 <- floor(quantile(na.exclude(mydata$eh_s11q4)[na.exclude(mydata$eh_s11q4)!=999999], probs = c(0.995)))
mydata <- top_recode (variable="eh_s11q4", break_point=percentile_99.5, missing=999999)
## [1] "Frequency table before encoding"
## eh_s11q4. Q796: In the past 12 months, how much did your household pay in interest on thes
##   -998      0      1      8     15     25    200    207    300    400    500    520    643    800    850    900 
##     10      4      1      1      1      1      4      1      1      1      2      1      1      2      1      1 
##   1000   1080   1200   1500   1614   1900   1950   2000   2625   3000   3600   3840   4000   4250   4400   4800 
##      2      1      3      2      1      1      1      3      1      4      1      1      1      1      1      1 
##   5000   5200   6000   7500   9000  10000  11000  12000  13000  13500  15000  16000  21000  40000  68000 120000 
##      1      1      2      1      1      3      2      2      1      1      1      1      1      1      1      1 
##   <NA> 
##   2209

## [1] "Frequency table after encoding"
## eh_s11q4. Q796: In the past 12 months, how much did your household pay in interest on thes
##          -998             0             1             8            15            25           200           207 
##            10             4             1             1             1             1             4             1 
##           300           400           500           520           643           800           850           900 
##             1             1             2             1             1             2             1             1 
##          1000          1080          1200          1500          1614          1900          1950          2000 
##             2             1             3             2             1             1             1             3 
##          2625          3000          3600          3840          4000          4250          4400          4800 
##             1             4             1             1             1             1             1             1 
##          5000          5200          6000          7500          9000         10000         11000         12000 
##             1             1             2             1             1             3             2             2 
##         13000         13500         15000         16000         21000         40000         68000 99719 or more 
##             1             1             1             1             1             1             1             1 
##          <NA> 
##          2209

percentile_99.5 <- floor(quantile(na.exclude(mydata$eh_s11q6)[na.exclude(mydata$eh_s11q6)!=999999], probs = c(0.995)))
mydata <- top_recode (variable="eh_s11q6", break_point=percentile_99.5, missing=999999)
## [1] "Frequency table before encoding"
## eh_s11q6. Q798: What is the total amount of the loan? If your household has had multiple l
##   -998      0     20    500    616   1000   1500   1600   1700   1935   2000   2060   2200   2500   2600   3000 
##      4      4      1      3      1      4      2      1      1      1     20      1      1      1      1     38 
##   4000   4200   4500   5000   5250   6000   6188   6240   6480   7000   8000   9000   9500  10000  11000  12000 
##     17      1      2    120      1     61      1      1      1     25     34     16      1    135      8     25 
##  13000  13320  14000  14592  15000  16000  17000  18000  19000  19260  20000  21000  22000  23000  23460  24000 
##     16      1     12      1     45     10     10     11      5      1     32      2      4      6      1      3 
##  24900  25000  27000  28000  29000  30000  33000  35000  36000  37000  38000  40000  42000  45000  46000  50000 
##      1     15      4      4      1     20      2      6      1      2      1      3      3      2      1     10 
##  52000  55000  60000  64000  65000  70000  80000  1e+05 115000 130300  2e+05 230000  5e+05   <NA> 
##      1      1      4      1      1      1      4      2      1      1      1      1      1   1499

## [1] "Frequency table after encoding"
## eh_s11q6. Q798: What is the total amount of the loan? If your household has had multiple l
##           -998              0             20            500            616           1000           1500 
##              4              4              1              3              1              4              2 
##           1600           1700           1935           2000           2060           2200           2500 
##              1              1              1             20              1              1              1 
##           2600           3000           4000           4200           4500           5000           5250 
##              1             38             17              1              2            120              1 
##           6000           6188           6240           6480           7000           8000           9000 
##             61              1              1              1             25             34             16 
##           9500          10000          11000          12000          13000          13320          14000 
##              1            135              8             25             16              1             12 
##          14592          15000          16000          17000          18000          19000          19260 
##              1             45             10             10             11              5              1 
##          20000          21000          22000          23000          23460          24000          24900 
##             32              2              4              6              1              3              1 
##          25000          27000          28000          29000          30000          33000          35000 
##             15              4              4              1             20              2              6 
##          36000          37000          38000          40000          42000          45000          46000 
##              1              2              1              3              3              2              1 
##          50000          52000          55000          60000          64000          65000          70000 
##             10              1              1              4              1              1              1 
##          80000          1e+05         115000 115917 or more           <NA> 
##              4              2              1              4           1499

percentile_99.5 <- floor(quantile(na.exclude(mydata$eh_s11q7)[na.exclude(mydata$eh_s11q7)!=999999], probs = c(0.995)))
mydata <- top_recode (variable="eh_s11q7", break_point=percentile_99.5, missing=999999)
## [1] "Frequency table before encoding"
## eh_s11q7. Q799: In the past 12 months, how much did your household pay in interest on thes
##  -999  -998     0     1     3    12    24    28    30    40    50    54    55    60    68    70    72    75    80 
##     2    66    41     1     3     2     1     1     2     1     3     1     1     2     1     1     1     1     1 
##    90    96   100   110   120   125   140   150   175   180   200   220   235   240   249   250   270   280   300 
##     2     1     5     1     2     1     1     2     1     2    12     1     1     1     1     8     2     1     7 
##   304   305   315   334   340   350   380   390   400   410   428   438   450   470   485   500   520   530   540 
##     1     2     1     1     1     1     1     1     7     1     1     1     4     2     1    17     2     1     1 
##   550   552   560   588   600   616   620   640   653   690   695   696   700   727   740   750   752   767   800 
##     2     1     2     1    17     1     1     2     1     1     1     1     7     1     1     7     1     1    17 
##   816   834   840   850   856   870   882   900   910   915   980  1000  1047  1049  1050  1080  1095  1100  1125 
##     1     1     2     2     1     1     1    20     2     1     1    49     1     1     1     2     1     1     1 
##  1130  1155  1175  1176  1180  1190  1200  1220  1225  1240  1245  1250  1280  1300  1320  1350  1360  1400  1440 
##     2     1     1     1     1     1    26     1     1     1     1     2     2     1     1     1     2     5     1 
##  1480  1500  1544  1600  1610  1650  1668  1672  1680  1700  1720  1800  1850  1890  1920  1940  1950  2000  2040 
##     1    24     1     9     1     2     1     1     1     1     1     7     1     1     1     2     1    42     1 
##  2100  2130  2160  2190  2200  2250  2300  2320  2400  2440  2450  2470  2480  2500  2592  2600  2625  2650  2660 
##     3     1     1     1     3     1     1     1    12     1     1     1     4     6     1     2     1     1     1 
##  2680  2700  2720  2736  2800  2850  2870  2880  2900  2930  3000  3200  3232  3250  3300  3400  3440  3460  3500 
##     1     2     2     1     6     1     1     1     2     1    34     2     1     1     1     1     3     1     6 
##  3520  3600  3675  3700  3750  3800  3827  3850  3920  4000  4100  4160  4200  4250  4400  4440  4500  4600  4650 
##     1     8     2     1     4     2     1     1     1    11     1     1     1     1     1     1     4     1     1 
##  4784  4800  4960  5000  5108  5132  5200  5250  5270  5300  5600  5640  5840  6000  6145  6250  6300  6321  6480 
##     1     4     1     8     1     1     2     1     1     1     1     1     1     7     1     1     1     1     1 
##  6500  6600  6800  6900  7000  7200  7344  7600  7680  8000  8140  8460  8500  8550  9000  9200  9600 10000 11000 
##     1     1     1     1     1     2     1     1     1     2     1     1     1     1     3     1     2     2     2 
## 11270 11550 12000 13000 14400 14714 14800 14980 15800 17060 17800 18300 18468 19200 20368 20904 22000 22920 23400 
##     1     1     6     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1 
## 25000 28000 30000 30600 40000 55200 62000 73930 75760  <NA> 
##     1     1     1     1     2     1     1     1     1  1499

## [1] "Frequency table after encoding"
## eh_s11q7. Q799: In the past 12 months, how much did your household pay in interest on thes
##          -999          -998             0             1             3            12            24            28 
##             2            66            41             1             3             2             1             1 
##            30            40            50            54            55            60            68            70 
##             2             1             3             1             1             2             1             1 
##            72            75            80            90            96           100           110           120 
##             1             1             1             2             1             5             1             2 
##           125           140           150           175           180           200           220           235 
##             1             1             2             1             2            12             1             1 
##           240           249           250           270           280           300           304           305 
##             1             1             8             2             1             7             1             2 
##           315           334           340           350           380           390           400           410 
##             1             1             1             1             1             1             7             1 
##           428           438           450           470           485           500           520           530 
##             1             1             4             2             1            17             2             1 
##           540           550           552           560           588           600           616           620 
##             1             2             1             2             1            17             1             1 
##           640           653           690           695           696           700           727           740 
##             2             1             1             1             1             7             1             1 
##           750           752           767           800           816           834           840           850 
##             7             1             1            17             1             1             2             2 
##           856           870           882           900           910           915           980          1000 
##             1             1             1            20             2             1             1            49 
##          1047          1049          1050          1080          1095          1100          1125          1130 
##             1             1             1             2             1             1             1             2 
##          1155          1175          1176          1180          1190          1200          1220          1225 
##             1             1             1             1             1            26             1             1 
##          1240          1245          1250          1280          1300          1320          1350          1360 
##             1             1             2             2             1             1             1             2 
##          1400          1440          1480          1500          1544          1600          1610          1650 
##             5             1             1            24             1             9             1             2 
##          1668          1672          1680          1700          1720          1800          1850          1890 
##             1             1             1             1             1             7             1             1 
##          1920          1940          1950          2000          2040          2100          2130          2160 
##             1             2             1            42             1             3             1             1 
##          2190          2200          2250          2300          2320          2400          2440          2450 
##             1             3             1             1             1            12             1             1 
##          2470          2480          2500          2592          2600          2625          2650          2660 
##             1             4             6             1             2             1             1             1 
##          2680          2700          2720          2736          2800          2850          2870          2880 
##             1             2             2             1             6             1             1             1 
##          2900          2930          3000          3200          3232          3250          3300          3400 
##             2             1            34             2             1             1             1             1 
##          3440          3460          3500          3520          3600          3675          3700          3750 
##             3             1             6             1             8             2             1             4 
##          3800          3827          3850          3920          4000          4100          4160          4200 
##             2             1             1             1            11             1             1             1 
##          4250          4400          4440          4500          4600          4650          4784          4800 
##             1             1             1             4             1             1             1             4 
##          4960          5000          5108          5132          5200          5250          5270          5300 
##             1             8             1             1             2             1             1             1 
##          5600          5640          5840          6000          6145          6250          6300          6321 
##             1             1             1             7             1             1             1             1 
##          6480          6500          6600          6800          6900          7000          7200          7344 
##             1             1             1             1             1             1             2             1 
##          7600          7680          8000          8140          8460          8500          8550          9000 
##             1             1             2             1             1             1             1             3 
##          9200          9600         10000         11000         11270         11550         12000         13000 
##             1             2             2             2             1             1             6             1 
##         14400         14714         14800         14980         15800         17060         17800         18300 
##             1             1             1             1             1             1             1             1 
##         18468         19200         20368         20904         22000         22920         23400         25000 
##             1             1             1             1             1             1             1             1 
##         28000         30000         30600         40000 40911 or more          <NA> 
##             1             1             1             2             4          1499

percentile_99.5 <- floor(quantile(na.exclude(mydata$eh_s11q9)[na.exclude(mydata$eh_s11q9)!=999999], probs = c(0.995)))
mydata <- top_recode (variable="eh_s11q9", break_point=percentile_99.5, missing=999999)
## [1] "Frequency table before encoding"
## eh_s11q9. Q801: What is the total amount of the loan? If your household has had multiple l
##   -999   -998      0     40    100    120    144    150    200    250    300    330    350    355    399    400 
##      1      2      2      1     20      1      1      2     21      2     15      1      3      1      1      7 
##    500    560    600    650    700    800    850    900   1000   1100   1150   1200   1300   1500   1600   1700 
##     55      2      6      1      4      3      1      3    107      2      1      6      3     27      1      3 
##   1800   1805   2000   2200   2220   2400   2450   2500   2600   2700   2780   2800   3000   3200   3250   3500 
##      1      1     77      1      1      2      1     11      1      2      1      1     60      1      1      4 
##   3800   4000   4200   4300   4400   4500   5000   5200   5500   6000   6295   6360   6500   6800   7000   7500 
##      2     20      1      1      1      2     83      1      2     15      1      1      1      1     23      1 
##   8000   8500   9000  10000  11000  12000  12800  13000  14400  15000  16000  16500  17000  18000  18200  19000 
##      9      1      4     50      3      5      2      4      1     14      1      1      4      2      1      1 
##  20000  24000  25000  28500  30000  30900  35000  36000  37060  40000  42000  45000  50000  60000  70000  74000 
##     23      1      4      1     13      1      4      1      1      7      1      2      5      4      1      1 
##  80000  1e+05 105000 150000 315000  8e+05   <NA> 
##      1      6      1      1      1      1   1476

## [1] "Frequency table after encoding"
## eh_s11q9. Q801: What is the total amount of the loan? If your household has had multiple l
##          -999          -998             0            40           100           120           144           150 
##             1             2             2             1            20             1             1             2 
##           200           250           300           330           350           355           399           400 
##            21             2            15             1             3             1             1             7 
##           500           560           600           650           700           800           850           900 
##            55             2             6             1             4             3             1             3 
##          1000          1100          1150          1200          1300          1500          1600          1700 
##           107             2             1             6             3            27             1             3 
##          1800          1805          2000          2200          2220          2400          2450          2500 
##             1             1            77             1             1             2             1            11 
##          2600          2700          2780          2800          3000          3200          3250          3500 
##             1             2             1             1            60             1             1             4 
##          3800          4000          4200          4300          4400          4500          5000          5200 
##             2            20             1             1             1             2            83             1 
##          5500          6000          6295          6360          6500          6800          7000          7500 
##             2            15             1             1             1             1            23             1 
##          8000          8500          9000         10000         11000         12000         12800         13000 
##             9             1             4            50             3             5             2             4 
##         14400         15000         16000         16500         17000         18000         18200         19000 
##             1            14             1             1             4             2             1             1 
##         20000         24000         25000         28500         30000         30900         35000         36000 
##            23             1             4             1            13             1             4             1 
##         37060         40000         42000         45000         50000         60000         70000         74000 
##             1             7             1             2             5             4             1             1 
##         80000 1e+05 or more          <NA> 
##             1            10          1476

percentile_99.5 <- floor(quantile(na.exclude(mydata$eh_s11q10)[na.exclude(mydata$eh_s11q10)!=999999], probs = c(0.995)))
mydata <- top_recode (variable="eh_s11q10", break_point=percentile_99.5, missing=999999)
## [1] "Frequency table before encoding"
## eh_s11q10. Q802: In the past 12 months, how much did your household pay in interest on thes
##  -999  -998     0     1    50    70   100   120   125   150   200   250   300   320   340   350   400   450   480 
##     7     5   533     2     6     1    17     2     1    10    23     3    17     1     1     1    13     3     1 
##   500   550   600   700   750   760   800  1000  1050  1100  1200  1250  1300  1400  1500  1750  1800  2000  2200 
##     8     1     9     8     1     1     3    28     1     2     6     2     1     4    12     1     1    17     1 
##  2400  2500  2800  2900  3000  3250  3600  4000  4500  4800  5000  5250  5600  6000  7000  7500  8500  9000 10000 
##     3     2     2     1     6     1     2     4     1     1     7     1     1     5     3     2     1     1     2 
## 12000 15000 16800 18000 20000 30900 60000  <NA> 
##     1     2     1     2     4     1     1  1476

## [1] "Frequency table after encoding"
## eh_s11q10. Q802: In the past 12 months, how much did your household pay in interest on thes
##          -999          -998             0             1            50            70           100           120 
##             7             5           533             2             6             1            17             2 
##           125           150           200           250           300           320           340           350 
##             1            10            23             3            17             1             1             1 
##           400           450           480           500           550           600           700           750 
##            13             3             1             8             1             9             8             1 
##           760           800          1000          1050          1100          1200          1250          1300 
##             1             3            28             1             2             6             2             1 
##          1400          1500          1750          1800          2000          2200          2400          2500 
##             4            12             1             1            17             1             3             2 
##          2800          2900          3000          3250          3600          4000          4500          4800 
##             2             1             6             1             2             4             1             1 
##          5000          5250          5600          6000          7000          7500          8500          9000 
##             7             1             1             5             3             2             1             1 
##         10000         12000         15000         16800         18000 20000 or more          <NA> 
##             2             1             2             1             2             6          1476

percentile_99.5 <- floor(quantile(na.exclude(mydata$eh_s11q12)[na.exclude(mydata$eh_s11q12)!=999999], probs = c(0.995)))
mydata <- top_recode (variable="eh_s11q12", break_point=percentile_99.5, missing=999999)
## [1] "Frequency table before encoding"
## eh_s11q12. Q804: What is the total amount of the loan? If your household has had multiple l
##   -998    350    450    600    700    840    950   1000   1180   1200   1350   1400   1500   2200   2250   2400 
##      1      1      1      1      1      1      1      1      1      1      1      1      1      1      1      1 
##   2500   2700   3000   3500   4000   5000   5500   6000   7000   8000   9250  10000  12000  13000  14000  16000 
##      2      1      2      1      1      6      1      2      1      4      1     10      1      1      1      1 
##  17000  18000  18500  18760  20000  21900  22000  23000  25000  26800  29000  30000  32000  35000  49000  50000 
##      1      1      1      1     10      1      1      1      1      1      1      2      1      1      1      1 
##  51000  60000  69000  70000  1e+05 105000 146000   <NA> 
##      1      1      1      1      2      1      1   2202

## [1] "Frequency table after encoding"
## eh_s11q12. Q804: What is the total amount of the loan? If your household has had multiple l
##           -998            350            450            600            700            840            950 
##              1              1              1              1              1              1              1 
##           1000           1180           1200           1350           1400           1500           2200 
##              1              1              1              1              1              1              1 
##           2250           2400           2500           2700           3000           3500           4000 
##              1              1              2              1              2              1              1 
##           5000           5500           6000           7000           8000           9250          10000 
##              6              1              2              1              4              1             10 
##          12000          13000          14000          16000          17000          18000          18500 
##              1              1              1              1              1              1              1 
##          18760          20000          21900          22000          23000          25000          26800 
##              1             10              1              1              1              1              1 
##          29000          30000          32000          35000          49000          50000          51000 
##              1              2              1              1              1              1              1 
##          60000          69000          70000          1e+05         105000 128575 or more           <NA> 
##              1              1              1              2              1              1           2202

percentile_99.5 <- floor(quantile(na.exclude(mydata$eh_s11q13)[na.exclude(mydata$eh_s11q13)!=999999], probs = c(0.995)))
mydata <- top_recode (variable="eh_s11q13", break_point=percentile_99.5, missing=999999)
## [1] "Frequency table before encoding"
## eh_s11q13. Q805: In the past 12 months, how much did your household pay in interest on thes
##   -998      0     50     68    100    150    200    250    300    400    450    500    600    700    840   1000 
##      6     32      1      1      1      1      1      1      1      1      1      4      2      3      1      3 
##   1100   1300   1500   1600   1800   2000   2400   2500   3000   3600   4000   5000   6000   6400  11256  12000 
##      1      1      1      3      1      3      1      1      1      1      2      2      2      1      1      1 
##  15000  18000 146000   <NA> 
##      1      1      1   2202

## [1] "Frequency table after encoding"
## eh_s11q13. Q805: In the past 12 months, how much did your household pay in interest on thes
##          -998             0            50            68           100           150           200           250 
##             6            32             1             1             1             1             1             1 
##           300           400           450           500           600           700           840          1000 
##             1             1             1             4             2             3             1             3 
##          1100          1300          1500          1600          1800          2000          2400          2500 
##             1             1             1             3             1             3             1             1 
##          3000          3600          4000          5000          6000          6400         11256         12000 
##             1             1             2             2             2             1             1             1 
##         15000         18000 91600 or more          <NA> 
##             1             1             1          2202

percentile_99.5 <- floor(quantile(na.exclude(mydata$eh_s11q15)[na.exclude(mydata$eh_s11q15)!=999999], probs = c(0.995)))
mydata <- top_recode (variable="eh_s11q15", break_point=percentile_99.5, missing=999999)
## [1] "Frequency table before encoding"
## eh_s11q15. Q807: What is the total amount of the loan? If your household has had multiple l
##   -998     80    200    300    350    500    600    650    700    750   1000   1200   1450   1500   1800   2000 
##      1      1      1      1      1     10      3      1      1      1     20      1      1      6      1     14 
##   2500   3000   3500   3600   4000   4100   4200   4500   5000   5200   5500   5600   6000   7000   8000   8100 
##      6     22      2      1      4      1      1      1     19      1      1      1      7      2      1      1 
##   8600   9000  10000  15000  16000  18000  20000  25000  28000  30000  35000  40000  41000  50000  54000 140000 
##      1      2     14      8      1      3      5      3      1      4      1      2      1      1      1      1 
##   <NA> 
##   2104

## [1] "Frequency table after encoding"
## eh_s11q15. Q807: What is the total amount of the loan? If your household has had multiple l
##          -998            80           200           300           350           500           600           650 
##             1             1             1             1             1            10             3             1 
##           700           750          1000          1200          1450          1500          1800          2000 
##             1             1            20             1             1             6             1            14 
##          2500          3000          3500          3600          4000          4100          4200          4500 
##             6            22             2             1             4             1             1             1 
##          5000          5200          5500          5600          6000          7000          8000          8100 
##            19             1             1             1             7             2             1             1 
##          8600          9000         10000         15000         16000         18000         20000         25000 
##             1             2            14             8             1             3             5             3 
##         28000         30000         35000         40000         41000         50000         54000 61310 or more 
##             1             4             1             2             1             1             1             1 
##          <NA> 
##          2104

percentile_99.5 <- floor(quantile(na.exclude(mydata$eh_s11q16)[na.exclude(mydata$eh_s11q16)!=999999], probs = c(0.995)))
mydata <- top_recode (variable="eh_s11q16", break_point=percentile_99.5, missing=999999)
## [1] "Frequency table before encoding"
## eh_s11q16. Q808: In the past 12 months, how much did your household pay in interest on thes
##  -998     0    50    60   100   150   200   250   300   350   356   400   450   500   600   650   720   750   800 
##    10    16     1     1     9     2    21     2     4     1     1    12     1     5    13     1     1     2     1 
##   900  1000  1200  1500  1600  1700  1800  2000  2400  2500  2800  2888  3000  3200  3400  3600  4000  4200  5000 
##     3    14     4     4     1     1     4    10     1     3     1     1     7     1     1     1     4     1     5 
##  5500  5600  6000  7000  7500  7800  8000  8400 18000 28200  <NA> 
##     1     1     2     1     1     1     2     2     1     1  2104

## [1] "Frequency table after encoding"
## eh_s11q16. Q808: In the past 12 months, how much did your household pay in interest on thes
##          -998             0            50            60           100           150           200           250 
##            10            16             1             1             9             2            21             2 
##           300           350           356           400           450           500           600           650 
##             4             1             1            12             1             5            13             1 
##           720           750           800           900          1000          1200          1500          1600 
##             1             2             1             3            14             4             4             1 
##          1700          1800          2000          2400          2500          2800          2888          3000 
##             1             4            10             1             3             1             1             7 
##          3200          3400          3600          4000          4200          5000          5500          5600 
##             1             1             1             4             1             5             1             1 
##          6000          7000          7500          7800          8000          8400         18000 18867 or more 
##             2             1             1             1             2             2             1             1 
##          <NA> 
##          2104

percentile_99.5 <- floor(quantile(na.exclude(mydata$eh_s11q18)[na.exclude(mydata$eh_s11q18)!=999999], probs = c(0.995)))
mydata <- top_recode (variable="eh_s11q18", break_point=percentile_99.5, missing=999999)
## [1] "Frequency table before encoding"
## eh_s11q18. Q810: What is the total amount of the loan? If your household has had multiple l
##  -999  -998     0    16    20    22    25    30    34    35    36    38    40    45    50    52    57    60    70 
##     1     5     4     1     1     1     1     2     1     2     1     1     2     5    11     1     1     5     6 
##    72    75    76    80    84    85    87    90    95    96    97   100   110   117   120   125   130   132   135 
##     1     1     1     8     1     2     1     3     1     1     2    64     3     1     5     1     2     1     1 
##   139   140   143   145   147   150   155   157   163   165   175   182   184   195   200   205   209   240   250 
##     1     2     1     1     1    25     1     1     2     1     1     1     1     1    74     1     1     1    10 
##   260   275   280   300   320   340   350   380   400   450   460   496   500   520   555   560   570   580   600 
##     2     1     1    69     1     1     8     1    20     3     1     1    81     1     1     1     1     2    17 
##   613   650   700   740   752   766   784   800   870   900   950   980  1000  1020  1100  1150  1200  1250  1300 
##     1     2    15     1     1     1     1    17     1     4     1     1    72     1     4     1    16     2     5 
##  1400  1500  1600  1700  1780  1800  2000  2200  2300  2400  2500  2600  2622  2700  2800  2880  2900  3000  3500 
##     4    28     3     2     1     4    29     3     1    10     7     1     1     2     2     1     2    24     1 
##  3600  3800  4000  4500  4800  5000  5500  6000  6500  7000  8000  8640  9000  9600 10000 10500 12000 13000 14400 
##     3     1     7     1     4    17     1     7     1     3     4     2     1     5     4     1     5     1     3 
## 15000 16000 19200 20000 20400 24000 25200 33600 36000 38400 54000 57600 60000 72000  <NA> 
##     2     1     1     2     1     1     1     2     2     2     1     1     1     3  1431

## [1] "Frequency table after encoding"
## eh_s11q18. Q810: What is the total amount of the loan? If your household has had multiple l
##          -999          -998             0            16            20            22            25            30 
##             1             5             4             1             1             1             1             2 
##            34            35            36            38            40            45            50            52 
##             1             2             1             1             2             5            11             1 
##            57            60            70            72            75            76            80            84 
##             1             5             6             1             1             1             8             1 
##            85            87            90            95            96            97           100           110 
##             2             1             3             1             1             2            64             3 
##           117           120           125           130           132           135           139           140 
##             1             5             1             2             1             1             1             2 
##           143           145           147           150           155           157           163           165 
##             1             1             1            25             1             1             2             1 
##           175           182           184           195           200           205           209           240 
##             1             1             1             1            74             1             1             1 
##           250           260           275           280           300           320           340           350 
##            10             2             1             1            69             1             1             8 
##           380           400           450           460           496           500           520           555 
##             1            20             3             1             1            81             1             1 
##           560           570           580           600           613           650           700           740 
##             1             1             2            17             1             2            15             1 
##           752           766           784           800           870           900           950           980 
##             1             1             1            17             1             4             1             1 
##          1000          1020          1100          1150          1200          1250          1300          1400 
##            72             1             4             1            16             2             5             4 
##          1500          1600          1700          1780          1800          2000          2200          2300 
##            28             3             2             1             4            29             3             1 
##          2400          2500          2600          2622          2700          2800          2880          2900 
##            10             7             1             1             2             2             1             2 
##          3000          3500          3600          3800          4000          4500          4800          5000 
##            24             1             3             1             7             1             4            17 
##          5500          6000          6500          7000          8000          8640          9000          9600 
##             1             7             1             3             4             2             1             5 
##         10000         10500         12000         13000         14400         15000         16000         19200 
##             4             1             5             1             3             2             1             1 
##         20000         20400         24000         25200         33600         36000         38400         54000 
##             2             1             1             1             2             2             2             1 
## 56592 or more          <NA> 
##             5          1431

percentile_99.5 <- floor(quantile(na.exclude(mydata$eh_s11q19)[na.exclude(mydata$eh_s11q19)!=999999], probs = c(0.995)))
mydata <- top_recode (variable="eh_s11q19", break_point=percentile_99.5, missing=999999)
## [1] "Frequency table before encoding"
## eh_s11q19. Q811: In the past 12 months, how much did your household pay in interest on thes
##  -999  -998     0     6    40    50   100   150   200   240   300   500   600   766  1000  1500  1782  2300  2400 
##     2     2   806     1     1     2     5     3     3     1     1     1     1     1     3     1     1     2     4 
##  2880  3500  4000  5500  6000  8640  9600 12000 14400 25200 37700 38170 72000  <NA> 
##     1     1     1     1     2     2     2     1     1     1     1     1     1  1431

## [1] "Frequency table after encoding"
## eh_s11q19. Q811: In the past 12 months, how much did your household pay in interest on thes
##          -999          -998             0             6            40            50           100           150 
##             2             2           806             1             1             2             5             3 
##           200           240           300           500           600           766          1000          1500 
##             3             1             1             1             1             1             3             1 
##          1782          2300          2400          2880          3500          4000          5500          6000 
##             1             2             4             1             1             1             1             2 
##          8640          9600         12000 13728 or more          <NA> 
##             2             2             1             5          1431

percentile_99.5 <- floor(quantile(na.exclude(mydata$eh_s11q21)[na.exclude(mydata$eh_s11q21)!=999999], probs = c(0.995)))
mydata <- top_recode (variable="eh_s11q21", break_point=percentile_99.5, missing=999999)
## [1] "Frequency table before encoding"
## eh_s11q21. Q813: What is the total amount of the loan? If your household has had multiple l
##    400    500    600    650    700   1000   1200   1300   2000   2200   2300   2400   2500   2800   3000   3500 
##      1      1      1      1      1      2      1      2      6      1      1      1      1      1      3      2 
##   3700   3800   4000   4500   4700   5000   6000   7000   7900   8000   9000  10000  12000  12100  13000  14000 
##      1      1      2      1      1      7      3      1      1      1      2      6      3      1      1      1 
##  19800  20000  21000  25200  30000  31050  35000  40000  50000  56000  59760  60000  72001  91800 105000 130000 
##      1      1      2      2      2      1      1      1      5      1      1      1      1      1      1      3 
## 133200  3e+05   <NA> 
##      1      1   2202

## [1] "Frequency table after encoding"
## eh_s11q21. Q813: What is the total amount of the loan? If your household has had multiple l
##            400            500            600            650            700           1000           1200 
##              1              1              1              1              1              2              1 
##           1300           2000           2200           2300           2400           2500           2800 
##              2              6              1              1              1              1              1 
##           3000           3500           3700           3800           4000           4500           4700 
##              3              2              1              1              2              1              1 
##           5000           6000           7000           7900           8000           9000          10000 
##              7              3              1              1              1              2              6 
##          12000          12100          13000          14000          19800          20000          21000 
##              3              1              1              1              1              1              2 
##          25200          30000          31050          35000          40000          50000          56000 
##              2              2              1              1              1              5              1 
##          59760          60000          72001          91800         105000         130000         133200 
##              1              1              1              1              1              3              1 
## 229110 or more           <NA> 
##              1           2202

percentile_99.5 <- floor(quantile(na.exclude(mydata$eh_s11q22)[na.exclude(mydata$eh_s11q22)!=999999], probs = c(0.995)))
mydata <- top_recode (variable="eh_s11q22", break_point=percentile_99.5, missing=999999)
## [1] "Frequency table before encoding"
## eh_s11q22. Q814: In the past 12 months, how much did your household pay in interest on thes
##  -999  -998     0    36    80   100   150   188   200   210   219   285   300   350   375   400   500   600   740 
##     1     4    38     1     1     1     1     1     1     1     1     1     1     1     1     3     2     1     1 
##   900  1000  1020  1200  1500  1835  2000  3000  3500  3800  3900  4000  4200  4800  5000  6000  9120 12100 20000 
##     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     2 
## 21800 35000 37200 69000  <NA> 
##     1     1     1     1  2202

## [1] "Frequency table after encoding"
## eh_s11q22. Q814: In the past 12 months, how much did your household pay in interest on thes
##          -999          -998             0            36            80           100           150           188 
##             1             4            38             1             1             1             1             1 
##           200           210           219           285           300           350           375           400 
##             1             1             1             1             1             1             1             3 
##           500           600           740           900          1000          1020          1200          1500 
##             2             1             1             1             1             1             1             1 
##          1835          2000          3000          3500          3800          3900          4000          4200 
##             1             1             1             1             1             1             1             1 
##          4800          5000          6000          9120         12100         20000         21800         35000 
##             1             1             1             1             1             2             1             1 
##         37200 55485 or more          <NA> 
##             1             1          2202

percentile_99.5 <- floor(quantile(na.exclude(mydata$eh_s11q24)[na.exclude(mydata$eh_s11q24)!=999999], probs = c(0.995)))
mydata <- top_recode (variable="eh_s11q24", break_point=percentile_99.5, missing=999999)
## [1] "Frequency table before encoding"
## eh_s11q24. Q816: How much do you owe these shops for items taken on credit?  Magkano ang ut
##   -998     20     40     45     50     70     77     80     95    100    120    150    180    200    250    270 
##      3      1      1      1      2      1      1      1      1      2      1      3      2      3      1      1 
##    300    320    400    450    500    550    600    700    792    800   1000   1100   1200   1250   1300   1400 
##      6      1      1      2      6      1      6      1      1      1     12      1      4      1      2      2 
##   1500   1700   1800   1875   1900   2000   2400   2500   2800   2890   2900   3000   3125   3200   3214   3400 
##      2      1      3      1      1      8      2      6      3      1      1      6      1      1      1      2 
##   3500   3600   3800   3870   3900   4000   4020   4200   4400   4500   4800   4900   5000   5031   5300   5400 
##      2      1      2      1      2      7      1      1      1      2      1      1      5      1      1      2 
##   5500   5600   5700   6000   6500   7000   8000   9000   9492   9600  10000  12000  12600  12660  12800  13500 
##      1      1      2      2      1      1      2      2      1      1      5      2      1      1      1      1 
##  13800  15840  15872  16000  18744  19000  21000  21200  26400  26544  27600  28000  30000  32000  33000  39060 
##      1      1      1      2      1      1      1      1      1      1      1      1      1      1      1      1 
##  40000  41000  42000  42900  44000  44200  45000  45600  50000  52095  52800  53200  54000  54400  56000  56700 
##      1      1      1      2      1      1      3      2      4      1      1      1      1      1      1      1 
##  57600  60000  62100  64800  66000  66800  67200  68580  72000  74500  74525  75600  76000  79000  79200  80000 
##      1      2      1      1      1      1      1      1      1      1      1      1      1      1      1      2 
##  86800  91000  91200  91400  1e+05 106592 118800 124000  2e+05   <NA> 
##      1      1      1      1      2      1      1      1      1   2051

## [1] "Frequency table after encoding"
## eh_s11q24. Q816: How much do you owe these shops for items taken on credit?  Magkano ang ut
##           -998             20             40             45             50             70             77 
##              3              1              1              1              2              1              1 
##             80             95            100            120            150            180            200 
##              1              1              2              1              3              2              3 
##            250            270            300            320            400            450            500 
##              1              1              6              1              1              2              6 
##            550            600            700            792            800           1000           1100 
##              1              6              1              1              1             12              1 
##           1200           1250           1300           1400           1500           1700           1800 
##              4              1              2              2              2              1              3 
##           1875           1900           2000           2400           2500           2800           2890 
##              1              1              8              2              6              3              1 
##           2900           3000           3125           3200           3214           3400           3500 
##              1              6              1              1              1              2              2 
##           3600           3800           3870           3900           4000           4020           4200 
##              1              2              1              2              7              1              1 
##           4400           4500           4800           4900           5000           5031           5300 
##              1              2              1              1              5              1              1 
##           5400           5500           5600           5700           6000           6500           7000 
##              2              1              1              2              2              1              1 
##           8000           9000           9492           9600          10000          12000          12600 
##              2              2              1              1              5              2              1 
##          12660          12800          13500          13800          15840          15872          16000 
##              1              1              1              1              1              1              2 
##          18744          19000          21000          21200          26400          26544          27600 
##              1              1              1              1              1              1              1 
##          28000          30000          32000          33000          39060          40000          41000 
##              1              1              1              1              1              1              1 
##          42000          42900          44000          44200          45000          45600          50000 
##              1              2              1              1              3              2              4 
##          52095          52800          53200          54000          54400          56000          56700 
##              1              1              1              1              1              1              1 
##          57600          60000          62100          64800          66000          66800          67200 
##              1              2              1              1              1              1              1 
##          68580          72000          74500          74525          75600          76000          79000 
##              1              1              1              1              1              1              1 
##          79200          80000          86800          91000          91200          91400          1e+05 
##              1              2              1              1              1              1              2 
##         106592         118800 123063 or more           <NA> 
##              1              1              2           2051

percentile_99.5 <- floor(quantile(na.exclude(mydata$eh_s11q26)[na.exclude(mydata$eh_s11q26)!=999999], probs = c(0.995)))
mydata <- top_recode (variable="eh_s11q26", break_point=percentile_99.5, missing=999999)
## [1] "Frequency table before encoding"
## eh_s11q26. Q819: What is the total amount currently saved in these bank accounts by you and
##  -999  -998     0    32   100   150   300   400   500   600   700   800   900  1000  1200  1300  1400  1500  1700 
##     8    12     7     1     1     1     3     2     9     2     2     1     2    12     1     1     2     6     2 
##  1800  1900  2000  2100  2200  2300  3000  3007  3027  3200  3600  3900  4000  4200  4300  4400  5000  5200  6000 
##     2     1     8     1     1     2    10     1     1     1     1     1     5     1     1     1    11     1     1 
##  7000  8000  9000 10000 11000 12000 13000 13818 15000 18000 19000 20000 22000 23000 25000 30000 40000 50000 60000 
##     1     1     1     8     1     1     2     1     2     2     1     7     1     1     2     4     2     2     1 
## 1e+05  <NA> 
##     1  2120

## [1] "Frequency table after encoding"
## eh_s11q26. Q819: What is the total amount currently saved in these bank accounts by you and
##          -999          -998             0            32           100           150           300           400 
##             8            12             7             1             1             1             3             2 
##           500           600           700           800           900          1000          1200          1300 
##             9             2             2             1             2            12             1             1 
##          1400          1500          1700          1800          1900          2000          2100          2200 
##             2             6             2             2             1             8             1             1 
##          2300          3000          3007          3027          3200          3600          3900          4000 
##             2            10             1             1             1             1             1             5 
##          4200          4300          4400          5000          5200          6000          7000          8000 
##             1             1             1            11             1             1             1             1 
##          9000         10000         11000         12000         13000         13818         15000         18000 
##             1             8             1             1             2             1             2             2 
##         19000         20000         22000         23000         25000         30000         40000         50000 
##             1             7             1             1             2             4             2             2 
##         60000 66599 or more          <NA> 
##             1             1          2120

percentile_99.5 <- floor(quantile(na.exclude(mydata$eh_s11q27)[na.exclude(mydata$eh_s11q27)!=999999], probs = c(0.995)))
mydata <- top_recode (variable="eh_s11q27", break_point=percentile_99.5, missing=999999)
## [1] "Frequency table before encoding"
## eh_s11q27. Q820: In the past 12 months, what is the total amount added to these bank accoun
##   -999   -998      0     15     38    100    120    240    300    400    500    600   1000   1300   1500   1900 
##      4     13     97      1      1      1      1      1      1      1      2      1      4      1      3      1 
##   2000   2200   2400   2500   3000   3300   3360   3500   4000   4800   5000   6000   6560   7200   7300   9600 
##      9      1      1      1      1      1      1      1      1      2      4      2      1      1      1      1 
##  10000  20000 110000 134400   <NA> 
##      3      1      1      1   2120

## [1] "Frequency table after encoding"
## eh_s11q27. Q820: In the past 12 months, what is the total amount added to these bank accoun
##           -999           -998              0             15             38            100            120 
##              4             13             97              1              1              1              1 
##            240            300            400            500            600           1000           1300 
##              1              1              1              2              1              4              1 
##           1500           1900           2000           2200           2400           2500           3000 
##              3              1              9              1              1              1              1 
##           3300           3360           3500           4000           4800           5000           6000 
##              1              1              1              1              2              4              2 
##           6560           7200           7300           9600          10000          20000         110000 
##              1              1              1              1              3              1              1 
## 114025 or more           <NA> 
##              1           2120

percentile_99.5 <- floor(quantile(na.exclude(mydata$eh_s11q28)[na.exclude(mydata$eh_s11q28)!=999999], probs = c(0.995)))
mydata <- top_recode (variable="eh_s11q28", break_point=percentile_99.5, missing=999999)
## [1] "Frequency table before encoding"
## eh_s11q28. Q821: In the past 12 months, what is the total amount withdrawn from these accou
##   -999   -998      0    200    300    390    500    600    700    800   1000   1300   1500   1800   2000   3000 
##      3     13    100      1      1      1      4      3      2      2      3      1      1      2      3      6 
##   4000   5000   5500   6000   7000   7600  10000  16500  20000  25000  37000  44000 110000 126000 132400   <NA> 
##      2      4      1      1      2      1      3      1      1      1      1      1      1      1      1   2120

## [1] "Frequency table after encoding"
## eh_s11q28. Q821: In the past 12 months, what is the total amount withdrawn from these accou
##           -999           -998              0            200            300            390            500 
##              3             13            100              1              1              1              4 
##            600            700            800           1000           1300           1500           1800 
##              3              2              2              3              1              1              2 
##           2000           3000           4000           5000           5500           6000           7000 
##              3              6              2              4              1              1              2 
##           7600          10000          16500          20000          25000          37000          44000 
##              1              3              1              1              1              1              1 
##         110000         126000 127055 or more           <NA> 
##              1              1              1           2120

percentile_99.5 <- floor(quantile(na.exclude(mydata$eh_s11q30)[na.exclude(mydata$eh_s11q30)!=999999], probs = c(0.995)))
mydata <- top_recode (variable="eh_s11q30", break_point=percentile_99.5, missing=999999)
## [1] "Frequency table before encoding"
## eh_s11q30. Q823: In the past 12 months, how much income did you earn from interest on these
##  -999  -998     0     4     5     7    10    12    13    14    15    17    18    20    21    24    25    27    30 
##     2    15     2     1     1     1     1     1     1     1     5     1     1     1     1     1     1     1     1 
##    32    38    50    52    66   100   106   120   140   200   288   300   400   500   600   700  1000  1200  2000 
##     1     1     3     1     1     1     1     1     1     2     1     2     1     1     1     1     2     1     1 
##  3000  5000 13200  <NA> 
##     1     1     1  2222

## [1] "Frequency table after encoding"
## eh_s11q30. Q823: In the past 12 months, how much income did you earn from interest on these
##          -999          -998             0             4             5             7            10            12 
##             2            15             2             1             1             1             1             1 
##            13            14            15            17            18            20            21            24 
##             1             1             5             1             1             1             1             1 
##            25            27            30            32            38            50            52            66 
##             1             1             1             1             1             3             1             1 
##           100           106           120           140           200           288           300           400 
##             1             1             1             1             2             1             2             1 
##           500           600           700          1000          1200          2000          3000          5000 
##             1             1             1             2             1             1             1             1 
## 10534 or more          <NA> 
##             1          2222

percentile_99.5 <- floor(quantile(na.exclude(mydata$eh_s11q32)[na.exclude(mydata$eh_s11q32)!=999999], probs = c(0.995)))
mydata <- top_recode (variable="eh_s11q32", break_point=percentile_99.5, missing=999999)
## [1] "Frequency table before encoding"
## eh_s11q32. Q825: What is the total amount currently saved with coops and MFIs (microfinance
##  -999  -998     0    16    20    30    40    50    70    80   100   105   120   150   200   250   300   310   350 
##     1    23     8     1     1     2     1     2     1     1     2     1     2     2     9     1    10     1     3 
##   390   400   410   420   456   480   500   520   575   600   640   650   680   700   720   750   800   813   825 
##     1     5     1     1     1     2    12     1     1    12     1     1     1     7     2     1     3     1     1 
##   850   880   886   900  1000  1001  1005  1070  1100  1200  1220  1240  1250  1293  1300  1400  1410  1440  1450 
##     1     1     1     4    45     1     1     1     2    17     1     1     1     1     6     8     1     1     1 
##  1470  1500  1575  1600  1680  1700  1800  1900  2000  2017  2100  2132  2200  2300  2400  2430  2500  2600  2700 
##     1    22     1     7     1     4    12     1    47     1     2     1     3     2     3     1    13     5     3 
##  2800  2850  2900  3000  3014  3020  3040  3100  3200  3300  3335  3371  3400  3496  3500  3568  3600  3610  3700 
##     7     2     2    49     1     1     1     1     4     2     1     1     2     1     8     1     6     1     1 
##  3789  3800  3831  3870  3900  3910  4000  4200  4300  4310  4312  4330  4399  4500  4560  4570  4600  4700  4800 
##     1     4     1     1     2     1    38     2     1     1     1     1     1     4     1     1     2     2     3 
##  4860  4900  5000  5006  5100  5400  5500  5550  5680  5700  5709  5800  6000  6075  6092  6300  6340  6400  6500 
##     1     1    36     1     1     1     6     1     1     1     1     1    21     1     1     1     1     1     2 
##  6700  6800  7000  7110  7200  7334  7883  8000  8500  8640  8800  9000  9463  9900 10000 10700 11000 11600 12000 
##     1     3    17     1     1     1     1    14     1     1     1     6     1     1    10     1     4     1     5 
## 12400 12740 14000 15000 15900 16000 17000 18000 19000 20000 21000 22000 24000 25000 30000 32500 80000 1e+05  <NA> 
##     1     1     4     5     1     2     1     1     2     4     1     1     1     1     2     1     1     1  1594

## [1] "Frequency table after encoding"
## eh_s11q32. Q825: What is the total amount currently saved with coops and MFIs (microfinance
##          -999          -998             0            16            20            30            40            50 
##             1            23             8             1             1             2             1             2 
##            70            80           100           105           120           150           200           250 
##             1             1             2             1             2             2             9             1 
##           300           310           350           390           400           410           420           456 
##            10             1             3             1             5             1             1             1 
##           480           500           520           575           600           640           650           680 
##             2            12             1             1            12             1             1             1 
##           700           720           750           800           813           825           850           880 
##             7             2             1             3             1             1             1             1 
##           886           900          1000          1001          1005          1070          1100          1200 
##             1             4            45             1             1             1             2            17 
##          1220          1240          1250          1293          1300          1400          1410          1440 
##             1             1             1             1             6             8             1             1 
##          1450          1470          1500          1575          1600          1680          1700          1800 
##             1             1            22             1             7             1             4            12 
##          1900          2000          2017          2100          2132          2200          2300          2400 
##             1            47             1             2             1             3             2             3 
##          2430          2500          2600          2700          2800          2850          2900          3000 
##             1            13             5             3             7             2             2            49 
##          3014          3020          3040          3100          3200          3300          3335          3371 
##             1             1             1             1             4             2             1             1 
##          3400          3496          3500          3568          3600          3610          3700          3789 
##             2             1             8             1             6             1             1             1 
##          3800          3831          3870          3900          3910          4000          4200          4300 
##             4             1             1             2             1            38             2             1 
##          4310          4312          4330          4399          4500          4560          4570          4600 
##             1             1             1             1             4             1             1             2 
##          4700          4800          4860          4900          5000          5006          5100          5400 
##             2             3             1             1            36             1             1             1 
##          5500          5550          5680          5700          5709          5800          6000          6075 
##             6             1             1             1             1             1            21             1 
##          6092          6300          6340          6400          6500          6700          6800          7000 
##             1             1             1             1             2             1             3            17 
##          7110          7200          7334          7883          8000          8500          8640          8800 
##             1             1             1             1            14             1             1             1 
##          9000          9463          9900         10000         10700         11000         11600         12000 
##             6             1             1            10             1             4             1             5 
##         12400         12740         14000         15000         15900         16000         17000         18000 
##             1             1             4             5             1             2             1             1 
##         19000         20000         21000         22000         24000         25000 30000 or more          <NA> 
##             2             4             1             1             1             1             5          1594

percentile_99.5 <- floor(quantile(na.exclude(mydata$eh_s11q33)[na.exclude(mydata$eh_s11q33)!=999999], probs = c(0.995)))
mydata <- top_recode (variable="eh_s11q33", break_point=percentile_99.5, missing=999999)
## [1] "Frequency table before encoding"
## eh_s11q33. Q826: In the past 12 months, what is the total amount added to these accounts by
##  -999  -998     0    12    14    20    30    40    50    68    72    80    85    90   100   120   125   140   150 
##     7    37   393     1     1     1     1     1     9     1     1     3     1     1     4     2     1     2     4 
##   195   200   228   240   250   300   370   400   420   480   500   557   600   640   720   800   880   900  1000 
##     1    11     1     4     5     8     1     5     1     1    14     1     6     1     4     4     1     1    27 
##  1100  1200  1300  1344  1400  1440  1470  1500  1550  1570  1575  1600  1680  1700  1800  2000  2122  2240  2400 
##     1     9     1     1     4     2     1     3     1     1     1     1     2     1     1    10     1     1    23 
##  2460  2600  2650  2700  2800  2850  2880  3000  3360  3500  3600  3800  3840  3900  4000  4200  4320  4462  4600 
##     1     2     1     2     3     1     1     5     4     2     1     1     1     1     4     1     1     1     1 
##  4800  5000  5500  5760  6300  6720  7000  7200  8000  8593  9000  9120  9600 12000 13000 13500 14000 30000 36000 
##     3     6     1     1     1     1     1     1     1     1     1     1     1     2     1     1     1     1     1 
##  <NA> 
##  1594

## [1] "Frequency table after encoding"
## eh_s11q33. Q826: In the past 12 months, what is the total amount added to these accounts by
##          -999          -998             0            12            14            20            30            40 
##             7            37           393             1             1             1             1             1 
##            50            68            72            80            85            90           100           120 
##             9             1             1             3             1             1             4             2 
##           125           140           150           195           200           228           240           250 
##             1             2             4             1            11             1             4             5 
##           300           370           400           420           480           500           557           600 
##             8             1             5             1             1            14             1             6 
##           640           720           800           880           900          1000          1100          1200 
##             1             4             4             1             1            27             1             9 
##          1300          1344          1400          1440          1470          1500          1550          1570 
##             1             1             4             2             1             3             1             1 
##          1575          1600          1680          1700          1800          2000          2122          2240 
##             1             1             2             1             1            10             1             1 
##          2400          2460          2600          2650          2700          2800          2850          2880 
##            23             1             2             1             2             3             1             1 
##          3000          3360          3500          3600          3800          3840          3900          4000 
##             5             4             2             1             1             1             1             4 
##          4200          4320          4462          4600          4800          5000          5500          5760 
##             1             1             1             1             3             6             1             1 
##          6300          6720          7000          7200          8000          8593          9000          9120 
##             1             1             1             1             1             1             1             1 
##          9600         12000         13000 13267 or more          <NA> 
##             1             2             1             4          1594

percentile_99.5 <- floor(quantile(na.exclude(mydata$eh_s11q34)[na.exclude(mydata$eh_s11q34)!=999999], probs = c(0.995)))
mydata <- top_recode (variable="eh_s11q34", break_point=percentile_99.5, missing=999999)
## [1] "Frequency table before encoding"
## eh_s11q34. Q827: In the past 12 months, what is the total amount withdrawn from these accou
##  -999  -998     0    60   100   150   200   240   270   300   340   400   410   450   500   520   600   650   679 
##     7    17   408     1     1     1     9     1     1    19     1    14     1     1    31     1     7     1     1 
##   700   710   720   730   750   800   852   900  1000  1050  1120  1200  1225  1300  1400  1500  1600  1620  1650 
##     3     1     1     1     1     8     1     6    30     1     1     4     1     3     1    12     5     1     1 
##  1700  1800  1900  2000  2100  2200  2360  2400  2500  2700  2900  3000  3500  3700  3800  4000  4500  4700  4750 
##     1     2     1    20     1     2     1     2     6     2     1     8     2     2     3     5     1     1     1 
##  4800  5000  6000  6880  7000  7300  7500  8000  8500 10000 10500 12600 16000 32000 40000 42000 1e+05  <NA> 
##     1     5     3     1     2     1     1     2     1     3     1     1     1     1     1     1     1  1594

## [1] "Frequency table after encoding"
## eh_s11q34. Q827: In the past 12 months, what is the total amount withdrawn from these accou
##          -999          -998             0            60           100           150           200           240 
##             7            17           408             1             1             1             9             1 
##           270           300           340           400           410           450           500           520 
##             1            19             1            14             1             1            31             1 
##           600           650           679           700           710           720           730           750 
##             7             1             1             3             1             1             1             1 
##           800           852           900          1000          1050          1120          1200          1225 
##             8             1             6            30             1             1             4             1 
##          1300          1400          1500          1600          1620          1650          1700          1800 
##             3             1            12             5             1             1             1             2 
##          1900          2000          2100          2200          2360          2400          2500          2700 
##             1            20             1             2             1             2             6             2 
##          2900          3000          3500          3700          3800          4000          4500          4700 
##             1             8             2             2             3             5             1             1 
##          4750          4800          5000          6000          6880          7000          7300          7500 
##             1             1             5             3             1             2             1             1 
##          8000          8500         10000         10500         12600         16000 24559 or more          <NA> 
##             2             1             3             1             1             1             4          1594

percentile_99.5 <- floor(quantile(na.exclude(mydata$eh_s11q36)[na.exclude(mydata$eh_s11q36)!=999999], probs = c(0.995)))
mydata <- top_recode (variable="eh_s11q36", break_point=percentile_99.5, missing=999999)
## [1] "Frequency table before encoding"
## eh_s11q36. Q829: In the past 12 months, how much income did you earn from interest on these
##  -999  -998     0     2     3     4     5     6     8     9    10    11    12    13    14    15    17    18    20 
##     3    77    11     1     2     1     5     5     1     1     2     2     2     1     1     3     2     1     8 
##    21    23    25    28    30    32    33    35    36    38    40    44    45    47    48    50    53    54    60 
##     1     2     4     1     7     1     1     3     3     1     4     1     2     1     1     9     1     1     4 
##    66    70    80    85    90    96   100   105   120   123   125   136   150   168   175   180   200   210   215 
##     1     3     1     1     2     1    15     1     2     1     1     1     5     1     1     3    15     3     1 
##   224   225   228   240   245   246   250   280   288   299   300   320   350   358   360   370   390   400   435 
##     1     1     1     1     1     1     1     1     1     1     7     2     2     1     1     1     1     4     1 
##   487   500   588   600   624   750   760   800   845  1000  1075  1200  1300  1500  1800  2000  3000  5000 12000 
##     1     5     1     5     1     1     2     4     1     6     1     2     1     4     1     4     1     1     1 
##  <NA> 
##  1979

## [1] "Frequency table after encoding"
## eh_s11q36. Q829: In the past 12 months, how much income did you earn from interest on these
##         -999         -998            0            2            3            4            5            6            8 
##            3           77           11            1            2            1            5            5            1 
##            9           10           11           12           13           14           15           17           18 
##            1            2            2            2            1            1            3            2            1 
##           20           21           23           25           28           30           32           33           35 
##            8            1            2            4            1            7            1            1            3 
##           36           38           40           44           45           47           48           50           53 
##            3            1            4            1            2            1            1            9            1 
##           54           60           66           70           80           85           90           96          100 
##            1            4            1            3            1            1            2            1           15 
##          105          120          123          125          136          150          168          175          180 
##            1            2            1            1            1            5            1            1            3 
##          200          210          215          224          225          228          240          245          246 
##           15            3            1            1            1            1            1            1            1 
##          250          280          288          299          300          320          350          358          360 
##            1            1            1            1            7            2            2            1            1 
##          370          390          400          435          487          500          588          600          624 
##            1            1            4            1            1            5            1            5            1 
##          750          760          800          845         1000         1075         1200         1300         1500 
##            1            2            4            1            6            1            2            1            4 
##         1800         2000         3000 3919 or more         <NA> 
##            1            4            1            2         1979

percentile_99.5 <- floor(quantile(na.exclude(mydata$eh_s11q38)[na.exclude(mydata$eh_s11q38)!=999999], probs = c(0.995)))
mydata <- top_recode (variable="eh_s11q38", break_point=percentile_99.5, missing=999999)
## [1] "Frequency table before encoding"
## eh_s11q38. Q831: What is the total amount currently saved with the 'paluwagan' by you and a
##  -999  -998     0    70    75   200   300   400   420   450   500   600   700   800   840   900  1000  1020  1050 
##     1     2     2     1     1     2     2     1     1     1     3     6     1     5     1     2     5     1     1 
##  1180  1200  1400  1500  1600  1750  1900  2300  2600  2800  3000  3080  3100  3150  3200  3300  3500  3600  3900 
##     1     7     1     2     1     1     1     2     2     3     8     1     1     1     2     1     1     1     1 
##  4000  4200  4500  4600  4800  5000  5200  5600  6000  6300  6600  6900  7000  7200  8000  8400  8500  8800  9000 
##     5     2     1     1     2     9     1     1     7     1     1     1     5     1     3     1     1     1     1 
##  9600 10000 10700 11000 11500 11600 12000 13000 13500 14700 15000 15400 15800 17000 17800 18000 19000 20000 22000 
##     1     2     1     2     1     1     4     1     1     1     3     2     1     1     1     2     1     2     1 
## 30000 34000 52000  <NA> 
##     1     1     1  2134

## [1] "Frequency table after encoding"
## eh_s11q38. Q831: What is the total amount currently saved with the 'paluwagan' by you and a
##          -999          -998             0            70            75           200           300           400 
##             1             2             2             1             1             2             2             1 
##           420           450           500           600           700           800           840           900 
##             1             1             3             6             1             5             1             2 
##          1000          1020          1050          1180          1200          1400          1500          1600 
##             5             1             1             1             7             1             2             1 
##          1750          1900          2300          2600          2800          3000          3080          3100 
##             1             1             2             2             3             8             1             1 
##          3150          3200          3300          3500          3600          3900          4000          4200 
##             1             2             1             1             1             1             5             2 
##          4500          4600          4800          5000          5200          5600          6000          6300 
##             1             1             2             9             1             1             7             1 
##          6600          6900          7000          7200          8000          8400          8500          8800 
##             1             1             5             1             3             1             1             1 
##          9000          9600         10000         10700         11000         11500         11600         12000 
##             1             1             2             1             2             1             1             4 
##         13000         13500         14700         15000         15400         15800         17000         17800 
##             1             1             1             3             2             1             1             1 
##         18000         19000         20000         22000         30000         34000 38229 or more          <NA> 
##             2             1             2             1             1             1             1          2134

percentile_99.5 <- floor(quantile(na.exclude(mydata$eh_s11q39)[na.exclude(mydata$eh_s11q39)!=999999], probs = c(0.995)))
mydata <- top_recode (variable="eh_s11q39", break_point=percentile_99.5, missing=999999)
## [1] "Frequency table before encoding"
## eh_s11q39. Q832: In the past 12 months, what is the total amount added to these accounts by
##  -999  -998     0   100   200   280   300   350   400   500   600   840   900  1000  1200  1300  2000  2400  2500 
##     3     6   101     4     5     2     1     1     1     1     3     2     1     1     3     1     3     1     1 
##  2660  3000  3100  3600  5000  6400  7000  8000 14700  <NA> 
##     1     2     1     1     4     1     1     1     1  2134

## [1] "Frequency table after encoding"
## eh_s11q39. Q832: In the past 12 months, what is the total amount added to these accounts by
##         -999         -998            0          100          200          280          300          350          400 
##            3            6          101            4            5            2            1            1            1 
##          500          600          840          900         1000         1200         1300         2000         2400 
##            1            3            2            1            1            3            1            3            1 
##         2500         2660         3000         3100         3600         5000         6400         7000         8000 
##            1            1            2            1            1            4            1            1            1 
## 9574 or more         <NA> 
##            1         2134

percentile_99.5 <- floor(quantile(na.exclude(mydata$eh_s11q40)[na.exclude(mydata$eh_s11q40)!=999999], probs = c(0.995)))
mydata <- top_recode (variable="eh_s11q40", break_point=percentile_99.5, missing=999999)
## [1] "Frequency table before encoding"
## eh_s11q40. Q833: In the past 12 months, what is the total amount withdrawn from these accou
##  -999  -998     0   600   700  1000  1500  1600  2000  2200  2600  3000  3500  4000  4200  4600  5000  5600  7200 
##     2     4   120     1     1     2     1     1     2     1     1     2     1     1     2     1     2     1     1 
##  8000 11000 13500 15000 22000  <NA> 
##     2     1     1     2     1  2134

## [1] "Frequency table after encoding"
## eh_s11q40. Q833: In the past 12 months, what is the total amount withdrawn from these accou
##          -999          -998             0           600           700          1000          1500          1600 
##             2             4           120             1             1             2             1             1 
##          2000          2200          2600          3000          3500          4000          4200          4600 
##             2             1             1             2             1             1             2             1 
##          5000          5600          7200          8000         11000         13500         15000 16644 or more 
##             2             1             1             2             1             1             2             1 
##          <NA> 
##          2134

percentile_99.5 <- floor(quantile(na.exclude(mydata$eh_s11q42)[na.exclude(mydata$eh_s11q42)!=999999], probs = c(0.995)))
mydata <- top_recode (variable="eh_s11q42", break_point=percentile_99.5, missing=999999)
## [1] "Frequency table before encoding"
## eh_s11q42. Q835: In the past 12 months, how much income did you earn from interest on these
##    0   50  150  250  300  400  500 2000 3000 <NA> 
##    2    1    1    1    1    2    1    1    1 2277

## [1] "Frequency table after encoding"
## eh_s11q42. Q835: In the past 12 months, how much income did you earn from interest on these
##            0           50          150          250          300          400          500         2000 2949 or more 
##            2            1            1            1            1            2            1            1            1 
##         <NA> 
##         2277

percentile_99.5 <- floor(quantile(na.exclude(mydata$eh_s11q44)[na.exclude(mydata$eh_s11q44)!=999999], probs = c(0.995)))
mydata <- top_recode (variable="eh_s11q44", break_point=percentile_99.5, missing=999999)
## [1] "Frequency table before encoding"
## eh_s11q44. Q837: What is the current amount of these other savings?  Ano ang kasalukuyang h
##   -999   -998      0     20     50     60     89    100    120    140    150    190    200    220    250    300 
##      3     16      6      1      4      1      1      5      1      1      5      1     11      1      1     10 
##    340    350    360    400    450    500    555    560    600    700    800    900   1000   1150   1156   1200 
##      1      1      1      4      1     41      1      2      3      5      3      1     47      1      1      4 
##   1500   1600   1700   1800   2000   2300   2400   2500   2717   2800   3000   3100   3500   3800   4000   4100 
##     18      2      1      1     29      1      2      8      1      1     22      1      2      1      8      1 
##   4200   5000   5790   6000   7000   7500   8000   9000  10000  11000  12000  14500  15000  16000  18000  20000 
##      1     22      1      9      6      1      4      1     12      1      1      1      3      1      3      5 
##  26000  50000  60000  72000  90000  1e+05 120000   <NA> 
##      1      2      1      1      1      3      1   1922

## [1] "Frequency table after encoding"
## eh_s11q44. Q837: What is the current amount of these other savings?  Ano ang kasalukuyang h
##          -999          -998             0            20            50            60            89           100 
##             3            16             6             1             4             1             1             5 
##           120           140           150           190           200           220           250           300 
##             1             1             5             1            11             1             1            10 
##           340           350           360           400           450           500           555           560 
##             1             1             1             4             1            41             1             2 
##           600           700           800           900          1000          1150          1156          1200 
##             3             5             3             1            47             1             1             4 
##          1500          1600          1700          1800          2000          2300          2400          2500 
##            18             2             1             1            29             1             2             8 
##          2717          2800          3000          3100          3500          3800          4000          4100 
##             1             1            22             1             2             1             8             1 
##          4200          5000          5790          6000          7000          7500          8000          9000 
##             1            22             1             9             6             1             4             1 
##         10000         11000         12000         14500         15000         16000         18000         20000 
##            12             1             1             1             3             1             3             5 
##         26000         50000         60000         72000         90000 1e+05 or more          <NA> 
##             1             2             1             1             1             4          1922

percentile_99.5 <- floor(quantile(na.exclude(mydata$eh_s11q45)[na.exclude(mydata$eh_s11q45)!=999999], probs = c(0.995)))
mydata <- top_recode (variable="eh_s11q45", break_point=percentile_99.5, missing=999999)
## [1] "Frequency table before encoding"
## eh_s11q45. Q838: In the past 12 months, what is the total amount added to this savings by y
##  -999  -998     0    20    30    50    80   100   150   200   250   300   320   340   400   450   500   600   700 
##     1    18   243     2     1     6     1     8     1     5     1     1     1     1     2     1    19     3     1 
##   750   800   960  1000  1200  1500  2000  2300  2400  3000  3300  4000  5000  5790  6000  6300  7000  8000  9000 
##     1     1     1    13     1     7     4     1     1     2     1     2     4     1     1     1     1     2     1 
## 10000 10500 18000 20000  <NA> 
##     1     1     1     1  1922

## [1] "Frequency table after encoding"
## eh_s11q45. Q838: In the past 12 months, what is the total amount added to this savings by y
##          -999          -998             0            20            30            50            80           100 
##             1            18           243             2             1             6             1             8 
##           150           200           250           300           320           340           400           450 
##             1             5             1             1             1             1             2             1 
##           500           600           700           750           800           960          1000          1200 
##            19             3             1             1             1             1            13             1 
##          1500          2000          2300          2400          3000          3300          4000          5000 
##             7             4             1             1             2             1             2             4 
##          5790          6000          6300          7000          8000          9000         10000         10500 
##             1             1             1             1             2             1             1             1 
## 11812 or more          <NA> 
##             2          1922

percentile_99.5 <- floor(quantile(na.exclude(mydata$eh_s11q46)[na.exclude(mydata$eh_s11q46)!=999999], probs = c(0.995)))
mydata <- top_recode (variable="eh_s11q46", break_point=percentile_99.5, missing=999999)
## [1] "Frequency table before encoding"
## eh_s11q46. Q839: In the past 12 months, what is the total amount withdrawn from this saving
##  -999  -998     0    15    20    80   100   200   300   400   500   520   600   700   800  1000  1200  1500  2000 
##     2    10   298     1     1     1     1     9     2     3    13     1     1     1     2     6     1     1     4 
##  3000  3500  4500  5000 10000 20000  <NA> 
##     1     2     1     2     1     1  1922

## [1] "Frequency table after encoding"
## eh_s11q46. Q839: In the past 12 months, what is the total amount withdrawn from this saving
##         -999         -998            0           15           20           80          100          200          300 
##            2           10          298            1            1            1            1            9            2 
##          400          500          520          600          700          800         1000         1200         1500 
##            3           13            1            1            1            2            6            1            1 
##         2000         3000         3500         4500         5000 5875 or more         <NA> 
##            4            1            2            1            2            2         1922

percentile_99.5 <- floor(quantile(na.exclude(mydata$eh_s11q48)[na.exclude(mydata$eh_s11q48)!=999999], probs = c(0.995)))
mydata <- top_recode (variable="eh_s11q48", break_point=percentile_99.5, missing=999999)
## [1] "Frequency table before encoding"
## eh_s11q48. Q841: In the past 12 months, how much income did you earn from interest on this 
## -998  100  150  200  350  500 1000 4000 <NA> 
##    3    1    1    2    1    1    1    2 2276

## [1] "Frequency table after encoding"
## eh_s11q48. Q841: In the past 12 months, how much income did you earn from interest on this 
##         -998          100          150          200          350          500         1000 4000 or more         <NA> 
##            3            1            1            2            1            1            1            2         2276

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("eh_s11q1",
                  "eh_s11q2",
                  "eh_s11q5",
                  "eh_s11q8",
                  "eh_s11q11",
                  "eh_s11q14",
                  "eh_s11q17",
                  "eh_s11q20",
                  "eh_s11q23",
                  "eh_s11q25",
                  "eh_s11q29",
                  "eh_s11q31",
                  "eh_s11q35",
                  "eh_s11q37",
                  "eh_s11q41",
                  "eh_s11q43",
                  "eh_s11q47")

capture_tables (indirect_PII)

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

Matching and crosstabulations: Run automated PII check

# !!!Insufficient demographic data

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

# !!!No Open-ends

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)