library(dplyr)
## Warning: package 'dplyr' was built under R version 4.4.3
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(readr) 
## Warning: package 'readr' was built under R version 4.4.3
library(srvyr)
## Warning: package 'srvyr' was built under R version 4.4.3
## 
## Attaching package: 'srvyr'
## The following object is masked from 'package:stats':
## 
##     filter
library(stringr)
library(tidyr)
## Warning: package 'tidyr' was built under R version 4.4.3

Población

conapo <- read_csv("pobproy_quinq1.csv")
## Rows: 252450 Columns: 27
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr   (4): NOM_ENT, NOM_MUN, SEXO, etiqueta_estado
## dbl  (22): CLAVE, CLAVE_ENT, ANO, POB_TOTAL, POB_00_04, POB_05_09, POB_010_0...
## date  (1): fecha
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
poblacion_estados <- conapo %>%
  filter(CLAVE_ENT %in% c(7, 28))
pob_anual <- poblacion_estados %>%
  group_by(CLAVE_ENT, NOM_ENT, ANO) %>%
  summarise(
    POB_TOTAL = sum(POB_TOTAL, na.rm = TRUE),
    .groups = "drop"
  )

Pobreza

2016

pobreza <- read.csv("pobreza_16.csv")

#  Chiapas (7) y Tam (28)
pobreza_filtrado <- pobreza %>% filter(ent %in% c(7, 28))

# pondero con el factor que ya viene 
pob_w <- as_survey_design(pobreza_filtrado, weights = factor, strata = est_dis, ids = upm, nest = TRUE)

# % de población con ingreso menor a la línea de pobreza, por estado
resultado <- pob_w %>%
  group_by(ent) %>%
  summarise(
    pct_plp   = survey_mean(plp, na.rm = TRUE) * 100,    # % pobreza por ingresos
    pct_plp_e = survey_mean(plp_e, na.rm = TRUE) * 100,  # % pobreza extrema por ingresos
    ictpc_prom = survey_mean(ictpc, na.rm = TRUE)         # ingreso per cápita promedio
  )

2018

pobreza_18 <- read.csv("pobreza_18.csv")

pobreza_18_filtrado <- pobreza_18 %>% filter(ent %in% c(7, 28))

pob_w_18 <- as_survey_design(pobreza_18_filtrado, weights = factor, 
                              strata = est_dis, ids = upm, nest = TRUE)

resultado_18 <- pob_w_18 %>%
  group_by(ent) %>%
  summarise(
    pct_plp    = survey_mean(plp, na.rm = TRUE) * 100,
    pct_plp_e  = survey_mean(plp_e, na.rm = TRUE) * 100,
    ictpc_prom = survey_mean(ictpc, na.rm = TRUE)
  )

print(resultado_18)
## # A tibble: 2 × 7
##     ent pct_plp pct_plp_se pct_plp_e pct_plp_e_se ictpc_prom ictpc_prom_se
##   <int>   <dbl>      <dbl>     <dbl>        <dbl>      <dbl>         <dbl>
## 1     7    81.0       1.38      49.4         2.37      2138.          86.4
## 2    28    48.4       1.60      11.9         1.11      4849.         225.

2020

pobreza_20 <- read.csv("pobreza_20.csv")

pobreza_20_filtrado <- pobreza_20 %>% filter(ent %in% c(7, 28))

pob_w_20 <- as_survey_design(pobreza_20_filtrado, weights = factor, 
                              strata = est_dis, ids = upm, nest = TRUE)

resultado_20 <- pob_w_20 %>%
  group_by(ent) %>%
  summarise(
    pct_plp    = survey_mean(plp, na.rm = TRUE) * 100,
    pct_plp_e  = survey_mean(plp_e, na.rm = TRUE) * 100,
    ictpc_prom = survey_mean(ictpc, na.rm = TRUE)
  )

print(resultado_20)
## # A tibble: 2 × 7
##     ent pct_plp pct_plp_se pct_plp_e pct_plp_e_se ictpc_prom ictpc_prom_se
##   <int>   <dbl>      <dbl>     <dbl>        <dbl>      <dbl>         <dbl>
## 1     7    78.8       1.28      44.1        2.47       2435.          85.1
## 2    28    48.3       1.35      12.7        0.810      4913.         168.

