#data
data<-read_xlsx("C:/SEMESTER 6/ADP/data.xlsx", sheet="asean all years")
pdata <- pdata.frame(data[,-1], index=c("C.Code","Year"))
#fem.ind
fem.ind<-plm(GDP~P+Emp+FCE, data = pdata, model = "within",
effect = "individual", index = c("C.Code, Year"))
summary(fem.ind)
## Oneway (individual) effect Within Model
##
## Call:
## plm(formula = GDP ~ P + Emp + FCE, data = pdata, effect = "individual",
## model = "within", index = c("C.Code, Year"))
##
## Balanced Panel: n = 10, T = 15, N = 150
##
## Residuals:
## Min. 1st Qu. Median 3rd Qu. Max.
## -14987.22 -1294.64 24.33 1141.27 16622.34
##
## Coefficients:
## Estimate Std. Error t-value Pr(>|t|)
## P 1.0341e-04 6.2390e-05 1.6574 0.09972 .
## Emp 3.9586e+02 1.5567e+02 2.5429 0.01211 *
## FCE -3.1273e+02 7.3046e+01 -4.2812 3.472e-05 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Total Sum of Squares: 2206400000
## Residual Sum of Squares: 1857200000
## R-Squared: 0.1583
## Adj. R-Squared: 0.084573
## F-statistic: 8.58852 on 3 and 137 DF, p-value: 2.8939e-05
#fem.time
fem.time<-plm(GDP~P+Emp+FCE, data = pdata, model = "within",
effect = "time", index = c("C.Code, Year"))
summary(fem.time)
## Oneway (time) effect Within Model
##
## Call:
## plm(formula = GDP ~ P + Emp + FCE, data = pdata, effect = "time",
## model = "within", index = c("C.Code, Year"))
##
## Balanced Panel: n = 10, T = 15, N = 150
##
## Residuals:
## Min. 1st Qu. Median 3rd Qu. Max.
## -15707.5 -6815.3 -1773.6 4599.4 31171.3
##
## Coefficients:
## Estimate Std. Error t-value Pr(>|t|)
## P -6.0535e-05 1.1916e-05 -5.0801 1.259e-06 ***
## Emp 2.3527e+01 1.2263e+02 0.1918 0.8482
## FCE -9.5023e+02 6.3596e+01 -14.9417 < 2.2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Total Sum of Squares: 4.6999e+10
## Residual Sum of Squares: 1.3002e+10
## R-Squared: 0.72336
## Adj. R-Squared: 0.68773
## F-statistic: 115.049 on 3 and 132 DF, p-value: < 2.22e-16
#rem dengan metode gls, efek individu
rem_gls_ind <- plm(GDP~P+Emp+FCE, data = pdata,
index = c("C.Code, Year"),
effect = "individual", model = "random")
summary(rem_gls_ind)
## Oneway (individual) effect Random Effect Model
## (Swamy-Arora's transformation)
##
## Call:
## plm(formula = GDP ~ P + Emp + FCE, data = pdata, effect = "individual",
## model = "random", index = c("C.Code, Year"))
##
## Balanced Panel: n = 10, T = 15, N = 150
##
## Effects:
## var std.dev share
## idiosyncratic 13555951 3682 0.108
## individual 111762347 10572 0.892
## theta: 0.9104
##
## Residuals:
## Min. 1st Qu. Median 3rd Qu. Max.
## -12153.4 -1775.4 -332.7 885.9 19457.1
##
## Coefficients:
## Estimate Std. Error z-value Pr(>|z|)
## (Intercept) 1.6667e+04 1.1962e+04 1.3933 0.16353
## P -1.0753e-05 3.8654e-05 -0.2782 0.78086
## Emp 3.1736e+02 1.5400e+02 2.0608 0.03933 *
## FCE -3.7711e+02 7.2972e+01 -5.1679 2.368e-07 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Total Sum of Squares: 2568900000
## Residual Sum of Squares: 2137500000
## R-Squared: 0.16792
## Adj. R-Squared: 0.15083
## Chisq: 29.4647 on 3 DF, p-value: 1.7884e-06
ranef(rem_gls_ind, effect = "individual")
## BRN IDN KHM LAO MMR MYS
## 14150.4491 -5423.6242 -10328.1788 -6983.9348 -7716.7151 -1279.0841
## PHL SGP THA VNM
## 269.3274 34647.6607 -6432.4282 -10903.4720
#pemeriksaan efek dalam model
##efek individu dan waktu
plmtest(rem_gls_ind,type = "bp", effect="twoways")#tolak H0
##
## Lagrange Multiplier Test - two-ways effects (Breusch-Pagan)
##
## data: GDP ~ P + Emp + FCE
## chisq = 597.28, df = 2, p-value < 2.2e-16
## alternative hypothesis: significant effects
##efek individu
plmtest(rem_gls_ind,type = "bp", effect="individual")#tolak H0
##
## Lagrange Multiplier Test - (Breusch-Pagan)
##
## data: GDP ~ P + Emp + FCE
## chisq = 592.55, df = 1, p-value < 2.2e-16
## alternative hypothesis: significant effects
##efek waktu
plmtest(rem_gls_ind,type = "bp", effect="time")#tolak H0
##
## Lagrange Multiplier Test - time effects (Breusch-Pagan)
##
## data: GDP ~ P + Emp + FCE
## chisq = 4.7262, df = 1, p-value = 0.02971
## alternative hypothesis: significant effects
##diagnostik sisaan model rem ind
res.rem_ind <- residuals(rem_gls_ind)
#normality
library(tseries)
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
jarque.bera.test(res.rem_ind)
##
## Jarque Bera Test
##
## data: res.rem_ind
## X-squared = 325.05, df = 2, p-value < 2.2e-16
#kolmogorov smirnov
ks.test(res.rem_ind, "pnorm")
##
## Asymptotic one-sample Kolmogorov-Smirnov test
##
## data: res.rem_ind
## D = 0.58, p-value < 2.2e-16
## alternative hypothesis: two-sided
#histogram
hist(res.rem_ind,
xlab = "sisaan",
col = "#27D3D3",
breaks=30,
prob = TRUE)
lines(density(res.rem_ind), # density plot
lwd = 2, # thickness of line
col = "chocolate3")

