Queremos a partir de la columna de folio o vivienda descubrir un patrón para el factor de expansión comunal faltante en algunas comunas de la Casen del 2015.

2017

1 Leemos la Casen 2017

dataset2017  <- readRDS("dataset2017.rds")

Huara

2 Seleccionamos las primeras 10 columnas de la comuna de Huara (no tiene factor de expansión comunal para el 2015):

huara <- dataset2017[dataset2017$comuna == "Huara", ] 
huara <- huara[,1:10]
head(huara,10)
##           folio o id_vivienda hogar             region provincia comuna  zona
## 9800 1.4043e+11 1  1404300201     1 Región de Tarapacá Tamarugal  Huara Rural
## 9801 1.4043e+11 1  1404300202     1 Región de Tarapacá Tamarugal  Huara Rural
## 9802 1.4043e+11 2  1404300202     1 Región de Tarapacá Tamarugal  Huara Rural
## 9803 1.4043e+11 1  1404300203     1 Región de Tarapacá Tamarugal  Huara Rural
## 9804 1.4043e+11 1  1404300204     1 Región de Tarapacá Tamarugal  Huara Rural
## 9805 1.4043e+11 1  1404300205     1 Región de Tarapacá Tamarugal  Huara Rural
## 9806 1.4043e+11 1  1404300206     1 Región de Tarapacá Tamarugal  Huara Rural
## 9807 1.4043e+11 2  1404300206     1 Región de Tarapacá Tamarugal  Huara Rural
## 9808 1.4043e+11 1  1404300208     1 Región de Tarapacá Tamarugal  Huara Rural
## 9809 1.4043e+11 2  1404300208     1 Región de Tarapacá Tamarugal  Huara Rural
##      expr expc
## 9800   23   22
## 9801   23   22
## 9802   23   22
## 9803   23   22
## 9804   23   22
## 9805   23   22
## 9806   23   22
## 9807   23   22
## 9808   23   22
## 9809   23   22

3 Extraemos los dígitos del 5 al 8 de folio:

huara_sub <- str_sub(huara$folio, 5,8)
head(huara_sub, 10)
##  [1] "3002" "3002" "3002" "3002" "3002" "3002" "3002" "3002" "3002" "3002"

4 Extraemos los valores del factor de expansión para Huara:

huara_fdee <- huara$expc
head(huara_fdee, 10)
##  [1] 22 22 22 22 22 22 22 22 22 22

5 Las unimos:

huara_unida <- cbind(huara_sub, huara_fdee)
head(huara_unida,10)
##       huara_sub huara_fdee
##  [1,] "3002"    "22"      
##  [2,] "3002"    "22"      
##  [3,] "3002"    "22"      
##  [4,] "3002"    "22"      
##  [5,] "3002"    "22"      
##  [6,] "3002"    "22"      
##  [7,] "3002"    "22"      
##  [8,] "3002"    "22"      
##  [9,] "3002"    "22"      
## [10,] "3002"    "22"

6 Extraemos todos los valores repetidos:

colnames(huara_unida)[1] <- "Código ad-hoc"
colnames(huara_unida)[2] <- "Factor de expansión comunal"

unique(huara_unida)
##      Código ad-hoc Factor de expansión comunal
## [1,] "3002"        "22"                       
## [2,] "3003"        "25"                       
## [3,] "3004"        "17"                       
## [4,] "3005"        "17"

Ese valor repetido para el código 3005 es sólo coincidencia.

Santiago

