Also covered using Python and Stata
Load libraries
library(wooldridge)
library(stargazer)
library(AER)
library(mfx)
Effects of Education on Fertility
OLS <- lm(children ~ educ + age + agesq + evermarr + urban + electric + tv, data=fertil2)
Poisson <- glm(children ~ educ + age + agesq + evermarr + urban + electric + tv, data=fertil2, family=poisson)
stargazer(OLS, Poisson, no.space=TRUE, type="text", title = "Table 18.1 OLS and Poisson Estimates of a Fertility Equation")
##
## Table 18.1 OLS and Poisson Estimates of a Fertility Equation
## ========================================================
## Dependent variable:
## ------------------------------------
## children
## OLS Poisson
## (1) (2)
## --------------------------------------------------------
## educ -0.064*** -0.022***
## (0.006) (0.003)
## age 0.272*** 0.337***
## (0.017) (0.010)
## agesq -0.002*** -0.004***
## (0.0003) (0.0001)
## evermarr 0.682*** 0.315***
## (0.052) (0.024)
## urban -0.228*** -0.086***
## (0.046) (0.022)
## electric -0.262*** -0.121***
## (0.076) (0.039)
## tv -0.250*** -0.145***
## (0.090) (0.047)
## Constant -3.394*** -5.375***
## (0.245) (0.163)
## --------------------------------------------------------
## Observations 4,358 4,358
## R2 0.590
## Adjusted R2 0.589
## Log Likelihood -6,497.060
## Akaike Inf. Crit. 13,010.120
## Residual Std. Error 1.424 (df = 4350)
## F Statistic 893.910*** (df = 7; 4350)
## ========================================================
## Note: *p<0.1; **p<0.05; ***p<0.01
poissonmfx(Poisson, data=fertil2, atmean = F)
## Call:
## poissonmfx(formula = Poisson, data = fertil2, atmean = F)
##
## Marginal Effects:
## dF/dx Std. Err. z P>|z|
## educ -0.04912535 0.00662408 -7.4162 1.205e-13 ***
## age 0.76491583 0.02380923 32.1269 < 2.2e-16 ***
## agesq -0.00933287 0.00034254 -27.2459 < 2.2e-16 ***
## evermarr 0.67533842 0.04986768 13.5426 < 2.2e-16 ***
## urban -0.19458611 0.04883491 -3.9846 6.760e-05 ***
## electric -0.26136098 0.08052419 -3.2457 0.001171 **
## tv -0.30907074 0.09527605 -3.2440 0.001179 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## dF/dx is for discrete change for the following variables:
##
## [1] "evermarr" "urban" "electric" "tv"
Is Education Endogenous in the Fertility Equation?
fertil2 <- subset(fertil2, !is.na(electric))
v2 <- resid(OLS <- lm(educ ~ frsthalf + age + agesq + evermarr + urban + electric + tv, data=fertil2))
Poisson <- glm(children ~ educ + age + agesq + evermarr + urban + electric + tv + v2, data=fertil2, family=poisson)
stargazer(OLS, Poisson, no.space=TRUE, type="text")
##
## ========================================================
## Dependent variable:
## ------------------------------------
## educ children
## OLS Poisson
## (1) (2)
## --------------------------------------------------------
## frsthalf -0.636***
## (0.104)
## educ -0.046
## (0.032)
## age -0.070* 0.336***
## (0.041) (0.010)
## agesq -0.001 -0.004***
## (0.001) (0.0001)
## evermarr -0.802*** 0.294***
## (0.124) (0.037)
## urban 0.864*** -0.065*
## (0.109) (0.035)
## electric 1.978*** -0.071
## (0.179) (0.076)
## tv 2.715*** -0.078
## (0.211) (0.100)
## v2 0.025
## (0.032)
## Constant 8.203*** -5.185***
## (0.575) (0.298)
## --------------------------------------------------------
## Observations 4,358 4,358
## R2 0.251
## Adjusted R2 0.250
## Log Likelihood -6,496.771
## Akaike Inf. Crit. 13,011.540
## Residual Std. Error 3.402 (df = 4350)
## F Statistic 208.021*** (df = 7; 4350)
## ========================================================
## Note: *p<0.1; **p<0.05; ***p<0.01