2022

pobreza_22 <- read.csv("pobreza_22.csv")

pobreza_22_filtrado <- pobreza_22 %>% filter(ent %in% c(7, 28))

pob_w_22 <- as_survey_design(pobreza_22_filtrado, weights = factor, 
                              strata = est_dis, ids = upm, nest = TRUE)

resultado_22 <- pob_w_22 %>%
  group_by(ent) %>%
  summarise(
    pct_plp    = survey_mean(plp, na.rm = TRUE) * 100,
    pct_plp_e  = survey_mean(plp_e, na.rm = TRUE) * 100,
    ictpc_prom = survey_mean(ictpc, na.rm = TRUE)
  )

print(resultado_22)
## # A tibble: 2 × 7
##     ent pct_plp pct_plp_se pct_plp_e pct_plp_e_se ictpc_prom ictpc_prom_se
##   <int>   <dbl>      <dbl>     <dbl>        <dbl>      <dbl>         <dbl>
## 1     7    70.0       1.60     36.6         2.26       3404.          142.
## 2    28    37.5       1.41      8.03        0.778      6540.          150.

Ingresos antes de 2014

2014

# como es una version previa del ENIGH que la de 2016 en adelante, NO ES COMPARABLE.
# deflacto para mayor comparación 
enigh14 <- read_csv("concentradohogar.csv")
## Rows: 19479 Columns: 132
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr   (6): folioviv, ubica_geo, ageb, est_dis, upm, educa_jefe
## dbl (126): foliohog, tam_loc, est_socio, factor_hog, clase_hog, sexo_jefe, e...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
inpc_2014 <- 85.220
inpc_2024 <- 136.013
enigh14 <- enigh14 %>%
  mutate(
    ubica_geo_str = str_pad(as.character(ubica_geo), 5, "left", pad = "0"),
    ent = as.numeric(str_sub(ubica_geo_str, 1, 2)),
    INGCOR = as.numeric(ing_cor),
    INGMON = as.numeric(ing_mon),
    factor = as.numeric(factor_hog)
  )
resultado <- enigh14 %>%
  filter(ent %in% c(7, 28)) %>%
  group_by(ent) %>%
  summarise(
    ingreso_prom_ict = sum(ing_cor * factor, na.rm = TRUE) / sum(factor, na.rm = TRUE),
    ingreso_prom_mon = sum(ing_mon * factor, na.rm = TRUE) / sum(factor, na.rm = TRUE)
  )



factor_deflactor <- inpc_2024 / inpc_2014

enigh14 <- enigh14 %>%
  mutate(
    ubica_geo_str = str_pad(as.character(ubica_geo), 8, "left", pad = "0"),
    ent = as.numeric(str_sub(ubica_geo_str, 1, 2))
  )

# Filtro CH y TAM
enigh_filtrado <- enigh14 %>% filter(ent %in% c(7, 28))

resultado <- resultado %>%
  mutate(
    ingreso_prom_ict_2024pesos = ingreso_prom_ict * factor_deflactor,
    ingreso_prom_mon_2024pesos = ingreso_prom_mon * factor_deflactor
  )

print(resultado)
## # A tibble: 2 × 5
##     ent ingreso_prom_ict ingreso_prom_mon ingreso_prom_ict_2024pesos
##   <dbl>            <dbl>            <dbl>                      <dbl>
## 1     7           21536.           16697.                     34372.
## 2    28           42159.           35424.                     67287.
## # ℹ 1 more variable: ingreso_prom_mon_2024pesos <dbl>

2012

enigh12 <- read_csv("concentradohogar2012.csv")
## Rows: 9002 Columns: 132
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr   (6): folioviv, ubica_geo, ageb, est_dis, upm, educa_jefe
## dbl (126): foliohog, tam_loc, est_socio, factor_hog, clase_hog, sexo_jefe, e...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
inpc_2012 <- 79.0910
inpc_2024 <- 136.013

factor_deflactor <- inpc_2024 / inpc_2012
enigh12 <- enigh12 %>%
  mutate(
    ubica_geo_str = str_pad(as.character(ubica_geo), 8, "left", pad = "0"),
    ent = as.numeric(str_sub(ubica_geo_str, 1, 2))
  )