santiago <- dataset2017[dataset2017$comuna == "Santiago", ] 
santiago <- santiago[,1:10]
head(santiago, 10)
##              folio o id_vivienda hogar                           region
## 155776 1.31011e+12 1 13101100105     1 Región Metropolitana de Santiago
## 155777 1.31011e+12 2 13101100105     1 Región Metropolitana de Santiago
## 155778 1.31011e+12 3 13101100105     1 Región Metropolitana de Santiago
## 155779 1.31011e+12 1 13101100107     1 Región Metropolitana de Santiago
## 155780 1.31011e+12 2 13101100107     1 Región Metropolitana de Santiago
## 155781 1.31011e+12 1 13101100117     1 Región Metropolitana de Santiago
## 155782 1.31011e+12 2 13101100117     1 Región Metropolitana de Santiago
## 155783 1.31011e+12 3 13101100117     1 Región Metropolitana de Santiago
## 155784 1.31011e+12 1 13101100122     1 Región Metropolitana de Santiago
## 155785 1.31011e+12 2 13101100122     1 Región Metropolitana de Santiago
##        provincia   comuna   zona expr expc
## 155776  Santiago Santiago Urbano   68   17
## 155777  Santiago Santiago Urbano   68   17
## 155778  Santiago Santiago Urbano   68   17
## 155779  Santiago Santiago Urbano   68   17
## 155780  Santiago Santiago Urbano   68   17
## 155781  Santiago Santiago Urbano   68   17
## 155782  Santiago Santiago Urbano   68   17
## 155783  Santiago Santiago Urbano   68   17
## 155784  Santiago Santiago Urbano   68   17
## 155785  Santiago Santiago Urbano   68   17
library(stringr)

#para Concepción:
# sub_folio <- str_sub(mejillones$folio, 5,8)

# para Santiago:
santiago_sub <- str_sub(santiago$folio, 6,9)
head(santiago_sub,10)
##  [1] "1001" "1001" "1001" "1001" "1001" "1001" "1001" "1001" "1001" "1001"
santiago_fdee <- santiago$expc
head(santiago_fdee, 10)
##  [1] 17 17 17 17 17 17 17 17 17 17
santiago_unido <- cbind(santiago_sub, santiago_fdee)
head(santiago_unido, 10)
##       santiago_sub santiago_fdee
##  [1,] "1001"       "17"         
##  [2,] "1001"       "17"         
##  [3,] "1001"       "17"         
##  [4,] "1001"       "17"         
##  [5,] "1001"       "17"         
##  [6,] "1001"       "17"         
##  [7,] "1001"       "17"         
##  [8,] "1001"       "17"         
##  [9,] "1001"       "17"         
## [10,] "1001"       "17"
colnames(santiago_unido)[1] <- "Código ad-hoc"
colnames(santiago_unido)[2] <- "Factor de expansión comunal"
unique(santiago_unido)
##       Código ad-hoc Factor de expansión comunal
##  [1,] "1001"        "17"                       
##  [2,] "1002"        "24"                       
##  [3,] "1003"        "39"                       
##  [4,] "1004"        "13"                       
##  [5,] "1005"        "53"                       
##  [6,] "1006"        "40"                       
##  [7,] "1007"        "15"                       
##  [8,] "1009"        "55"                       
##  [9,] "1010"        "41"                       
## [10,] "1011"        "57"                       
## [11,] "1012"        "25"                       
## [12,] "1013"        "18"                       
## [13,] "1014"        "20"                       
## [14,] "1016"        "88"                       
## [15,] "1017"        "156"                      
## [16,] "1018"        "42"                       
## [17,] "1019"        "25"                       
## [18,] "1020"        "38"                       
## [19,] "1021"        "23"                       
## [20,] "1022"        "23"                       
## [21,] "1023"        "21"                       
## [22,] "1024"        "25"                       
## [23,] "1025"        "36"                       
## [24,] "1027"        "18"                       
## [25,] "1028"        "43"                       
## [26,] "1029"        "35"                       
## [27,] "1030"        "21"                       
## [28,] "1031"        "48"                       
## [29,] "1032"        "1220"                     
## [30,] "1033"        "68"                       
## [31,] "1034"        "40"                       
## [32,] "1035"        "22"                       
## [33,] "1036"        "34"                       
## [34,] "1037"        "50"                       
## [35,] "1038"        "24"                       
## [36,] "1039"        "33"                       
## [37,] "1040"        "29"                       
## [38,] "1041"        "40"                       
## [39,] "1042"        "141"                      
## [40,] "1043"        "39"                       
## [41,] "1044"        "143"                      
## [42,] "1045"        "39"                       
## [43,] "1046"        "151"                      
## [44,] "1047"        "131"                      
## [45,] "1048"        "25"                       
## [46,] "1049"        "61"                       
## [47,] "1050"        "29"                       
## [48,] "1051"        "29"                       
## [49,] "1052"        "1438"                     
## [50,] "1053"        "22"                       
## [51,] "1054"        "38"                       
## [52,] "1055"        "22"                       
## [53,] "1056"        "132"                      
## [54,] "1057"        "225"                      
## [55,] "1058"        "74"                       
## [56,] "1059"        "43"                       
## [57,] "1060"        "16"                       
## [58,] "1061"        "156"                      
## [59,] "1062"        "65"                       
## [60,] "1063"        "19"                       
## [61,] "1064"        "19"                       
## [62,] "1065"        "12"                       
## [63,] "1066"        "50"                       
## [64,] "1067"        "61"                       
## [65,] "1068"        "66"                       
## [66,] "1069"        "25"                       
## [67,] "1070"        "24"                       
## [68,] "1071"        "44"                       
## [69,] "1072"        "25"                       
## [70,] "1073"        "27"                       
## [71,] "1074"        "26"                       
## [72,] "1075"        "196"                      
## [73,] "1076"        "19"                       
## [74,] "1077"        "15"                       
## [75,] "1078"        "29"                       
## [76,] "1079"        "11"                       
## [77,] "1080"        "49"                       
## [78,] "1081"        "27"                       
## [79,] "1082"        "125"                      
## [80,] "1083"        "26"                       
## [81,] "1084"        "21"                       
## [82,] "1086"        "54"                       
## [83,] "1087"        "15"                       
## [84,] "1088"        "26"                       
## [85,] "1089"        "26"                       
## [86,] "1090"        "50"                       
## [87,] "1091"        "65"                       
## [88,] "1092"        "97"                       
## [89,] "1094"        "25"                       
## [90,] "1095"        "19"                       
## [91,] "1096"        "19"                       
## [92,] "1097"        "51"                       
## [93,] "1098"        "70"                       
## [94,] "1099"        "50"                       
## [95,] "1100"        "90"                       
## [96,] "1101"        "163"                      
## [97,] "1102"        "35"                       
## [98,] "1103"        "17"

