population investment hdi
population 1.0000000 0.7052198 0.1212988
investment 0.7052198 1.0000000 0.3222325
hdi 0.1212988 0.3222325 1.0000000
library(lmtest)
Loading required package: zoo
Attaching package: 'zoo'
The following objects are masked from 'package:base':
as.Date, as.Date.numeric
# Heteroscedasticitybptest(FEM)
studentized Breusch-Pagan test
data: FEM
BP = 32.396, df = 3, p-value = 4.319e-07
# Autocorrelationpbgtest(FEM)
Breusch-Godfrey/Wooldridge test for serial correlation in panel models
data: model1
chisq = 84.76, df = 7, p-value = 1.468e-15
alternative hypothesis: serial correlation in idiosyncratic errors
# Cluster Robust Standard Errorlibrary(sandwich)coeftest(FEM, vcovHC(FEM, type ="sss", cluster ="group"))
t test of coefficients:
Estimate Std. Error t value Pr(>|t|)
log(population) -0.4403249 0.4093013 -1.0758 0.2834
log(investment) -0.0046652 0.0056843 -0.8207 0.4128
log(hdi) 1.4472500 1.0807171 1.3392 0.1821
# HAC Robust Standard Errorcoeftest(FEM, vcovHC(FEM, method="arellano"))
t test of coefficients:
Estimate Std. Error t value Pr(>|t|)
log(population) -0.4403249 0.4012959 -1.0973 0.2739
log(investment) -0.0046652 0.0055732 -0.8371 0.4036
log(hdi) 1.4472500 1.0595795 1.3659 0.1736
5.2 Dynamic Panel Data
head(datapanel)
# A tibble: 6 × 6
province year realgdp population investment hdi
<chr> <dbl> <dbl> <dbl> <dbl> <dbl>
1 Aceh 2010 101545. 4523100 82.3 67.1
2 Aceh 2011 104874. 4619000 463. 67.4
3 Aceh 2012 108915. 4715100 1726. 67.8
4 Aceh 2013 111756. 4811100 4785. 68.3
5 Aceh 2014 113488. 4906800 5497. 68.8
6 Aceh 2015 112672. 5002000 4485. 69.4
# Panel Data Regression```{r}library(readxl)datapanel =read_excel("Data/Bab 5/Data Panel.xlsx")head(datapanel)```## Static Panel Data```{r}library(plm)model1 =log(realgdp) ~log(population) +log(investment) +log(hdi)``````{r}# time vs individual effectpFtest(model1, data = datapanel, effect ="time")pFtest(model1, data = datapanel, effect ="individual")pFtest(model1, data = datapanel, effect ="twoways")```### Pooled OLS```{r}POLS <-plm(model1, data = datapanel, index =c("province", "year"), effect ="twoways", model ="pooling")summary(POLS)```### Fixed Effects Model```{r}FEM <-plm(model1, data = datapanel, index =c("province", "year"), effect ="twoways", model ="within")summary(FEM)``````{r}# FEM vs. Pooled OLSpFtest(FEM, POLS)```### Random Effects Model```{r}REM <-plm(model1, data = datapanel, index =c("province", "year"), effect ="twoways", model ="random")summary(REM)```### Hausman Test```{r}phtest(FEM,REM)```### Model Diagnostics```{r}# Multicolinearitylibrary(car)vif(POLS)cor(datapanel[,4:6])``````{r}library(lmtest)# Heteroscedasticitybptest(FEM) # Autocorrelationpbgtest(FEM)``````{r}# Cluster Robust Standard Errorlibrary(sandwich)coeftest(FEM, vcovHC(FEM, type ="sss", cluster ="group"))``````{r}# HAC Robust Standard Errorcoeftest(FEM, vcovHC(FEM, method="arellano"))```## Dynamic Panel Data```{r}head(datapanel)``````{r}# lag(log(realgdp), 2:7) = Instrumentmodeldyn1 =log(realgdp) ~lag(log(realgdp)) +log(population) +log(investment) +log(hdi) |lag(log(realgdp),2:7) # Dynamic OLS and FEMmodeldyn2 =log(realgdp) ~lag(log(realgdp)) +log(population) +log(investment) +log(hdi)```### First Difference GMM```{r}fd.gmm =pgmm(modeldyn1, data = datapanel)summary(fd.gmm)```### System GMM```{r}sys.gmm =pgmm(modeldyn1, data = datapanel, transformation="ld")summary(sys.gmm)```### Model Diagnotics```{r}# FEMFEMdyn =plm(modeldyn2, data = datapanel, index=c("province","year"), model="within")summary(FEMdyn)# OLSOLSdyn =plm(modeldyn2, data = datapanel, index=c("province","year"), model="pooling")summary(OLSdyn)```FDGMM = 0.731 SysGMM = 0.968 FEM = 0.767 OLS = 0.986FEM < GMM < OLSBest Model: System GMM```{r}summary(sys.gmm)```### Speed of Adjustment```{r}alpha1 = sys.gmm$coef[1]1-alpha1```### Half Time```{r}log(0.5)/log(sys.gmm$coef[1])```### Short Run and Long Run Coefficients```{r}sys.gmm$coefficients[2] # Short Run Poppulationsys.gmm$coefficients[2] / (1-alpha1) # Long Run Poppulation```