resultado <- enigh12%>%
  filter(ent %in% c(7, 28)) %>%
  group_by(ent) %>%
  summarise(
    ingreso_prom_ict = sum(ing_cor * factor_hog, na.rm = TRUE) / sum(factor_hog, na.rm = TRUE),
    ingreso_prom_mon = sum(ing_mon * factor_hog, na.rm = TRUE) / sum(factor_hog, na.rm = TRUE)
  )
# Filtrar
enigh_filtrado <- enigh12 %>% filter(ent %in% c(7, 28))

resultado <- resultado %>%
  mutate(
    ingreso_prom_ict_2024pesos = ingreso_prom_ict * factor_deflactor,
    ingreso_prom_mon_2024pesos = ingreso_prom_mon * factor_deflactor
  )

print(resultado)
## # A tibble: 2 × 5
##     ent ingreso_prom_ict ingreso_prom_mon ingreso_prom_ict_2024pesos
##   <dbl>            <dbl>            <dbl>                      <dbl>
## 1     7           21032.           16470.                     36168.
## 2    28           39053.           31856.                     67160.
## # ℹ 1 more variable: ingreso_prom_mon_2024pesos <dbl>

2010

library(dplyr)
library(stringr)
library(foreign)
## Warning: package 'foreign' was built under R version 4.4.3
datos <- read.dbf("enigh2010.dbf", as.is = TRUE)
datos <- datos %>%
  mutate(
    ubica_geo_str = str_pad(as.character(ubica_geo), 5, "left", pad = "0"),
    ent = as.numeric(str_sub(ubica_geo_str, 1, 2))
  )

table(datos$ent)
## 
##    1    2    3    4    5    6    7    8    9   10   11   12   13   14   15   16 
##  329  504  299  427  564  361 2805  836 2799  497 1901  868  513  595 2748  700 
##   17   18   19   20   21   22   23   24   25   26   27   28   29   30   31   32 
##  462  408  411 1051  662  452  350  539  458  649  487  558  380  898 2719  425
resultado_2010 <- datos %>%
  filter(ent %in% c(7, 28)) %>%
  group_by(ent) %>%
  summarise(
    ingreso_prom_ict = sum(ingcor * factor, na.rm = TRUE) / sum(factor, na.rm = TRUE),
    ingreso_prom_mon = sum(ingmon * factor, na.rm = TRUE) / sum(factor, na.rm = TRUE)
  )

# Deflactar
inpc_2010 <- 73.1316
inpc_2024 <- 136.013
factor_deflactor_2010 <- inpc_2024 / inpc_2010

resultado_2010 <- resultado_2010 %>%
  mutate(
    ingreso_prom_ict_2024pesos = ingreso_prom_ict * factor_deflactor_2010,
    ingreso_prom_mon_2024pesos = ingreso_prom_mon * factor_deflactor_2010
  )

print(resultado_2010)
## # A tibble: 2 × 5
##     ent ingreso_prom_ict ingreso_prom_mon ingreso_prom_ict_2024pesos
##   <dbl>            <dbl>            <dbl>                      <dbl>
## 1     7           18547.           15096.                     34494.
## 2    28           31755.           26103.                     59060.
## # ℹ 1 more variable: ingreso_prom_mon_2024pesos <dbl>

2008

library(dplyr)
library(stringr)