Concepción

concepcion <- dataset2017[dataset2017$comuna == "Concepción", ] 
concepcion <- concepcion[,1:10]
head(concepcion,10)
##            folio o id_vivienda hogar            region  provincia     comuna
## 86269 8.1011e+11 1  8101100101     1 Región del Biobío Concepción Concepción
## 86270 8.1011e+11 1  8101100102     1 Región del Biobío Concepción Concepción
## 86271 8.1011e+11 1  8101100102     2 Región del Biobío Concepción Concepción
## 86272 8.1011e+11 1  8101100105     1 Región del Biobío Concepción Concepción
## 86273 8.1011e+11 2  8101100105     1 Región del Biobío Concepción Concepción
## 86274 8.1011e+11 3  8101100105     1 Región del Biobío Concepción Concepción
## 86275 8.1011e+11 1  8101100106     1 Región del Biobío Concepción Concepción
## 86276 8.1011e+11 1  8101100106     2 Región del Biobío Concepción Concepción
## 86277 8.1011e+11 1  8101100106     3 Región del Biobío Concepción Concepción
## 86278 8.1011e+11 1  8101100107     1 Región del Biobío Concepción Concepción
##         zona expr expc
## 86269 Urbano   51   51
## 86270 Urbano   51   51
## 86271 Urbano   51   51
## 86272 Urbano   51   51
## 86273 Urbano   51   51
## 86274 Urbano   51   51
## 86275 Urbano   51   51
## 86276 Urbano   51   51
## 86277 Urbano   51   51
## 86278 Urbano   51   51
concepcion_sub <- str_sub(concepcion$folio, 5,8)
head(concepcion_sub, 10)
##  [1] "1001" "1001" "1001" "1001" "1001" "1001" "1001" "1001" "1001" "1001"
concepcion_fdee <- concepcion$expc
head(concepcion_fdee, 10)
##  [1] 51 51 51 51 51 51 51 51 51 51
concepcion_unido <- cbind(concepcion_sub, concepcion_fdee)
head(concepcion_unido,10)
##       concepcion_sub concepcion_fdee
##  [1,] "1001"         "51"           
##  [2,] "1001"         "51"           
##  [3,] "1001"         "51"           
##  [4,] "1001"         "51"           
##  [5,] "1001"         "51"           
##  [6,] "1001"         "51"           
##  [7,] "1001"         "51"           
##  [8,] "1001"         "51"           
##  [9,] "1001"         "51"           
## [10,] "1001"         "51"
colnames(concepcion_unido)[1] <- "Código ad-hoc"
colnames(concepcion_unido)[2] <- "Factor de expansión comunal"

