link: https://rpubs.com/ReginaPC/1194137 ## R Markdown
library(wooldridge)
attach(mroz)
names(mroz)
## [1] "inlf" "hours" "kidslt6" "kidsge6" "age" "educ"
## [7] "wage" "repwage" "hushrs" "husage" "huseduc" "huswage"
## [13] "faminc" "mtr" "motheduc" "fatheduc" "unem" "city"
## [19] "exper" "nwifeinc" "lwage" "expersq"
MCO1<-lm(lwage~educ + exper+expersq, data=mroz)
summary(MCO1)
##
## Call:
## lm(formula = lwage ~ educ + exper + expersq, data = mroz)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.08404 -0.30627 0.04952 0.37498 2.37115
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.5220406 0.1986321 -2.628 0.00890 **
## educ 0.1074896 0.0141465 7.598 1.94e-13 ***
## exper 0.0415665 0.0131752 3.155 0.00172 **
## expersq -0.0008112 0.0003932 -2.063 0.03974 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.6664 on 424 degrees of freedom
## (325 observations deleted due to missingness)
## Multiple R-squared: 0.1568, Adjusted R-squared: 0.1509
## F-statistic: 26.29 on 3 and 424 DF, p-value: 1.302e-15
MES1<-lm(educ~exper+expersq+motheduc+fatheduc, data=mroz)
summary(MES1)
##
## Call:
## lm(formula = educ ~ exper + expersq + motheduc + fatheduc, data = mroz)
##
## Residuals:
## Min 1Q Median 3Q Max
## -7.4990 -1.1214 0.0277 0.9584 6.6078
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 8.3667162 0.2667111 31.370 < 2e-16 ***
## exper 0.0853780 0.0255485 3.342 0.000874 ***
## expersq -0.0018564 0.0008276 -2.243 0.025182 *
## motheduc 0.1856173 0.0259869 7.143 2.17e-12 ***
## fatheduc 0.1845745 0.0244979 7.534 1.42e-13 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.964 on 748 degrees of freedom
## Multiple R-squared: 0.2624, Adjusted R-squared: 0.2584
## F-statistic: 66.52 on 4 and 748 DF, p-value: < 2.2e-16
mroz$educpred=MES1$fitted.values
summary(mroz)
## inlf hours kidslt6 kidsge6
## Min. :0.0000 Min. : 0.0 Min. :0.0000 Min. :0.000
## 1st Qu.:0.0000 1st Qu.: 0.0 1st Qu.:0.0000 1st Qu.:0.000
## Median :1.0000 Median : 288.0 Median :0.0000 Median :1.000
## Mean :0.5684 Mean : 740.6 Mean :0.2377 Mean :1.353
## 3rd Qu.:1.0000 3rd Qu.:1516.0 3rd Qu.:0.0000 3rd Qu.:2.000
## Max. :1.0000 Max. :4950.0 Max. :3.0000 Max. :8.000
##
## age educ wage repwage
## Min. :30.00 Min. : 5.00 Min. : 0.1282 Min. :0.00
## 1st Qu.:36.00 1st Qu.:12.00 1st Qu.: 2.2626 1st Qu.:0.00
## Median :43.00 Median :12.00 Median : 3.4819 Median :0.00
## Mean :42.54 Mean :12.29 Mean : 4.1777 Mean :1.85
## 3rd Qu.:49.00 3rd Qu.:13.00 3rd Qu.: 4.9708 3rd Qu.:3.58
## Max. :60.00 Max. :17.00 Max. :25.0000 Max. :9.98
## NA's :325
## hushrs husage huseduc huswage
## Min. : 175 Min. :30.00 Min. : 3.00 Min. : 0.4121
## 1st Qu.:1928 1st Qu.:38.00 1st Qu.:11.00 1st Qu.: 4.7883
## Median :2164 Median :46.00 Median :12.00 Median : 6.9758
## Mean :2267 Mean :45.12 Mean :12.49 Mean : 7.4822
## 3rd Qu.:2553 3rd Qu.:52.00 3rd Qu.:15.00 3rd Qu.: 9.1667
## Max. :5010 Max. :60.00 Max. :17.00 Max. :40.5090
##
## faminc mtr motheduc fatheduc
## Min. : 1500 Min. :0.4415 Min. : 0.000 Min. : 0.000
## 1st Qu.:15428 1st Qu.:0.6215 1st Qu.: 7.000 1st Qu.: 7.000
## Median :20880 Median :0.6915 Median :10.000 Median : 7.000
## Mean :23081 Mean :0.6789 Mean : 9.251 Mean : 8.809
## 3rd Qu.:28200 3rd Qu.:0.7215 3rd Qu.:12.000 3rd Qu.:12.000
## Max. :96000 Max. :0.9415 Max. :17.000 Max. :17.000
##
## unem city exper nwifeinc
## Min. : 3.000 Min. :0.0000 Min. : 0.00 Min. :-0.02906
## 1st Qu.: 7.500 1st Qu.:0.0000 1st Qu.: 4.00 1st Qu.:13.02504
## Median : 7.500 Median :1.0000 Median : 9.00 Median :17.70000
## Mean : 8.624 Mean :0.6428 Mean :10.63 Mean :20.12896
## 3rd Qu.:11.000 3rd Qu.:1.0000 3rd Qu.:15.00 3rd Qu.:24.46600
## Max. :14.000 Max. :1.0000 Max. :45.00 Max. :96.00000
##
## lwage expersq educpred
## Min. :-2.0542 Min. : 0 Min. : 8.606
## 1st Qu.: 0.8165 1st Qu.: 16 1st Qu.:11.515
## Median : 1.2476 Median : 81 Median :12.267
## Mean : 1.1902 Mean : 178 Mean :12.287
## 3rd Qu.: 1.6036 3rd Qu.: 225 3rd Qu.:13.089
## Max. : 3.2189 Max. :2025 Max. :15.328
## NA's :325
MES2=lm(lwage~educpred+exper+expersq, data=mroz)
MES2
##
## Call:
## lm(formula = lwage ~ educpred + exper + expersq, data = mroz)
##
## Coefficients:
## (Intercept) educpred exper expersq
## 0.1332094 0.0568605 0.0421082 -0.0008565
library(AER)
## Cargando paquete requerido: car
## Cargando paquete requerido: carData
## Cargando paquete requerido: lmtest
## Cargando paquete requerido: zoo
##
## Adjuntando el paquete: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
## Cargando paquete requerido: sandwich
## Cargando paquete requerido: survival
IV1=ivreg(lwage~educ+exper+expersq|exper+expersq+motheduc+fatheduc)
IV1
##
## Call:
## ivreg(formula = lwage ~ educ + exper + expersq | exper + expersq + motheduc + fatheduc)
##
## Coefficients:
## (Intercept) educ exper expersq
## 0.048100 0.061397 0.044170 -0.000899
library(stargazer)
library(stargazer)
##
## Please cite as:
## Hlavac, Marek (2022). stargazer: Well-Formatted Regression and Summary Statistics Tables.
## R package version 5.2.3. https://CRAN.R-project.org/package=stargazer
stargazer(MCO1,MES2,IV1, type="text")
##
## ==============================================================
## Dependent variable:
## -------------------------------
## lwage
## OLS instrumental
## variable
## (1) (2) (3)
## --------------------------------------------------------------
## educ 0.107*** 0.061*
## (0.014) (0.031)
##
## educpred 0.057*
## (0.031)
##
## exper 0.042*** 0.042*** 0.044***
## (0.013) (0.014) (0.013)
##
## expersq -0.001** -0.001** -0.001**
## (0.0004) (0.0004) (0.0004)
##
## Constant -0.522*** 0.133 0.048
## (0.199) (0.382) (0.400)
##
## --------------------------------------------------------------
## Observations 428 428 428
## R2 0.157 0.050 0.136
## Adjusted R2 0.151 0.043 0.130
## Residual Std. Error (df = 424) 0.666 0.708 0.675
## F Statistic (df = 3; 424) 26.286*** 7.363***
## ==============================================================
## Note: *p<0.1; **p<0.05; ***p<0.01
summary(IV1, diagnostics=T)
##
## Call:
## ivreg(formula = lwage ~ educ + exper + expersq | exper + expersq +
## motheduc + fatheduc)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.0986 -0.3196 0.0551 0.3689 2.3493
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.0481003 0.4003281 0.120 0.90442
## educ 0.0613966 0.0314367 1.953 0.05147 .
## exper 0.0441704 0.0134325 3.288 0.00109 **
## expersq -0.0008990 0.0004017 -2.238 0.02574 *
##
## Diagnostic tests:
## df1 df2 statistic p-value
## Weak instruments 2 423 55.400 <2e-16 ***
## Wu-Hausman 1 423 2.793 0.0954 .
## Sargan 1 NA 0.378 0.5386
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.6747 on 424 degrees of freedom
## Multiple R-Squared: 0.1357, Adjusted R-squared: 0.1296
## Wald test: 8.141 on 3 and 424 DF, p-value: 2.787e-05
library(wooldridge)
Mlogit=glm(formula=inlf~nwifeinc+educ+exper+expersq+age+kidslt6+kidsge6, mroz, family=binomial(link="logit"))
summary(Mlogit)
##
## Call:
## glm(formula = inlf ~ nwifeinc + educ + exper + expersq + age +
## kidslt6 + kidsge6, family = binomial(link = "logit"), data = mroz)
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 0.425452 0.860365 0.495 0.62095
## nwifeinc -0.021345 0.008421 -2.535 0.01126 *
## educ 0.221170 0.043439 5.091 3.55e-07 ***
## exper 0.205870 0.032057 6.422 1.34e-10 ***
## expersq -0.003154 0.001016 -3.104 0.00191 **
## age -0.088024 0.014573 -6.040 1.54e-09 ***
## kidslt6 -1.443354 0.203583 -7.090 1.34e-12 ***
## kidsge6 0.060112 0.074789 0.804 0.42154
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 1029.75 on 752 degrees of freedom
## Residual deviance: 803.53 on 745 degrees of freedom
## AIC: 819.53
##
## Number of Fisher Scoring iterations: 4
exp(coefficients(Mlogit))
## (Intercept) nwifeinc educ exper expersq age
## 1.5302825 0.9788810 1.2475360 1.2285929 0.9968509 0.9157386
## kidslt6 kidsge6
## 0.2361344 1.0619557
RV=with(Mlogit,null.deviance-deviance)
pvalue=with(Mlogit,pchisq(RV, df.null-df.residual, lower.tail=FALSE))
R2MCFadeen=with(Mlogit, 1-(deviance/null.deviance))
R2MCFadeen
## [1] 0.2196814