install.packages("readstata13")
library(AER)
library(data.table)
library(ggplot2)
library(foreign)
library(haven)
Casen<-read.dta("Casen2015.dta")
EncuestaCasen<-as.data.table(Casen)
Encuesta2<-EncuestaCasen[,.(folio,o,sexo,edad,region,zona,ecivil,esc,educ,pco1,ypch,ypchtot,ypchautcor,ypchtrabajo,pobreza,expr)]
Encuesta2[,sexomujer:=ifelse(sexo== "mujer",1,0)]
Encuesta2[,Experiencia_lab:= edad-esc-6]
setnames(Encuesta2,c("pco1"),c("relacion_jf"))
\(Y_i= β_0+β_1*mujer + U_i\) , modelo poblacional
modelo_simple<- lm(ypchtrabajo~sexomujer, data = Encuesta2)
summary(modelo_simple)
##
## Call:
## lm(formula = ypchtrabajo ~ sexomujer, data = Encuesta2)
##
## Residuals:
## Min 1Q Median 3Q Max
## -212126 -135034 -73301 25374 25329541
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 212125.8 895.8 236.79 <2e-16 ***
## sexomujer -25324.5 1239.8 -20.43 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 320000 on 266966 degrees of freedom
## Multiple R-squared: 0.00156, Adjusted R-squared: 0.001557
## F-statistic: 417.2 on 1 and 266966 DF, p-value: < 2.2e-16
Encuesta2[,ingreso_predicho:=predict(modelo_simple)]
Encuesta2[,residuo:=ypchtrabajo-ingreso_predicho]
modelo2<- lm(ypch~sexomujer + esc + Experiencia_lab, data = Encuesta2)
summary(modelo2)
##
## Call:
## lm(formula = ypch ~ sexomujer + esc + Experiencia_lab, data = Encuesta2)
##
## Residuals:
## Min 1Q Median 3Q Max
## -842280 -158243 -61324 56927 54603111
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -230584.54 3892.87 -59.23 <2e-16 ***
## sexomujer -25305.50 1771.69 -14.28 <2e-16 ***
## esc 39628.40 255.99 154.81 <2e-16 ***
## Experiencia_lab 4520.91 51.09 88.49 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 407000 on 212338 degrees of freedom
## (54626 observations deleted due to missingness)
## Multiple R-squared: 0.1021, Adjusted R-squared: 0.1021
## F-statistic: 8046 on 3 and 212338 DF, p-value: < 2.2e-16
Encuesta2[,Ingreso_predicho2:=predict(object = modelo2, newdata = Encuesta2)]
Encuesta2[,Residuo2:=ypchtrabajo-Ingreso_predicho2]
predict(object = modelo2, newdata = data.table(sexomujer=1,esc=17,Experiencia_lab=5 ))
## 1
## 440397.4
predict(object = modelo2, newdata = data.table(sexomujer=0,esc=17,Experiencia_lab=5 ))
## 1
## 465702.9
Smujer<-predict(object = modelo2, newdata = data.table(sexomujer=1,esc=17,Experiencia_lab=5 ))
Shombre<-predict(object = modelo2, newdata = data.table(sexomujer=0,esc=17,Experiencia_lab=5 ))
Shombre-Smujer
## 1
## 25305.5