datos <- read.dbf("enigh2008.dbf", as.is = TRUE)
names(datos)
##   [1] "FOLIOVIV"   "FOLIOHOG"   "FACTOR"     "ESTRATO"    "UBICA_GEO" 
##   [6] "CONAPO"     "TENENCIA"   "CLASE_HOG"  "SEXO"       "EDAD"      
##  [11] "ED_FORMAL"  "TAM_HOG"    "HOMBRES"    "MUJERES"    "TOT_RESI"  
##  [16] "TOT_HOM"    "TOT_MUJ"    "MAYORES"    "MENORES"    "P12_64"    
##  [21] "P65MAS"     "N_OCUP"     "PERING"     "PEROCU"     "INGTOT"    
##  [26] "INGCOR"     "INGMON"     "TRABAJO"    "SUELDOS"    "HOREXT"    
##  [31] "COMIS"      "OTRA_REM"   "REM_ESP"    "REGA"       "NEGOCIO"   
##  [36] "NOAGROP"    "INDUSTRIA"  "COMERCIO"   "SERVICIOS"  "AGROPE"    
##  [41] "AGRICOLAS"  "PECUARIOS"  "REPRODUCC"  "PESCA"      "AUTOC"     
##  [46] "OTROS_TRAB" "RENTAS"     "UTILIDAD"   "ARRENDA"    "TRANSFER"  
##  [51] "JUBILA"     "BECA"       "DONATIVO"   "REMESA"     "BENE_GOB"  
##  [56] "ESP_HOG"    "ESP_INST"   "ESTI"       "OTROS"      "GASNOM"    
##  [61] "GASTOT"     "GASCOR"     "GASMON"     "ALIMENTOS"  "ALI_DENT"  
##  [66] "CEREALES"   "CARNES"     "PESCADO"    "LECHE"      "HUEVO"     
##  [71] "ACEITES"    "TUBERCULO"  "VERDURAS"   "FRUTAS"     "AZUCAR"    
##  [76] "CAFE"       "ESPECIAS"   "OTRO_ALI"   "BEBIDAS"    "FUERA_HOG" 
##  [81] "TABACO"     "VESTIDO_C"  "VESTIDO"    "CALZADO"    "VIVIENDA"  
##  [86] "ALQUILER"   "PRED_CONS"  "AGUA"       "ENERGIA"    "LIMPIEZA"  
##  [91] "CUIDADOS"   "UTENSILIOS" "ENSERES"    "SALUD"      "ATEN_PRI"  
##  [96] "HOSPITAL"   "MEDICA"     "TRANSPORTE" "PUBLICO"    "FORANEO"   
## [101] "ADQUI"      "MANTE"      "REFA"       "COMBUS"     "COMUNICA"  
## [106] "EDUCACION"  "EDUCA"      "ESPARCI"    "PAQUETE"    "PERSONAL"  
## [111] "CUIDADO"    "ACCESORIO"  "OTROS_GAS"  "TRANSFE"    "PERTOT"    
## [116] "PERMON"     "RETIRO"     "PRESTAMO"   "OTRAS_PR"   "EROTOT"    
## [121] "ERONOM"     "EROMON"     "CUOTA"      "MAT_SERV"   "MATERIAL"  
## [126] "SERVICIO"   "DEPOSITO"   "TERCEROS"   "PAGO_TAR"   "DEUDAS"    
## [131] "BALANCE"    "OTRA_ERO"   "SMG"        "EST_DIS"    "UPM"
datos <- datos %>%
  mutate(
    ubica_geo_str = str_pad(as.character(UBICA_GEO), 5, "left", pad = "0"),
    ent = as.numeric(str_sub(ubica_geo_str, 1, 2)),
    INGCOR = as.numeric(INGCOR),
    INGMON = as.numeric(INGMON),
    FACTOR = as.numeric(FACTOR)
  )

table(datos$ent)
## 
##    1    2    3    4    5    6    7    8    9   10   11   12   13   14   15   16 
##  305  438  270  385  520  387  908  801 2542  500 1732  790  434 2316 2480  642 
##   17   18   19   20   21   22   23   24   25   26   27   28   29   30   31   32 
##  477  343  382  991  660 2475  307  484  412 2512  478  545  365  795 2409  383
resultado_2008 <- datos %>%
  filter(ent %in% c(7, 28)) %>%
  group_by(ent) %>%
  summarise(
    ingreso_prom_ict = sum(INGCOR * FACTOR, na.rm = TRUE) / sum(FACTOR, na.rm = TRUE),
    ingreso_prom_mon = sum(INGMON * FACTOR, na.rm = TRUE) / sum(FACTOR, na.rm = TRUE)
  )

# Deflact
inpc_2008 <- 67.1270
inpc_2024 <- 136.013
factor_deflactor_2008 <- inpc_2024 / inpc_2008   

resultado_2008 <- resultado_2008 %>%
  mutate(
    ingreso_prom_ict_2024pesos = ingreso_prom_ict * factor_deflactor_2008,
    ingreso_prom_mon_2024pesos = ingreso_prom_mon * factor_deflactor_2008
  )