unique(concepcion_unido)
##        Código ad-hoc Factor de expansión comunal
##   [1,] "1001"        "51"                       
##   [2,] "1002"        "126"                      
##   [3,] "1003"        "84"                       
##   [4,] "1004"        "59"                       
##   [5,] "1005"        "82"                       
##   [6,] "1006"        "317"                      
##   [7,] "1007"        "20"                       
##   [8,] "1008"        "65"                       
##   [9,] "1009"        "82"                       
##  [10,] "1010"        "678"                      
##  [11,] "1011"        "188"                      
##  [12,] "1012"        "72"                       
##  [13,] "1013"        "51"                       
##  [14,] "1014"        "101"                      
##  [15,] "1015"        "59"                       
##  [16,] "1016"        "38"                       
##  [17,] "1017"        "42"                       
##  [18,] "1018"        "54"                       
##  [19,] "1019"        "101"                      
##  [20,] "1020"        "73"                       
##  [21,] "1021"        "94"                       
##  [22,] "1022"        "68"                       
##  [23,] "1023"        "68"                       
##  [24,] "1024"        "42"                       
##  [25,] "1025"        "95"                       
##  [26,] "1026"        "20"                       
##  [27,] "1027"        "105"                      
##  [28,] "1028"        "37"                       
##  [29,] "1029"        "98"                       
##  [30,] "1030"        "126"                      
##  [31,] "1031"        "42"                       
##  [32,] "1032"        "85"                       
##  [33,] "1033"        "104"                      
##  [34,] "1034"        "86"                       
##  [35,] "1035"        "71"                       
##  [36,] "1036"        "58"                       
##  [37,] "1037"        "84"                       
##  [38,] "1038"        "63"                       
##  [39,] "1039"        "84"                       
##  [40,] "1040"        "112"                      
##  [41,] "1041"        "110"                      
##  [42,] "1042"        "66"                       
##  [43,] "1044"        "79"                       
##  [44,] "1045"        "59"                       
##  [45,] "1046"        "58"                       
##  [46,] "1047"        "56"                       
##  [47,] "1048"        "54"                       
##  [48,] "1049"        "320"                      
##  [49,] "1050"        "89"                       
##  [50,] "1051"        "66"                       
##  [51,] "1052"        "119"                      
##  [52,] "1053"        "81"                       
##  [53,] "1054"        "61"                       
##  [54,] "1055"        "53"                       
##  [55,] "1056"        "73"                       
##  [56,] "1057"        "105"                      
##  [57,] "1058"        "71"                       
##  [58,] "1059"        "63"                       
##  [59,] "1060"        "58"                       
##  [60,] "1061"        "77"                       
##  [61,] "1062"        "25"                       
##  [62,] "1063"        "83"                       
##  [63,] "1064"        "58"                       
##  [64,] "1065"        "58"                       
##  [65,] "1066"        "134"                      
##  [66,] "1068"        "89"                       
##  [67,] "1069"        "95"                       
##  [68,] "1070"        "155"                      
##  [69,] "1071"        "90"                       
##  [70,] "1072"        "47"                       
##  [71,] "1073"        "105"                      
##  [72,] "1074"        "134"                      
##  [73,] "1075"        "81"                       
##  [74,] "1076"        "100"                      
##  [75,] "1077"        "96"                       
##  [76,] "1078"        "63"                       
##  [77,] "1079"        "101"                      
##  [78,] "1080"        "74"                       
##  [79,] "1081"        "147"                      
##  [80,] "1082"        "122"                      
##  [81,] "1083"        "84"                       
##  [82,] "1084"        "63"                       
##  [83,] "1085"        "58"                       
##  [84,] "1086"        "73"                       
##  [85,] "1087"        "415"                      
##  [86,] "1088"        "95"                       
##  [87,] "1089"        "110"                      
##  [88,] "1090"        "94"                       
##  [89,] "1091"        "91"                       
##  [90,] "1092"        "55"                       
##  [91,] "1093"        "43"                       
##  [92,] "1094"        "86"                       
##  [93,] "1095"        "79"                       
##  [94,] "1096"        "38"                       
##  [95,] "1097"        "40"                       
##  [96,] "1098"        "59"                       
##  [97,] "1099"        "289"                      
##  [98,] "1100"        "56"                       
##  [99,] "1101"        "50"                       
## [100,] "1102"        "78"                       
## [101,] "1104"        "54"                       
## [102,] "1105"        "37"                       
## [103,] "1106"        "83"                       
## [104,] "1107"        "58"                       
## [105,] "1108"        "66"                       
## [106,] "1109"        "163"                      
## [107,] "1110"        "53"                       
## [108,] "1111"        "76"                       
## [109,] "1112"        "100"                      
## [110,] "1113"        "89"                       
## [111,] "1114"        "89"                       
## [112,] "1115"        "62"                       
## [113,] "1116"        "62"                       
## [114,] "1117"        "83"                       
## [115,] "1118"        "79"                       
## [116,] "1119"        "61"                       
## [117,] "1120"        "91"                       
## [118,] "1121"        "107"                      
## [119,] "1122"        "63"                       
## [120,] "1123"        "58"                       
## [121,] "1124"        "56"                       
## [122,] "1125"        "74"                       
## [123,] "1126"        "107"                      
## [124,] "1127"        "100"                      
## [125,] "1128"        "81"                       
## [126,] "1129"        "116"                      
## [127,] "1130"        "126"                      
## [128,] "3001"        "22"                       
## [129,] "3002"        "36"                       
## [130,] "3003"        "22"                       
## [131,] "3004"        "19"                       
## [132,] "3005"        "17"

