Also covered using Python and Stata
library(wooldridge)
library(lmtest)
library(stargazer)
library(car)
library(dynlm)
mrk_l1 <- lm(return ~ return_1, data =nyse)
stargazer(mrk_l1, no.space=TRUE, type="text")
##
## ===============================================
## Dependent variable:
## ---------------------------
## return
## -----------------------------------------------
## return_1 0.059
## (0.038)
## Constant 0.180**
## (0.081)
## -----------------------------------------------
## Observations 689
## R2 0.003
## Adjusted R2 0.002
## Residual Std. Error 2.110 (df = 687)
## F Statistic 2.399 (df = 1; 687)
## ===============================================
## Note: *p<0.1; **p<0.05; ***p<0.01
nyse_tsset <- ts(nyse)
mrk_lag2 <- dynlm(return ~ return_1 + L(return, 2), data =nyse_tsset)
stargazer(mrk_lag2, no.space=TRUE, type="text")
##
## ===============================================
## Dependent variable:
## ---------------------------
## return
## -----------------------------------------------
## return_1 0.060
## (0.038)
## L(return, 2) -0.038
## (0.038)
## Constant 0.186**
## (0.081)
## -----------------------------------------------
## Observations 688
## R2 0.005
## Adjusted R2 0.002
## Residual Std. Error 2.112 (df = 685)
## F Statistic 1.659 (df = 2; 685)
## ===============================================
## Note: *p<0.1; **p<0.05; ***p<0.01
linearHypothesis(mrk_lag2, c("return_1 =0","L(return, 2)=0"))
## Linear hypothesis test
##
## Hypothesis:
## return_1 = 0
## L(return, 2) = 0
##
## Model 1: restricted model
## Model 2: return ~ return_1 + L(return, 2)
##
## Res.Df RSS Df Sum of Sq F Pr(>F)
## 1 687 3069.4
## 2 685 3054.6 2 14.792 1.6586 0.1912
data(phillips, package='wooldridge')
phillips_old <-subset(phillips, phillips$year<1997)
phill_new<-lm(cinf ~ unem + 1, data=phillips) #Slightly longer dataset (1948-2003)
phill_old<-lm(cinf ~ unem + 1, data=phillips_old) #Dataset as in the textbook (1948-1996)
stargazer(phill_new, phill_old, column.labels=c("LongerData", "OriginalData"),no.space=TRUE, type="text")
##
## =============================================================
## Dependent variable:
## -----------------------------------------
## cinf
## LongerData OriginalData
## (1) (2)
## -------------------------------------------------------------
## unem -0.518** -0.543**
## (0.209) (0.230)
## Constant 2.828** 3.031**
## (1.225) (1.377)
## -------------------------------------------------------------
## Observations 55 48
## R2 0.104 0.108
## Adjusted R2 0.087 0.088
## Residual Std. Error 2.307 (df = 53) 2.451 (df = 46)
## F Statistic 6.132** (df = 1; 53) 5.558** (df = 1; 46)
## =============================================================
## Note: *p<0.1; **p<0.05; ***p<0.01
u0 <- phill_old$coef[1]/-phill_old$coef[2]
u0
## (Intercept)
## 5.585429
fertil3_tsset <- ts(fertil3)
fert_lag2 <- dynlm(cgfr ~ cpe + L(cpe, 1) + L(cpe, 2), data =fertil3_tsset)
stargazer(fert_lag2, no.space=TRUE, type="text")
##
## ===============================================
## Dependent variable:
## ---------------------------
## cgfr
## -----------------------------------------------
## cpe -0.036
## (0.027)
## L(cpe, 1) -0.014
## (0.028)
## L(cpe, 2) 0.110***
## (0.027)
## Constant -0.964**
## (0.468)
## -----------------------------------------------
## Observations 69
## R2 0.232
## Adjusted R2 0.197
## Residual Std. Error 3.859 (df = 65)
## F Statistic 6.563*** (df = 3; 65)
## ===============================================
## Note: *p<0.1; **p<0.05; ***p<0.01
linearHypothesis(fert_lag2, c("cpe =0","L(cpe, 1)=0"))
## Linear hypothesis test
##
## Hypothesis:
## cpe = 0
## L(cpe,0
##
## Model 1: restricted model
## Model 2: cgfr ~ cpe + L(cpe, 1) + L(cpe, 2)
##
## Res.Df RSS Df Sum of Sq F Pr(>F)
## 1 67 1006.6
## 2 65 968.2 2 38.413 1.2894 0.2824
earns_t <- lm(lhrwage ~ loutphr + t, data=earns)
stargazer(earns_t, no.space=TRUE, type="text")
##
## ===============================================
## Dependent variable:
## ---------------------------
## lhrwage
## -----------------------------------------------
## loutphr 1.640***
## (0.093)
## t -0.018***
## (0.002)
## Constant -5.328***
## (0.374)
## -----------------------------------------------
## Observations 41
## R2 0.971
## Adjusted R2 0.970
## Residual Std. Error 0.029 (df = 38)
## F Statistic 641.224*** (df = 2; 38)
## ===============================================
## Note: *p<0.1; **p<0.05; ***p<0.01
wage_g <- lm(ghrwage ~ goutphr, data=earns)
stargazer(wage_g, no.space=TRUE, type="text")
##
## ===============================================
## Dependent variable:
## ---------------------------
## ghrwage
## -----------------------------------------------
## goutphr 0.809***
## (0.173)
## Constant -0.004
## (0.004)
## -----------------------------------------------
## Observations 40
## R2 0.364
## Adjusted R2 0.348
## Residual Std. Error 0.017 (df = 38)
## F Statistic 21.771*** (df = 1; 38)
## ===============================================
## Note: *p<0.1; **p<0.05; ***p<0.01
fertil3_tsset <- ts(fertil3)
fert_lags <- dynlm(cgfr ~ L(cgfr, 1) + cpe + L(cpe, 1) + L(cpe, 2), data =fertil3_tsset)
stargazer(fert_lags, no.space=TRUE, type="text")
##
## ===============================================
## Dependent variable:
## ---------------------------
## cgfr
## -----------------------------------------------
## L(cgfr, 1) 0.300***
## (0.106)
## cpe -0.045*
## (0.026)
## L(cpe, 1) 0.002
## (0.027)
## L(cpe, 2) 0.105***
## (0.026)
## Constant -0.702
## (0.454)
## -----------------------------------------------
## Observations 69
## R2 0.318
## Adjusted R2 0.275
## Residual Std. Error 3.666 (df = 64)
## F Statistic 7.464*** (df = 4; 64)
## ===============================================
## Note: *p<0.1; **p<0.05; ***p<0.01
linearHypothesis(fert_lags, c("cpe =0","L(cpe, 1)=0"))
## Linear hypothesis test
##
## Hypothesis:
## cpe = 0
## L(cpe,0
##
## Model 1: restricted model
## Model 2: cgfr ~ L(cgfr, 1) + cpe + L(cpe, 1) + L(cpe, 2)
##
## Res.Df RSS Df Sum of Sq F Pr(>F)
## 1 66 904.68
## 2 64 860.17 2 44.508 1.6558 0.199