print(resultado_2008)
## # A tibble: 2 × 5
##     ent ingreso_prom_ict ingreso_prom_mon ingreso_prom_ict_2024pesos
##   <dbl>            <dbl>            <dbl>                      <dbl>
## 1     7           18697.           15125.                     37883.
## 2    28           35670.           29017.                     72274.
## # ℹ 1 more variable: ingreso_prom_mon_2024pesos <dbl>

2006

datos <- read.dbf("ENIGH2006.dbf", as.is = TRUE)
hogares <- read.dbf("factor2006.dbf", as.is = TRUE)  

str(datos$folio); str(hogares$folio)
##  chr [1:20875] "20060110010" "20060110020" "20060110030" "20060110050" ...
##  NULL
str(datos$hog);   str(hogares$hog)
##  num [1:20875] 861 861 861 861 1389 ...
##  NULL
# Uno  ingresos con la otra base que trae el factor de expansión
datos <- datos %>%
  left_join(hogares %>% select(FOLIO, FACTOR),  
            by = c("folio" = "FOLIO"))

datos <- datos %>%
  mutate(
    ubica_geo_str = str_pad(as.character(ubica_geo), 5, "left", pad = "0"),
    ent = as.numeric(str_sub(ubica_geo_str, 1, 2)),
    ingcor = as.numeric(ingcor),
    ingmon = as.numeric(ingmon),
    factor = as.numeric(FACTOR)
  )

table(datos$ent)
## 
##    1    2    3    4    5    6    7    8    9   10   11   12   13   14   15   16 
##  378  559  312  477  596  412  713  850 1135  556 1889  762  541  657 1161  592 
##   17   18   19   20   21   22   23   24   25   26   27   28   29   30   31   32 
##  515  335  487  784  618  418  427  521  506  682  458  635  359 1745  431  364
sum(is.na(datos$factor)) 
## [1] 0
# Filtrar y agrupar
resultado_2006 <- datos %>%
  filter(ent %in% c(7, 28)) %>%
  group_by(ent) %>%
  summarise(
    ingreso_prom_ict = sum(ingcor * factor, na.rm = TRUE) / sum(factor, na.rm = TRUE),
    ingreso_prom_mon = sum(ingmon * factor, na.rm = TRUE) / sum(factor, na.rm = TRUE)
  )

inpc_2006 <- 62.6920    
inpc_2024 <- 136.013
factor_deflactor_2006 <- inpc_2024 / inpc_2006

resultado_2006 <- resultado_2006 %>%
  mutate(
    ingreso_prom_ict_2024pesos = ingreso_prom_ict * factor_deflactor_2006,
    ingreso_prom_mon_2024pesos = ingreso_prom_mon * factor_deflactor_2006
  )

print(resultado_2006)
## # A tibble: 2 × 5
##     ent ingreso_prom_ict ingreso_prom_mon ingreso_prom_ict_2024pesos
##   <dbl>            <dbl>            <dbl>                      <dbl>
## 1     7           21825.           17198.                     47350.
## 2    28           34396.           28613.                     74624.
## # ℹ 1 more variable: ingreso_prom_mon_2024pesos <dbl>

2005

library(dplyr)
library(stringr)
library(foreign)
datos <- read.dbf("Enigh2005.dbf", as.is = TRUE)
hogares <- read.dbf("factor2005.dbf", as.is = TRUE)  

str(datos$folio); str(hogares$folio)
##  NULL
##  NULL
str(datos$hog);   str(hogares$hog)
##  NULL
##  NULL
datos <- datos %>%
  left_join(hogares %>% select(FOLIO, FACTOR),  
            by = c("FOLIO"))

# Crea la columna de entidad
datos <- datos %>%
  mutate(
    ubica_geo_str = str_pad(as.character(UBICA_GEO), 5, "left", pad = "0"),
    ent = as.numeric(str_sub(ubica_geo_str, 1, 2)),
    ingcor = as.numeric(INGCOR),
    ingmon = as.numeric(INGMON),
    factor = as.numeric(FACTOR)
  )

