library(tidyverse)
library(readr)
library(ggplot2)
library(dplyr)
library(stargazer)
data <- read_rds("~/R studio/Clase de ciencia de datos M Rob/Actividad de ENOE/full_data_h.rds")
datos_finales <- data %>%
filter(
cd_a %in% c(1, 2, 3),
hrsocup >= 1,
hrsocup <= 144
) %>%
# 2. Eliminar observaciones con datos faltantes en tus variables
filter(
if_all(
c("ln_ing_x_hrs", "exp", "eda", "cs_p13_1", "emp_ppal",
"anio_enc", "hrsocup", "exp2", "anios_esc", "ingocup", "nivel_educ_2"),
~ !is.na(.x)
)
) %>%
# 3. Dummies y factores
mutate(
# Pasamos primero a texto explícito "Informalidad" / "Formalidad"
informalidad_txt = if_else(emp_ppal == 1, "Informalidad", "Formalidad"),
inform = factor(
informalidad_txt,
levels = c("Formalidad", "Informalidad")
),
ciudad = relevel(factor(cd_a, levels = c(1, 2, 3), labels = c("CDMX", "Guadalajara", "Monterrey")), ref = "Monterrey"),
anio = relevel(factor(anio_enc), ref = "2005")
) %>%
# 4. Seleccionar solo las variables de interés
select(
ln_ing_x_hrs, exp, eda, cs_p13_1, emp_ppal, inform,
anio_enc, anio, hrsocup, exp2, anios_esc, ingocup,
nivel_educ_2, cd_a, ciudad
)
# Confirmar el nuevo tamaño de muestra por nivel educativo
datos_finales %>% count(nivel_educ_2)
## # A tibble: 5 × 2
## nivel_educ_2 n
## <fct> <int>
## 1 Secundaria o menos 220639
## 2 Preparatoria 84074
## 3 Normal_tecnica 20102
## 4 Profesional 67539
## 5 Maestria_Doctorado 6123
# El mismo diagnóstico de celdas vacías que antes
tabla_anio_nivel <- datos_finales %>%
count(nivel_educ_2, anio_enc) %>%
pivot_wider(names_from = anio_enc, values_from = n, values_fill = 0)
tabla_anio_nivel %>%
rowwise() %>%
mutate(anios_vacios = sum(c_across(-nivel_educ_2) == 0)) %>%
select(nivel_educ_2, anios_vacios)
## # A tibble: 5 × 2
## # Rowwise:
## nivel_educ_2 anios_vacios
## <fct> <int>
## 1 Secundaria o menos 0
## 2 Preparatoria 0
## 3 Normal_tecnica 0
## 4 Profesional 0
## 5 Maestria_Doctorado 0
Recordamos que se observa solo el nivel, el nivel 1 es la variable 0.
levels(datos_finales$inform)
## [1] "Formalidad" "Informalidad"
levels(datos_finales$ciudad)
## [1] "Monterrey" "CDMX" "Guadalajara"
levels(datos_finales$anio)
## [1] "2005" "2006" "2007" "2008" "2009" "2010" "2011" "2012" "2013" "2014"
## [11] "2015" "2016" "2017" "2018" "2019" "2020" "2021" "2022" "2023" "2024"
## [21] "2025"
datos_finales <- datos_finales %>%
filter(anios_esc != 99, exp >= 0)
vars_continuas <- c("ln_ing_x_hrs", "exp", "eda", "cs_p13_1", "emp_ppal","anio_enc", "hrsocup", "exp2", "anios_esc", "ingocup")
datos_long <- datos_finales %>%
select(cd_a, all_of(vars_continuas)) %>%
pivot_longer(cols = all_of(vars_continuas), names_to = "variable", values_to = "valor")
datos_long <- datos_long %>%
mutate(ciudad = case_when(
cd_a == 1 ~ "Ciudad de Mexico",
cd_a == 2 ~ "Guadalajara",
cd_a == 3 ~ "Monterrey",
TRUE ~ NA_character_
))
ggplot(datos_long, aes(x = valor, color = ciudad, fill = ciudad)) +
geom_density(alpha = 0.2) +
facet_wrap(~ variable, scales = "free") +
labs(color = "Ciudad", fill = "Ciudad")
## 5.Variables Numéricas
vars_numericas <- datos_finales %>%
select(where(is.numeric), -c(emp_ppal, cd_a, anio_enc)) %>%
colnames()
vars_numericas
## [1] "ln_ing_x_hrs" "exp" "eda" "cs_p13_1" "hrsocup"
## [6] "exp2" "anios_esc" "ingocup"
resumen_numerico <- datos_finales %>%
select(all_of(vars_numericas)) %>%
pivot_longer(everything(), names_to = "variable", values_to = "valor") %>%
group_by(variable) %>%
summarise(
n = sum(!is.na(valor)),
n_na = sum(is.na(valor)),
media = mean(valor, na.rm = TRUE),
de = sd(valor, na.rm = TRUE),
min = min(valor, na.rm = TRUE),
mediana = median(valor, na.rm = TRUE),
max = max(valor, na.rm = TRUE)
) %>%
arrange(variable)
resumen_numerico
## # A tibble: 8 × 8
## variable n n_na media de min mediana max
## <chr> <int> <int> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 anios_esc 397787 0 10.0 3.95 0 9 24
## 2 cs_p13_1 397787 0 3.86 1.84 0 3 9
## 3 eda 397787 0 39.2 13.8 15 38 98
## 4 exp 397787 0 23.2 14.8 0 21 92
## 5 exp2 397787 0 758. 875. 0 441 8464
## 6 hrsocup 397787 0 47.5 14.8 1 48 144
## 7 ingocup 397787 0 10406. 10716. 18.2 7995. 1034787.
## 8 ln_ing_x_hrs 397787 0 3.76 0.685 -1.76 3.69 9.21
resumen_numerico %>%
filter(variable %in% vars_numericas) %>%
ggplot(aes(x = variable, y = media)) +
geom_col(fill = "#ADD8E6") +
geom_errorbar(aes(ymin = media - de, ymax = media + de), width = 0.3) +
facet_wrap(~variable, scales = "free", ncol = 3) +
labs(title = "Media ± desviación estándar por variable clave", x = NULL, y = NULL) +
theme(axis.text.x = element_blank(), axis.ticks.x = element_blank())
#vars_clave <- c("eda", "anios_esc", "hrsocup", "exp", "ingocup", "ing_x_hrs")
datos_finales %>%
select(all_of(vars_numericas)) %>%
pivot_longer(everything(), names_to = "variable", values_to = "valor") %>%
ggplot(aes(valor)) +
geom_histogram(bins = 40, fill = "#154360", color = "white") +
facet_wrap(~variable, scales = "free") +
labs(x = NULL, y = "Frecuencia", title = "Distribución de variables numéricas clave")
vars_categoricas <- c("nivel_educ_2", "inform")
for (v in vars_categoricas) {
cat("\n---", v, "---\n")
print(datos_finales %>% count(.data[[v]], sort = TRUE) %>% mutate(pct = round(100 * n / sum(n), 1)))
}
##
## --- nivel_educ_2 ---
## # A tibble: 5 × 3
## nivel_educ_2 n pct
## <fct> <int> <dbl>
## 1 Secundaria o menos 220561 55.4
## 2 Preparatoria 83946 21.1
## 3 Profesional 67158 16.9
## 4 Normal_tecnica 20012 5
## 5 Maestria_Doctorado 6110 1.5
##
## --- inform ---
## # A tibble: 2 × 3
## inform n pct
## <fct> <int> <dbl>
## 1 Formalidad 217894 54.8
## 2 Informalidad 179893 45.2
datos_finales %>%
select(all_of(vars_categoricas)) %>%
mutate(across(everything(), as.character)) %>%
pivot_longer(everything(), names_to = "variable", values_to = "categoria") %>%
ggplot(aes(categoria)) +
geom_bar(fill = "#154360") +
facet_wrap(~variable, scales = "free") +
labs(x = NULL, y = "Frecuencia", title = "Frecuencias de variables categóricas") +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
## 7. Gráficos Exploratorios
# Quitar los outliers
datos_finales %>%
filter(ingocup < quantile(ingocup, 0.99, na.rm = TRUE)) %>%
ggplot(aes(nivel_educ_2, ingocup, fill = nivel_educ_2)) +
geom_boxplot(outlier.shape = NA) +
coord_cartesian(ylim = c(0, 40000)) +
labs(title = "Ingreso por nivel educativo", x = NULL, y = "Ingreso de ocupación") +
theme(axis.text.x = element_text(angle = 30, hjust = 1), legend.position = "none")+
scale_fill_brewer(palette = "Blues")
vars_cor <- c("eda", "anios_esc", "exp", "hrsocup", "ingocup", "ln_ing_x_hrs")
mat_cor <- datos_finales %>%
select(all_of(vars_cor)) %>%
cor(use = "pairwise.complete.obs")
mat_cor
## eda anios_esc exp hrsocup ingocup
## eda 1.00000000 -0.13392088 0.96452874 -0.06343715 0.05984766
## anios_esc -0.13392088 1.00000000 -0.39077051 -0.05677729 0.34650210
## exp 0.96452874 -0.39077051 1.00000000 -0.04379974 -0.03671051
## hrsocup -0.06343715 -0.05677729 -0.04379974 1.00000000 0.05419240
## ingocup 0.05984766 0.34650210 -0.03671051 0.05419240 1.00000000
## ln_ing_x_hrs 0.07223592 0.40195250 -0.03997434 -0.39051185 0.67681883
## ln_ing_x_hrs
## eda 0.07223592
## anios_esc 0.40195250
## exp -0.03997434
## hrsocup -0.39051185
## ingocup 0.67681883
## ln_ing_x_hrs 1.00000000
mat_cor %>%
as.data.frame() %>%
rownames_to_column("var1") %>%
pivot_longer(-var1, names_to = "var2", values_to = "correlacion") %>%
ggplot(aes(var1, var2, fill = correlacion)) +
geom_tile() +
geom_text(aes(label = round(correlacion, 2)), size = 3) +
scale_fill_gradient2(low = "steelblue", mid = "white", high = "firebrick", midpoint = 0) +
labs(title = "Matriz de correlación", x = NULL, y = NULL) +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
medias_escolaridad <- datos_finales %>%
filter(!is.na(ingocup), ingocup > 0, !is.na(anios_esc)) %>%
group_by(anios_esc) %>%
summarise(ingreso_medio = mean(ingocup, na.rm = TRUE))
medias_escolaridad %>% filter(anios_esc<99) %>%
ggplot(aes(x = anios_esc, y = ingreso_medio)) +
geom_col(fill = "skyblue") +
labs(
title = "Ingreso promedio por años de escolaridad (ENOE)",
x = "Años de escolaridad",
y = "Ingreso promedio"
) +
theme_minimal()
data <- datos_finales %>%
filter(hrsocup > 0, hrsocup <= 84) %>%
mutate(rango_horas = cut(hrsocup,
breaks = c(0, 20, 34, 40, 48, 84),
labels = c("1-20", "21-34", "35-40", "41-48", "49+"),
include.lowest = TRUE))
ggplot(data, aes(x = rango_horas, y = ln_ing_x_hrs, fill = rango_horas)) +
geom_boxplot() +
scale_fill_brewer(palette = "Blues") +
theme(legend.position = "none") +
labs(x = "Rango de horas trabajadas", y = "ln_ing_x_hrs")
datos_finales %>%
filter(eda >= 15, eda <= 70) %>%
ggplot(aes(eda, hrsocup, colour = inform)) +
stat_summary() +
scale_colour_manual(values = c("#85C1E9", "#154360")) +
labs(
x = "edad",
y = "horas ocupadas",
title = "Horas ocupadas por edad e informalidad"
)
datos_finales %>%
filter(ln_ing_x_hrs < quantile(ln_ing_x_hrs, 0.99, na.rm = TRUE)) %>%
ggplot(aes(nivel_educ_2, ln_ing_x_hrs, colour = inform)) +
geom_boxplot() +
scale_colour_manual(values = c("#85C1E9", "#154360")) +
labs(x = "nivel educativo", y = "LN (Ingreso por hora)")
modelos_por_nivel <- datos_finales %>%
group_by(nivel_educ_2) %>% # crea subgrupos por nivel educativo
group_map(~ lm(
ln_ing_x_hrs ~ inform + exp + exp2 + ciudad + anio + hrsocup,
data = .x
)) # corre una regresión por subgrupo
# Nombrar cada modelo según su nivel educativo real
# (más seguro que levels(as.factor(...)) porque usa el mismo agrupamiento)
niveles_orden <- group_keys(datos_finales %>% group_by(nivel_educ_2))$nivel_educ_2
names(modelos_por_nivel) <- niveles_orden
niveles_orden # imprime el orden real -> confirma que coincide con tu lista:
## [1] Secundaria o menos Preparatoria Normal_tecnica Profesional
## [5] Maestria_Doctorado
## 5 Levels: Secundaria o menos Preparatoria Normal_tecnica ... Maestria_Doctorado
#1- secundaria o menos
#2- preparatoria
#3- normal técnica
#4- profesional
#5- posgrados
# Revisar cada modelo individualmente
summary(modelos_por_nivel[[1]])
##
## Call:
## lm(formula = ln_ing_x_hrs ~ inform + exp + exp2 + ciudad + anio +
## hrsocup, data = .x)
##
## Residuals:
## Min 1Q Median 3Q Max
## -4.7545 -0.2641 -0.0150 0.2571 4.7943
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 4.329e+00 5.998e-03 721.735 < 2e-16 ***
## informInformalidad -9.741e-02 2.168e-03 -44.933 < 2e-16 ***
## exp 2.301e-02 2.241e-04 102.687 < 2e-16 ***
## exp2 -3.748e-04 3.503e-06 -106.976 < 2e-16 ***
## ciudadCDMX -2.257e-01 2.551e-03 -88.467 < 2e-16 ***
## ciudadGuadalajara -6.340e-02 2.675e-03 -23.704 < 2e-16 ***
## anio2006 8.711e-03 5.235e-03 1.664 0.0961 .
## anio2007 -4.516e-03 5.265e-03 -0.858 0.3911
## anio2008 -2.720e-02 5.348e-03 -5.086 3.67e-07 ***
## anio2009 -7.795e-02 5.520e-03 -14.119 < 2e-16 ***
## anio2010 -1.180e-01 5.541e-03 -21.297 < 2e-16 ***
## anio2011 -1.599e-01 6.964e-03 -22.958 < 2e-16 ***
## anio2012 -1.585e-01 6.235e-03 -25.418 < 2e-16 ***
## anio2013 -1.471e-01 5.835e-03 -25.205 < 2e-16 ***
## anio2014 -1.750e-01 5.851e-03 -29.910 < 2e-16 ***
## anio2015 -1.682e-01 5.919e-03 -28.424 < 2e-16 ***
## anio2016 -1.767e-01 6.053e-03 -29.185 < 2e-16 ***
## anio2017 -1.840e-01 6.224e-03 -29.560 < 2e-16 ***
## anio2018 -1.872e-01 6.261e-03 -29.892 < 2e-16 ***
## anio2019 -1.818e-01 6.493e-03 -27.992 < 2e-16 ***
## anio2020 -2.117e-01 7.228e-03 -29.286 < 2e-16 ***
## anio2021 -1.873e-01 6.475e-03 -28.934 < 2e-16 ***
## anio2022 -1.664e-01 6.821e-03 -24.395 < 2e-16 ***
## anio2023 -1.097e-01 6.618e-03 -16.577 < 2e-16 ***
## anio2024 -5.465e-02 6.896e-03 -7.925 2.30e-15 ***
## anio2025 -5.738e-02 1.000e-02 -5.735 9.75e-09 ***
## hrsocup -1.535e-02 6.962e-05 -220.520 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.4857 on 220534 degrees of freedom
## Multiple R-squared: 0.2583, Adjusted R-squared: 0.2582
## F-statistic: 2954 on 26 and 220534 DF, p-value: < 2.2e-16
summary(modelos_por_nivel[[2]])
##
## Call:
## lm(formula = ln_ing_x_hrs ~ inform + exp + exp2 + ciudad + anio +
## hrsocup, data = .x)
##
## Residuals:
## Min 1Q Median 3Q Max
## -4.3594 -0.2989 -0.0383 0.2608 3.8654
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 4.601e+00 1.066e-02 431.729 < 2e-16 ***
## informInformalidad -1.365e-01 3.705e-03 -36.839 < 2e-16 ***
## exp 2.928e-02 4.482e-04 65.329 < 2e-16 ***
## exp2 -4.853e-04 9.744e-06 -49.800 < 2e-16 ***
## ciudadCDMX -2.140e-01 4.282e-03 -49.976 < 2e-16 ***
## ciudadGuadalajara -7.798e-02 4.829e-03 -16.148 < 2e-16 ***
## anio2006 -1.222e-02 1.044e-02 -1.171 0.242
## anio2007 -1.193e-02 1.036e-02 -1.151 0.250
## anio2008 -4.779e-02 1.046e-02 -4.570 4.87e-06 ***
## anio2009 -9.978e-02 1.062e-02 -9.394 < 2e-16 ***
## anio2010 -1.458e-01 1.044e-02 -13.959 < 2e-16 ***
## anio2011 -1.785e-01 1.262e-02 -14.147 < 2e-16 ***
## anio2012 -2.002e-01 1.134e-02 -17.661 < 2e-16 ***
## anio2013 -1.833e-01 1.069e-02 -17.146 < 2e-16 ***
## anio2014 -2.320e-01 1.078e-02 -21.521 < 2e-16 ***
## anio2015 -2.279e-01 1.085e-02 -21.008 < 2e-16 ***
## anio2016 -2.331e-01 1.072e-02 -21.754 < 2e-16 ***
## anio2017 -2.616e-01 1.084e-02 -24.131 < 2e-16 ***
## anio2018 -2.545e-01 1.087e-02 -23.408 < 2e-16 ***
## anio2019 -2.625e-01 1.108e-02 -23.697 < 2e-16 ***
## anio2020 -3.005e-01 1.205e-02 -24.945 < 2e-16 ***
## anio2021 -2.925e-01 1.091e-02 -26.805 < 2e-16 ***
## anio2022 -2.566e-01 1.097e-02 -23.391 < 2e-16 ***
## anio2023 -1.876e-01 1.075e-02 -17.454 < 2e-16 ***
## anio2024 -1.458e-01 1.085e-02 -13.435 < 2e-16 ***
## anio2025 -1.103e-01 1.479e-02 -7.460 8.76e-14 ***
## hrsocup -1.759e-02 1.243e-04 -141.546 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.5095 on 83919 degrees of freedom
## Multiple R-squared: 0.2791, Adjusted R-squared: 0.2789
## F-statistic: 1250 on 26 and 83919 DF, p-value: < 2.2e-16
summary(modelos_por_nivel[[3]])
##
## Call:
## lm(formula = ln_ing_x_hrs ~ inform + exp + exp2 + ciudad + anio +
## hrsocup, data = .x)
##
## Residuals:
## Min 1Q Median 3Q Max
## -5.7471 -0.3115 -0.0289 0.2878 3.8092
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 4.716e+00 1.994e-02 236.517 < 2e-16 ***
## informInformalidad -1.957e-01 8.247e-03 -23.729 < 2e-16 ***
## exp 2.738e-02 9.468e-04 28.923 < 2e-16 ***
## exp2 -4.693e-04 1.839e-05 -25.516 < 2e-16 ***
## ciudadCDMX -1.648e-01 8.524e-03 -19.337 < 2e-16 ***
## ciudadGuadalajara -2.017e-02 1.006e-02 -2.004 0.0450 *
## anio2006 -2.649e-02 1.727e-02 -1.534 0.1251
## anio2007 7.461e-04 1.755e-02 0.043 0.9661
## anio2008 -4.202e-02 1.770e-02 -2.374 0.0176 *
## anio2009 -1.140e-01 1.818e-02 -6.268 3.73e-10 ***
## anio2010 -1.433e-01 1.814e-02 -7.898 2.98e-15 ***
## anio2011 -1.458e-01 2.472e-02 -5.898 3.75e-09 ***
## anio2012 -1.566e-01 2.233e-02 -7.012 2.43e-12 ***
## anio2013 -1.873e-01 2.003e-02 -9.354 < 2e-16 ***
## anio2014 -2.613e-01 2.039e-02 -12.814 < 2e-16 ***
## anio2015 -1.867e-01 2.045e-02 -9.129 < 2e-16 ***
## anio2016 -2.208e-01 2.114e-02 -10.442 < 2e-16 ***
## anio2017 -2.354e-01 2.210e-02 -10.650 < 2e-16 ***
## anio2018 -2.401e-01 2.266e-02 -10.597 < 2e-16 ***
## anio2019 -2.755e-01 2.555e-02 -10.782 < 2e-16 ***
## anio2020 -2.686e-01 2.758e-02 -9.739 < 2e-16 ***
## anio2021 -2.022e-01 2.380e-02 -8.496 < 2e-16 ***
## anio2022 -1.727e-01 2.514e-02 -6.870 6.60e-12 ***
## anio2023 -1.836e-01 2.514e-02 -7.303 2.93e-13 ***
## anio2024 -1.278e-01 2.492e-02 -5.128 2.95e-07 ***
## anio2025 -1.642e-01 3.923e-02 -4.187 2.84e-05 ***
## hrsocup -1.960e-02 2.611e-04 -75.060 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.5213 on 19985 degrees of freedom
## Multiple R-squared: 0.2852, Adjusted R-squared: 0.2843
## F-statistic: 306.7 on 26 and 19985 DF, p-value: < 2.2e-16
summary(modelos_por_nivel[[4]])
##
## Call:
## lm(formula = ln_ing_x_hrs ~ inform + exp + exp2 + ciudad + anio +
## hrsocup, data = .x)
##
## Residuals:
## Min 1Q Median 3Q Max
## -5.0520 -0.4217 -0.0418 0.3938 4.2731
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 5.443e+00 1.430e-02 380.693 < 2e-16 ***
## informInformalidad -3.799e-01 5.948e-03 -63.863 < 2e-16 ***
## exp 2.404e-02 6.519e-04 36.878 < 2e-16 ***
## exp2 -4.242e-04 1.415e-05 -29.971 < 2e-16 ***
## ciudadCDMX -1.832e-01 6.015e-03 -30.463 < 2e-16 ***
## ciudadGuadalajara -1.509e-01 6.552e-03 -23.033 < 2e-16 ***
## anio2006 -3.607e-03 1.328e-02 -0.272 0.785925
## anio2007 -8.905e-03 1.346e-02 -0.661 0.508393
## anio2008 -4.483e-02 1.361e-02 -3.295 0.000984 ***
## anio2009 -1.280e-01 1.424e-02 -8.989 < 2e-16 ***
## anio2010 -1.705e-01 1.419e-02 -12.014 < 2e-16 ***
## anio2011 -2.692e-01 1.938e-02 -13.891 < 2e-16 ***
## anio2012 -2.618e-01 1.623e-02 -16.136 < 2e-16 ***
## anio2013 -2.701e-01 1.503e-02 -17.974 < 2e-16 ***
## anio2014 -2.837e-01 1.529e-02 -18.560 < 2e-16 ***
## anio2015 -2.706e-01 1.505e-02 -17.972 < 2e-16 ***
## anio2016 -3.055e-01 1.503e-02 -20.324 < 2e-16 ***
## anio2017 -3.706e-01 1.536e-02 -24.133 < 2e-16 ***
## anio2018 -3.513e-01 1.576e-02 -22.287 < 2e-16 ***
## anio2019 -3.609e-01 1.559e-02 -23.157 < 2e-16 ***
## anio2020 -3.312e-01 1.652e-02 -20.052 < 2e-16 ***
## anio2021 -3.382e-01 1.479e-02 -22.871 < 2e-16 ***
## anio2022 -3.936e-01 1.491e-02 -26.400 < 2e-16 ***
## anio2023 -3.086e-01 1.451e-02 -21.266 < 2e-16 ***
## anio2024 -2.669e-01 1.457e-02 -18.311 < 2e-16 ***
## anio2025 -2.624e-01 2.056e-02 -12.766 < 2e-16 ***
## hrsocup -2.119e-02 1.846e-04 -114.800 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.6507 on 67131 degrees of freedom
## Multiple R-squared: 0.2427, Adjusted R-squared: 0.2424
## F-statistic: 827.5 on 26 and 67131 DF, p-value: < 2.2e-16
summary(modelos_por_nivel[[5]])
##
## Call:
## lm(formula = ln_ing_x_hrs ~ inform + exp + exp2 + ciudad + anio +
## hrsocup, data = .x)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.2493 -0.4294 -0.0131 0.4198 3.3925
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 5.828e+00 5.329e-02 109.369 < 2e-16 ***
## informInformalidad -2.669e-01 2.760e-02 -9.670 < 2e-16 ***
## exp 1.269e-02 2.823e-03 4.495 7.10e-06 ***
## exp2 -1.464e-04 5.819e-05 -2.516 0.01188 *
## ciudadCDMX -1.507e-01 2.143e-02 -7.034 2.23e-12 ***
## ciudadGuadalajara -2.723e-01 2.401e-02 -11.342 < 2e-16 ***
## anio2006 2.451e-02 4.630e-02 0.529 0.59658
## anio2007 4.514e-02 4.673e-02 0.966 0.33416
## anio2008 -8.974e-02 4.725e-02 -1.899 0.05759 .
## anio2009 -1.277e-01 4.945e-02 -2.583 0.00983 **
## anio2010 -2.302e-01 5.072e-02 -4.538 5.78e-06 ***
## anio2011 -2.853e-01 6.888e-02 -4.142 3.49e-05 ***
## anio2012 -3.015e-01 5.742e-02 -5.251 1.57e-07 ***
## anio2013 -2.658e-01 5.290e-02 -5.025 5.19e-07 ***
## anio2014 -3.888e-01 5.489e-02 -7.083 1.57e-12 ***
## anio2015 -3.283e-01 5.586e-02 -5.877 4.40e-09 ***
## anio2016 -3.586e-01 5.664e-02 -6.332 2.59e-10 ***
## anio2017 -3.903e-01 5.554e-02 -7.027 2.34e-12 ***
## anio2018 -4.237e-01 5.867e-02 -7.222 5.76e-13 ***
## anio2019 -4.432e-01 5.583e-02 -7.939 2.40e-15 ***
## anio2020 -4.348e-01 5.314e-02 -8.182 3.37e-16 ***
## anio2021 -4.661e-01 5.042e-02 -9.246 < 2e-16 ***
## anio2022 -5.717e-01 5.460e-02 -10.470 < 2e-16 ***
## anio2023 -4.130e-01 5.153e-02 -8.015 1.31e-15 ***
## anio2024 -3.782e-01 4.927e-02 -7.675 1.91e-14 ***
## anio2025 -4.145e-01 6.592e-02 -6.288 3.44e-10 ***
## hrsocup -1.484e-02 6.574e-04 -22.572 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.6868 on 6083 degrees of freedom
## Multiple R-squared: 0.1686, Adjusted R-squared: 0.1651
## F-statistic: 47.45 on 26 and 6083 DF, p-value: < 2.2e-16
# Chequeo rápido: ¿algún modelo perdió coeficientes por colinealidad?
sapply(modelos_por_nivel, function(m) length(coef(m)))
## Secundaria o menos Preparatoria Normal_tecnica Profesional
## 27 27 27 27
## Maestria_Doctorado
## 27
length(coef(modelos_por_nivel[[5]])) # o el índice que corresponda a Maestría/Doc
## [1] 27
length(coef(modelos_por_nivel[[1]])) # compara contra un modelo con muestra grande
## [1] 27
niveles_anio <- levels(datos_finales$anio) # incluye la base en la posición 1
anio_base <- niveles_anio[1]
anios_dummy <- niveles_anio[-1] # todos menos el año base
stargazer(
modelos_por_nivel,
type = "text",
title = "Regresiones Mincerianas Salariales con Efectos Fijos Explícitos",
column.labels = c("Secundaria/Menos", "Preparatoria", "Normal/Técnica",
"Profesional", "Maestría/Doc"),
dep.var.labels = "Logaritmo del Ingreso por Hora",
covariate.labels = c(
"Informalidad (1 = Sí)",
"Experiencia laboral",
"Experiencia²",
"CDMX (Base: Monterrey)",
"Guadalajara (Base: Monterrey)",
paste0("Año ", anios_dummy, " (Base: ", anio_base, ")"),
"Horas trabajadas a la semana"
),
digits = 3,
star.cutoffs = c(0.05, 0.01, 0.001)
)
##
## Regresiones Mincerianas Salariales con Efectos Fijos Explícitos
## ============================================================================================================================================================================
## Dependent variable:
## ----------------------------------------------------------------------------------------------------------------------------------------------
## Logaritmo del Ingreso por Hora
## Secundaria/Menos Preparatoria Normal/Técnica Profesional Maestría/Doc
## (1) (2) (3) (4) (5)
## ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
## Informalidad (1 = Sí) -0.097*** -0.136*** -0.196*** -0.380*** -0.267***
## (0.002) (0.004) (0.008) (0.006) (0.028)
##
## Experiencia laboral 0.023*** 0.029*** 0.027*** 0.024*** 0.013***
## (0.0002) (0.0004) (0.001) (0.001) (0.003)
##
## Experiencia² -0.0004*** -0.0005*** -0.0005*** -0.0004*** -0.0001*
## (0.00000) (0.00001) (0.00002) (0.00001) (0.0001)
##
## CDMX (Base: Monterrey) -0.226*** -0.214*** -0.165*** -0.183*** -0.151***
## (0.003) (0.004) (0.009) (0.006) (0.021)
##
## Guadalajara (Base: Monterrey) -0.063*** -0.078*** -0.020* -0.151*** -0.272***
## (0.003) (0.005) (0.010) (0.007) (0.024)
##
## Año 2006 (Base: 2005) 0.009 -0.012 -0.026 -0.004 0.025
## (0.005) (0.010) (0.017) (0.013) (0.046)
##
## Año 2007 (Base: 2005) -0.005 -0.012 0.001 -0.009 0.045
## (0.005) (0.010) (0.018) (0.013) (0.047)
##
## Año 2008 (Base: 2005) -0.027*** -0.048*** -0.042* -0.045*** -0.090
## (0.005) (0.010) (0.018) (0.014) (0.047)
##
## Año 2009 (Base: 2005) -0.078*** -0.100*** -0.114*** -0.128*** -0.128**
## (0.006) (0.011) (0.018) (0.014) (0.049)
##
## Año 2010 (Base: 2005) -0.118*** -0.146*** -0.143*** -0.170*** -0.230***
## (0.006) (0.010) (0.018) (0.014) (0.051)
##
## Año 2011 (Base: 2005) -0.160*** -0.178*** -0.146*** -0.269*** -0.285***
## (0.007) (0.013) (0.025) (0.019) (0.069)
##
## Año 2012 (Base: 2005) -0.158*** -0.200*** -0.157*** -0.262*** -0.301***
## (0.006) (0.011) (0.022) (0.016) (0.057)
##
## Año 2013 (Base: 2005) -0.147*** -0.183*** -0.187*** -0.270*** -0.266***
## (0.006) (0.011) (0.020) (0.015) (0.053)
##
## Año 2014 (Base: 2005) -0.175*** -0.232*** -0.261*** -0.284*** -0.389***
## (0.006) (0.011) (0.020) (0.015) (0.055)
##
## Año 2015 (Base: 2005) -0.168*** -0.228*** -0.187*** -0.271*** -0.328***
## (0.006) (0.011) (0.020) (0.015) (0.056)
##
## Año 2016 (Base: 2005) -0.177*** -0.233*** -0.221*** -0.306*** -0.359***
## (0.006) (0.011) (0.021) (0.015) (0.057)
##
## Año 2017 (Base: 2005) -0.184*** -0.262*** -0.235*** -0.371*** -0.390***
## (0.006) (0.011) (0.022) (0.015) (0.056)
##
## Año 2018 (Base: 2005) -0.187*** -0.255*** -0.240*** -0.351*** -0.424***
## (0.006) (0.011) (0.023) (0.016) (0.059)
##
## Año 2019 (Base: 2005) -0.182*** -0.263*** -0.275*** -0.361*** -0.443***
## (0.006) (0.011) (0.026) (0.016) (0.056)
##
## Año 2020 (Base: 2005) -0.212*** -0.301*** -0.269*** -0.331*** -0.435***
## (0.007) (0.012) (0.028) (0.017) (0.053)
##
## Año 2021 (Base: 2005) -0.187*** -0.292*** -0.202*** -0.338*** -0.466***
## (0.006) (0.011) (0.024) (0.015) (0.050)
##
## Año 2022 (Base: 2005) -0.166*** -0.257*** -0.173*** -0.394*** -0.572***
## (0.007) (0.011) (0.025) (0.015) (0.055)
##
## Año 2023 (Base: 2005) -0.110*** -0.188*** -0.184*** -0.309*** -0.413***
## (0.007) (0.011) (0.025) (0.015) (0.052)
##
## Año 2024 (Base: 2005) -0.055*** -0.146*** -0.128*** -0.267*** -0.378***
## (0.007) (0.011) (0.025) (0.015) (0.049)
##
## Año 2025 (Base: 2005) -0.057*** -0.110*** -0.164*** -0.262*** -0.415***
## (0.010) (0.015) (0.039) (0.021) (0.066)
##
## Horas trabajadas a la semana -0.015*** -0.018*** -0.020*** -0.021*** -0.015***
## (0.0001) (0.0001) (0.0003) (0.0002) (0.001)
##
## Constant 4.329*** 4.601*** 4.716*** 5.443*** 5.828***
## (0.006) (0.011) (0.020) (0.014) (0.053)
##
## ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
## Observations 220,561 83,946 20,012 67,158 6,110
## R2 0.258 0.279 0.285 0.243 0.169
## Adjusted R2 0.258 0.279 0.284 0.242 0.165
## Residual Std. Error 0.486 (df = 220534) 0.509 (df = 83919) 0.521 (df = 19985) 0.651 (df = 67131) 0.687 (df = 6083)
## F Statistic 2,954.281*** (df = 26; 220534) 1,249.661*** (df = 26; 83919) 306.750*** (df = 26; 19985) 827.477*** (df = 26; 67131) 47.449*** (df = 26; 6083)
## ============================================================================================================================================================================
## Note: *p<0.05; **p<0.01; ***p<0.001