#plotqqnorm
set.seed(1353)
res.rem_ind1 <- as.numeric(res.rem_ind)
qqnorm(res.rem_ind1,datax=T, col="blue")
qqline(rnorm(length(res.rem_ind1),mean(res.rem_ind1),sd(res.rem_ind1)),datax=T, col="red")

#autocorelastion
adf.test(res.rem_ind, k=2) #alternatif : Terdapat autokorelasi
##
## Augmented Dickey-Fuller Test
##
## data: res.rem_ind
## Dickey-Fuller = -5.5366, Lag order = 2, p-value = 0.01
## alternative hypothesis: stationary
#homogen
bptest(rem_gls_ind)
##
## studentized Breusch-Pagan test
##
## data: rem_gls_ind
## BP = 29.228, df = 3, p-value = 2.005e-06
#rem dengan metode gls, efek waktu
rem_gls_time <- plm(GDP~P+Emp+FCE, data = pdata,
index = c("C.Code, Year"),
effect = "time", model = "random")
summary(rem_gls_time)
## Oneway (time) effect Random Effect Model
## (Swamy-Arora's transformation)
##
## Call:
## plm(formula = GDP ~ P + Emp + FCE, data = pdata, effect = "time",
## model = "random", index = c("C.Code, Year"))
##
## Balanced Panel: n = 10, T = 15, N = 150
##
## Effects:
## var std.dev share
## idiosyncratic 98498974 9925 1
## time 0 0 0
## theta: 0
##
## Residuals:
## Min. 1st Qu. Median 3rd Qu. Max.
## -17374.1 -6631.9 -1318.3 4568.4 33503.6
##
## Coefficients:
## Estimate Std. Error z-value Pr(>|z|)
## (Intercept) 7.9516e+04 7.3355e+03 10.8399 < 2.2e-16 ***
## P -6.0328e-05 1.1457e-05 -5.2657 1.397e-07 ***
## Emp 4.9186e+00 1.1667e+02 0.0422 0.9664
## FCE -9.4593e+02 6.0750e+01 -15.5709 < 2.2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Total Sum of Squares: 4.7389e+10
## Residual Sum of Squares: 1.3334e+10
## R-Squared: 0.71863
## Adj. R-Squared: 0.71285
## Chisq: 372.887 on 3 DF, p-value: < 2.22e-16
ranef(rem_gls_time, effect = "time")
## 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021
## 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## adj-r2 naik dari 16% (rem.ind) ke 71% (rem.time)
## tapi efek waktu semuanya 0 (invariant)
#pemilihan fem dan rem
#H0 : random, H1 : fixed
phtest(fem.ind, rem_gls_ind)#pvalue <5%, artinya model yang sesuai adalah fem.ind
##
## Hausman Test
##
## data: GDP ~ P + Emp + FCE
## chisq = 19.579, df = 3, p-value = 0.0002075
## alternative hypothesis: one model is inconsistent
phtest(fem.time, rem_gls_time)#pvalue>5%, artinya model yang sesuai adalah rem_gls_time
##
## Hausman Test
##
## data: GDP ~ P + Emp + FCE
## chisq = 0.30521, df = 3, p-value = 0.959
## alternative hypothesis: one model is inconsistent
#bingung tentang pemilihan model
#memeriksa antara model pengaruh acak dengan common effect model dengan uji pengganda laggrang.
cem <- plm(GDP~P+Emp+FCE, data = pdata, model="pooling")
c.tw <- plmtest(cem, effect = "twoways", type = c("bp"))
c.ind <- plmtest(cem, effect = "individual", type = c("bp"))
c.time <-plmtest(cem, effect = "time", type = c("bp"))
c.tw;c.ind;c.time
##
## Lagrange Multiplier Test - two-ways effects (Breusch-Pagan)
##
## data: GDP ~ P + Emp + FCE
## chisq = 597.28, df = 2, p-value < 2.2e-16
## alternative hypothesis: significant effects
##
## Lagrange Multiplier Test - (Breusch-Pagan)
##
## data: GDP ~ P + Emp + FCE
## chisq = 592.55, df = 1, p-value < 2.2e-16
## alternative hypothesis: significant effects
##
## Lagrange Multiplier Test - time effects (Breusch-Pagan)
##
## data: GDP ~ P + Emp + FCE
## chisq = 4.7262, df = 1, p-value = 0.02971
## alternative hypothesis: significant effects
##pooling model tidak cukup, karena terdapat efek panel