table(datos$ent)
## 
##    1    2    3    4    5    6    7    8    9   10   11   12   13   14   15   16 
##  384  550  400  544  554  389  650  776 1194  561  610  661  590  506 1226  537 
##   17   18   19   20   21   22   23   24   25   26   27   28   29   30   31   32 
##  472  401  525  686 1878  456  444  526  469 1836 1798  609  385 1757  455  345
sum(is.na(datos$factor)) 
## [1] 0
resultado_2006 <- datos %>%
  filter(ent %in% c(7, 28)) %>%
  group_by(ent) %>%
  summarise(
    ingreso_prom_ict = sum(ingcor * factor, na.rm = TRUE) / sum(factor, na.rm = TRUE),
    ingreso_prom_mon = sum(ingmon * factor, na.rm = TRUE) / sum(factor, na.rm = TRUE)
  )

inpc_2006 <- 62.6920    
inpc_2024 <- 136.013
factor_deflactor_2006 <- inpc_2024 / inpc_2006

resultado_2006 <- resultado_2006 %>%
  mutate(
    ingreso_prom_ict_2024pesos = ingreso_prom_ict * factor_deflactor_2006,
    ingreso_prom_mon_2024pesos = ingreso_prom_mon * factor_deflactor_2006
  )

print(resultado_2006)
## # A tibble: 2 × 5
##     ent ingreso_prom_ict ingreso_prom_mon ingreso_prom_ict_2024pesos
##   <dbl>            <dbl>            <dbl>                      <dbl>
## 1     7           19154.           15797.                     41556.
## 2    28           32464.           26525.                     70432.
## # ℹ 1 more variable: ingreso_prom_mon_2024pesos <dbl>

2004

library(dplyr)
library(stringr)
library(foreign)
datos <- read.dbf("enigh2004.dbf", as.is = TRUE)
hogares <- read.dbf("factor2004.dbf", as.is = TRUE)  


str(datos$folio); str(hogares$folio)
##  NULL
##  NULL
str(datos$hog);   str(hogares$hog)
##  NULL
##  NULL
datos <- datos %>%
  left_join(hogares %>% select(FOLIO, FACTOR),  
            by = c("FOLIO"))

datos <- datos %>%
  mutate(
    ubica_geo_str = str_pad(as.character(UBICA_GEO), 5, "left", pad = "0"),
    ent = as.numeric(str_sub(ubica_geo_str, 1, 2)),
    ingcor = as.numeric(INGCOR),
    ingmon = as.numeric(INGMON),
    factor = as.numeric(FACTOR)
  )

table(datos$ent)
## 
##    1    2    3    4    5    6    7    8    9   10   11   12   13   14   15   16 
##  383  555  380  527  558  389  673  743 2964  554  636  667  569  499 1214  540 
##   17   18   19   20   21   22   23   24   25   26   27   28   29   30   31   32 
##  480  387 3055  694  587  465  435  557  458  519  460  593  404  811  494  345
sum(is.na(datos$factor)) 
## [1] 0
resultado_2006 <- datos %>%
  filter(ent %in% c(7, 28)) %>%
  group_by(ent) %>%
  summarise(
    ingreso_prom_ict = sum(ingcor * factor, na.rm = TRUE) / sum(factor, na.rm = TRUE),
    ingreso_prom_mon = sum(ingmon * factor, na.rm = TRUE) / sum(factor, na.rm = TRUE)
  )

inpc_2006 <- 56.8280    
inpc_2024 <- 136.013
factor_deflactor_2006 <- inpc_2024 / inpc_2006

resultado_2006 <- resultado_2006 %>%
  mutate(
    ingreso_prom_ict_2024pesos = ingreso_prom_ict * factor_deflactor_2006,
    ingreso_prom_mon_2024pesos = ingreso_prom_mon * factor_deflactor_2006
  )

print(resultado_2006)
## # A tibble: 2 × 5
##     ent ingreso_prom_ict ingreso_prom_mon ingreso_prom_ict_2024pesos
##   <dbl>            <dbl>            <dbl>                      <dbl>
## 1     7           14765.           11985.                     35339.
## 2    28           29057.           24326.                     69546.
## # ℹ 1 more variable: ingreso_prom_mon_2024pesos <dbl>

Porcentaje de la población que usa computadora y su uso destinado

library(foreign)
library(dplyr)

usu25 <- read.dbf(
  "~/Downloads/endutih2025_bd_dbf/ti25usu.dbf",
  as.is = TRUE
)
#usuarios2025 <- read.dbf("ti25usu.dbf", as.is = TRUE)  