2015

1 Leemos la Casen 2015

dataset2015  <- readRDS("dataset2015.rds")
# dataset2015

Santiago

santiago <- dataset2015[dataset2015$comuna == "santiago", ] 
# santiago <- santiago[,1:10]
# head(santiago, 10)
library(stringr)

#para Concepción:
# sub_folio <- str_sub(mejillones$folio, 5,8)

# para Santiago:
santiago_sub <- str_sub(santiago$folio, 6,9)
head(santiago_sub,10)
##  [1] "1001" "1001" "1001" "1001" "1001" "1001" "1001" "1001" "1001" "1001"
santiago_fdee <- santiago$expc
head(santiago_fdee, 10)
##  [1] 61 61 61 61 61 61 61 61 61 61
santiago_unido <- cbind(santiago_sub, santiago_fdee)
head(santiago_unido, 10)
##       santiago_sub santiago_fdee
##  [1,] "1001"       "61"         
##  [2,] "1001"       "61"         
##  [3,] "1001"       "61"         
##  [4,] "1001"       "61"         
##  [5,] "1001"       "61"         
##  [6,] "1001"       "61"         
##  [7,] "1001"       "61"         
##  [8,] "1001"       "61"         
##  [9,] "1001"       "61"         
## [10,] "1001"       "61"
colnames(santiago_unido)[1] <- "Código ad-hoc"
colnames(santiago_unido)[2] <- "Factor de expansión comunal"
unique(santiago_unido)
##       Código ad-hoc Factor de expansión comunal
##  [1,] "1001"        "61"                       
##  [2,] "1002"        "50"                       
##  [3,] "1003"        "137"                      
##  [4,] "1004"        "32"                       
##  [5,] "1005"        "17"                       
##  [6,] "1006"        "33"                       
##  [7,] "1007"        "125"                      
##  [8,] "1008"        "35"                       
##  [9,] "1009"        "52"                       
## [10,] "1010"        "24"                       
## [11,] "1011"        "37"                       
## [12,] "1012"        "37"                       
## [13,] "1013"        "68"                       
## [14,] "1014"        "40"                       
## [15,] "1015"        "47"                       
## [16,] "1016"        "20"                       
## [17,] "1017"        "78"                       
## [18,] "1018"        "61"                       
## [19,] "1019"        "69"                       
## [20,] "1020"        "41"                       
## [21,] "1021"        "52"                       
## [22,] "1022"        "18"                       
## [23,] "1023"        "80"                       
## [24,] "1024"        "101"                      
## [25,] "1025"        "63"                       
## [26,] "1026"        "1148"                     
## [27,] "1027"        "282"                      
## [28,] "1028"        "95"                       
## [29,] "1030"        "500"                      
## [30,] "1031"        "36"                       
## [31,] "1032"        "757"                      
## [32,] "1033"        "22"                       
## [33,] "1034"        "52"                       
## [34,] "1035"        "30"                       
## [35,] "1036"        "22"                       
## [36,] "1037"        "53"                       
## [37,] "1038"        "27"                       
## [38,] "1039"        "29"                       
## [39,] "1040"        "14"                       
## [40,] "1041"        "28"                       
## [41,] "1042"        "35"                       
## [42,] "1043"        "46"                       
## [43,] "1044"        "30"                       
## [44,] "1045"        "40"                       
## [45,] "1046"        "20"                       
## [46,] "1047"        "33"                       
## [47,] "1048"        "308"                      
## [48,] "1049"        "25"                       
## [49,] "1050"        "228"                      
## [50,] "1052"        "39"                       
## [51,] "1053"        "39"                       
## [52,] "1054"        "35"                       
## [53,] "1055"        "22"                       
## [54,] "1056"        "109"                      
## [55,] "1057"        "30"                       
## [56,] "1058"        "52"                       
## [57,] "1059"        "32"                       
## [58,] "1060"        "22"                       
## [59,] "1061"        "40"                       
## [60,] "1062"        "22"                       
## [61,] "1063"        "11"                       
## [62,] "1064"        "39"                       
## [63,] "1065"        "36"                       
## [64,] "1066"        "50"                       
## [65,] "1067"        "52"                       
## [66,] "1068"        "27"                       
## [67,] "1069"        "20"                       
## [68,] "1070"        "65"                       
## [69,] "1071"        "72"                       
## [70,] "1072"        "49"                       
## [71,] "1073"        "36"                       
## [72,] "1074"        "63"                       
## [73,] "1075"        "39"                       
## [74,] "1076"        "32"                       
## [75,] "1077"        "47"                       
## [76,] "1078"        "48"                       
## [77,] "1079"        "147"                      
## [78,] "1080"        "69"                       
## [79,] "1081"        "36"                       
## [80,] "1082"        "40"                       
## [81,] "1083"        "124"

Conclusión

Si bien hemos logrado asociar un código al factor de expansión comunal extrayendo cierta secuencia del campo folio, no encontramos todavía asociación alguna entre los factores de expansión entre años para las comunas.