uso_computadora <- usu25 %>%
  filter(CVE_ENT %in% c("07", "28")) %>%
  mutate(
    entidad = case_when(
      CVE_ENT == "07" ~ "Chiapas",
      CVE_ENT == "28" ~ "Tamaulipas"
    ),
    FAC_PER = as.numeric(FAC_PER),
    usa_computadora = if_else(P6_1 == "1", 1, 0)
  ) %>%
  filter(P6_1 %in% c("1", "2")) %>%
  group_by(entidad) %>%
  summarise(
    porcentaje_usa_computadora = sum(usa_computadora * FAC_PER, na.rm = TRUE) /
      sum(FAC_PER, na.rm = TRUE) * 100,
    .groups = "drop"
  ) %>%
  mutate(
    porcentaje_usa_computadora = round(porcentaje_usa_computadora, 2)
  )

print(uso_computadora)
## # A tibble: 2 × 2
##   entidad    porcentaje_usa_computadora
##   <chr>                           <dbl>
## 1 Chiapas                          22.7
## 2 Tamaulipas                       42.6
usu25 <- read.dbf("~/Downloads/endutih2025_bd_dbf/ti25usu.dbf", as.is = TRUE)

str(usu25$CVE_ENT)
##  chr [1:57810] "01" "01" "01" "01" "01" "01" "01" "01" "01" "01" "01" "01" ...
str(usu25$FAC_PER)
##  int [1:57810] 483 491 493 474 481 694 724 219 235 690 ...
names(usu25) <- toupper(names(usu25))

usu25 <- usu25 %>%
  mutate(
    ent = as.numeric(CVE_ENT),
    factor = as.numeric(FAC_PER),
    
    uso_laboral = as.character(P6_8_1),
    uso_escolar = as.character(P6_8_2),
    uso_capacitacion = as.character(P6_8_3),
    uso_entretenimiento = as.character(P6_8_4),
    uso_internet = as.character(P6_8_5),
    uso_otro = as.character(P6_8_6)
  )

#Variables para el uso de computadora
vars_computadora <- c(
  uso_laboral = "Actividades laborales",
  uso_escolar = "Labores escolares",
  uso_capacitacion = "Capacitación independiente",
  uso_entretenimiento = "Entretenimiento",
  uso_internet = "Acceso a internet",
  uso_otro = "Otro uso"
)

#Porcentaje para chiaps y tamaulipas
usos_computadora25 <- usu25 %>%
  filter(ent %in% c(7, 28)) %>%
  mutate(
    entidad = case_when(
      ent == 7 ~ "Chiapas",
      ent == 28 ~ "Tamaulipas"
    )
  ) %>%
  select(entidad, factor, all_of(names(vars_computadora))) %>%
  pivot_longer(
    cols = all_of(names(vars_computadora)),
    names_to = "variable",
    values_to = "respuesta"
  ) %>%
  mutate(
    uso = vars_computadora[variable],
    respuesta = as.character(respuesta)
  ) %>%
  filter(respuesta %in% c("1", "2")) %>%
  group_by(entidad, uso) %>%
  summarise(
    porcentaje = sum((respuesta == "1") * factor, na.rm = TRUE) /
      sum(factor, na.rm = TRUE) * 100,
    .groups = "drop"
  ) %>%
  mutate(
    porcentaje = round(porcentaje, 2)
  ) %>%
  arrange(entidad, uso)

print(usos_computadora25, n = Inf)
## # A tibble: 12 × 3
##    entidad    uso                        porcentaje
##    <chr>      <chr>                           <dbl>
##  1 Chiapas    Acceso a internet               65.4 
##  2 Chiapas    Actividades laborales           59.0 
##  3 Chiapas    Capacitación independiente      20.6 
##  4 Chiapas    Entretenimiento                 47.4 
##  5 Chiapas    Labores escolares               49.4 
##  6 Chiapas    Otro uso                         0.24
##  7 Tamaulipas Acceso a internet               74.1 
##  8 Tamaulipas Actividades laborales           62.7 
##  9 Tamaulipas Capacitación independiente      21.2 
## 10 Tamaulipas Entretenimiento                 61.2 
## 11 Tamaulipas Labores escolares               38.9 
## 12 Tamaulipas Otro uso                         0