This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.
Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Ctrl+Shift+Enter.
library(plm) # model data panel
library(lmtest) # coeftest, bptest
library(sandwich) # matriks kovarian robust
library(dplyr)
library(ggplot2)
library(car) # vif, linearHypothesis
data <- read.csv(file.choose())
data <- data_panel_industri
str(data)
spc_tbl_ [300 × 8] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
$ id_perusahaan: num [1:300] 1 1 1 1 1 1 1 1 1 1 ...
$ perusahaan : chr [1:300] "PT_01" "PT_01" "PT_01" "PT_01" ...
$ sektor : chr [1:300] "Makanan-Minuman" "Makanan-Minuman" "Makanan-Minuman" "Makanan-Minuman" ...
$ tahun : num [1:300] 2015 2016 2017 2018 2019 ...
$ output : num [1:300] 277 282 292 276 271 ...
$ tenaga_kerja : num [1:300] 194 182 187 183 184 204 177 211 191 205 ...
$ modal : num [1:300] 66.1 60.4 64.5 58.6 55.7 ...
$ rnd : num [1:300] 1.6 1.66 1.75 1.96 2.03 2.37 2.01 2.3 1.95 1.96 ...
- attr(*, "spec")=
.. cols(
.. id_perusahaan = col_double(),
.. perusahaan = col_character(),
.. sektor = col_character(),
.. tahun = col_double(),
.. output = col_double(),
.. tenaga_kerja = col_double(),
.. modal = col_double(),
.. rnd = col_double()
.. )
- attr(*, "problems")=<externalptr>
summary(data)
id_perusahaan perusahaan sektor tahun output tenaga_kerja
Min. : 1.0 Length:300 Length:300 Min. :2015 Min. : 74.87 Min. :102.0
1st Qu.: 8.0 Class :character Class :character 1st Qu.:2017 1st Qu.: 243.22 1st Qu.:183.0
Median :15.5 Mode :character Mode :character Median :2020 Median : 462.95 Median :241.5
Mean :15.5 Mean :2020 Mean : 859.30 Mean :272.8
3rd Qu.:23.0 3rd Qu.:2022 3rd Qu.:1388.39 3rd Qu.:355.2
Max. :30.0 Max. :2024 Max. :3900.42 Max. :615.0
modal rnd
Min. : 26.92 Min. :0.260
1st Qu.: 72.19 1st Qu.:1.730
Median :109.58 Median :2.370
Mean :144.48 Mean :2.253
3rd Qu.:194.80 3rd Qu.:2.882
Max. :567.44 Max. :3.750
data <- data %>%
mutate(ln_output = log(output),
ln_tk = log(tenaga_kerja),
ln_modal = log(modal))
# Deklarasi struktur panel: (individu, waktu)
pdata <- pdata.frame(data, index = c("id_perusahaan", "tahun"))
pdim(pdata) # n = 30, T = 10, balanced
Balanced Panel: n = 30, T = 10, N = 300
is.pbalanced(pdata)
[1] TRUE
# Statistik deskriptif per sektor
data %>%
group_by(sektor) %>%
summarise(rata_output = mean(output), rata_tk = mean(tenaga_kerja),
rata_modal = mean(modal), rata_rnd = mean(rnd), .groups = "drop")
# Lintasan ln(output) tiap perusahaan (heterogenitas antar-individu)
ggplot(data, aes(tahun, ln_output, group = id_perusahaan, color = sektor)) +
geom_line(alpha = .7) +
labs(title = "Lintasan ln(Output) per Perusahaan", x = "Tahun", y = "ln(Output)") +
theme_minimal()
# Rata-rata ln(output) per tahun (efek waktu, mis. dampak 2020)
data %>% group_by(tahun) %>%
summarise(m = mean(ln_output)) %>%
ggplot(aes(tahun, m)) + geom_line() + geom_point() +
labs(title = "Rata-rata ln(Output) per Tahun", x = "Tahun", y = "Rata-rata ln(Output)") +
theme_minimal()
# Multikolinearitas (pada model pooled biasa)
vif(lm(ln_output ~ ln_tk + ln_modal + rnd, data = data))
ln_tk ln_modal rnd
4.090498 4.237730 1.112340
rumus <- ln_output ~ ln_tk + ln_modal + rnd
cem <- plm(rumus, data = pdata, model = "pooling") # Common Effect
fem <- plm(rumus, data = pdata, model = "within") # Fixed Effect
rem <- plm(rumus, data = pdata, model = "random") # Random Effect
summary(cem)
Pooling Model
Call:
plm(formula = rumus, data = pdata, model = "pooling")
Balanced Panel: n = 30, T = 10, N = 300
Residuals:
Min. 1st Qu. Median 3rd Qu. Max.
-1.08286186 -0.20280190 0.00047553 0.24070549 1.10012169
Coefficients:
Estimate Std. Error t-value Pr(>|t|)
(Intercept) -4.271468 0.415132 -10.2894 < 2.2e-16 ***
ln_tk 1.347785 0.121032 11.1358 < 2.2e-16 ***
ln_modal 0.557933 0.075778 7.3627 1.795e-12 ***
rnd 0.199406 0.031315 6.3677 7.305e-10 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Total Sum of Squares: 283.56
Residual Sum of Squares: 49.013
R-Squared: 0.82715
Adj. R-Squared: 0.8254
F-statistic: 472.155 on 3 and 296 DF, p-value: < 2.22e-16
summary(fem)
Oneway (individual) effect Within Model
Call:
plm(formula = rumus, data = pdata, model = "within")
Balanced Panel: n = 30, T = 10, N = 300
Residuals:
Min. 1st Qu. Median 3rd Qu. Max.
-0.2623159 -0.0537254 0.0044568 0.0550731 0.2095264
Coefficients:
Estimate Std. Error t-value Pr(>|t|)
ln_tk 0.421424 0.058740 7.1744 7.165e-12 ***
ln_modal 0.571365 0.032907 17.3632 < 2.2e-16 ***
rnd 0.083758 0.018437 4.5429 8.409e-06 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Total Sum of Squares: 6.1706
Residual Sum of Squares: 1.8637
R-Squared: 0.69796
Adj. R-Squared: 0.66177
F-statistic: 205.667 on 3 and 267 DF, p-value: < 2.22e-16
summary(rem)
Oneway (individual) effect Random Effect Model
(Swamy-Arora's transformation)
Call:
plm(formula = rumus, data = pdata, model = "random")
Balanced Panel: n = 30, T = 10, N = 300
Effects:
var std.dev share
idiosyncratic 0.00698 0.08355 0.04
individual 0.16879 0.41084 0.96
theta: 0.9358
Residuals:
Min. 1st Qu. Median 3rd Qu. Max.
-0.2555793 -0.0554974 0.0023774 0.0571482 0.2350037
Coefficients:
Estimate Std. Error z-value Pr(>|z|)
(Intercept) 0.637303 0.315967 2.0170 0.0437 *
ln_tk 0.479486 0.059232 8.0950 5.725e-16 ***
ln_modal 0.592151 0.033465 17.6944 < 2.2e-16 ***
rnd 0.080114 0.018715 4.2806 1.864e-05 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Total Sum of Squares: 7.313
Residual Sum of Squares: 2.2124
R-Squared: 0.69748
Adj. R-Squared: 0.69441
Chisq: 682.435 on 3 DF, p-value: < 2.22e-16
# Perbandingan koefisien
data.frame(CEM = coef(cem)[-1], FEM = coef(fem), REM = coef(rem)[-1])
NA
# 4a. Uji Chow: CEM vs FEM (H0: CEM memadai)
pFtest(fem, cem)
F test for individual effects
data: rumus
F = 232.92, df1 = 29, df2 = 267, p-value < 2.2e-16
alternative hypothesis: significant effects
# 4b. Uji Breusch-Pagan LM: CEM vs REM (H0: tidak ada efek individu)
plmtest(cem, type = "bp")
Lagrange Multiplier Test - (Breusch-Pagan)
data: rumus
chisq = 1089.7, df = 1, p-value < 2.2e-16
alternative hypothesis: significant effects
# 4c. Uji Hausman: FEM vs REM (H0: REM konsisten / efek tidak berkorelasi)
phtest(fem, rem)
Hausman Test
data: rumus
chisq = 48.107, df = 3, p-value = 2.021e-10
alternative hypothesis: one model is inconsistent
# p-value < 0.05 -> tolak H0 -> pilih FEM
fem2 <- plm(rumus, data = pdata, model = "within", effect = "twoways")
summary(fem2)
Twoways effects Within Model
Call:
plm(formula = rumus, data = pdata, effect = "twoways", model = "within")
Balanced Panel: n = 30, T = 10, N = 300
Residuals:
Min. 1st Qu. Median 3rd Qu. Max.
-2.1491e-01 -4.8847e-02 -2.1364e-05 4.6719e-02 1.7877e-01
Coefficients:
Estimate Std. Error t-value Pr(>|t|)
ln_tk 0.376545 0.052811 7.1300 1.008e-11 ***
ln_modal 0.465053 0.039123 11.8868 < 2.2e-16 ***
rnd 0.052952 0.017653 2.9996 0.002968 **
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Total Sum of Squares: 2.466
Residual Sum of Squares: 1.3728
R-Squared: 0.4433
Adj. R-Squared: 0.35483
F-statistic: 68.4823 on 3 and 258 DF, p-value: < 2.22e-16
# Uji apakah efek waktu signifikan (H0: tanpa efek waktu)
pFtest(fem2, fem)
F test for twoways effects
data: rumus
F = 10.251, df1 = 9, df2 = 258, p-value = 1.683e-13
alternative hypothesis: significant effects
plmtest(fem, effect = "time", type = "bp")
Lagrange Multiplier Test - time effects (Breusch-Pagan)
data: rumus
chisq = 1.1925, df = 1, p-value = 0.2748
alternative hypothesis: significant effects
# Efek tetap tiap perusahaan (intersep individual)
head(sort(fixef(fem2, effect = "individual"), decreasing = TRUE), 5)
2 14 29 17 19
2.831006 2.749453 2.717654 2.715568 2.637762
# Heteroskedastisitas (Breusch-Pagan pada model LSDV)
bptest(ln_output ~ ln_tk + ln_modal + rnd + factor(id_perusahaan),
data = data, studentize = TRUE)
studentized Breusch-Pagan test
data: ln_output ~ ln_tk + ln_modal + rnd + factor(id_perusahaan)
BP = 39.886, df = 32, p-value = 0.1595
# Autokorelasi serial (Wooldridge) -- H0: tidak ada autokorelasi
pwartest(fem)
Wooldridge's test for serial correlation in FE panels
data: fem
F = 10.475, df1 = 1, df2 = 268, p-value = 0.001362
alternative hypothesis: serial correlation
pbgtest(fem) # Breusch-Godfrey untuk panel
Breusch-Godfrey/Wooldridge test for serial correlation in panel models
data: rumus
chisq = 42.943, df = 10, p-value = 5.092e-06
alternative hypothesis: serial correlation in idiosyncratic errors
# Ketergantungan antar-individu (Pesaran CD) -- H0: tidak ada
pcdtest(fem, test = "cd")
Pesaran CD test for cross-sectional dependence in panels
data: ln_output ~ ln_tk + ln_modal + rnd
z = 14.732, p-value < 2.2e-16
alternative hypothesis: cross-sectional dependence
# Galat baku robust terhadap heteroskedastisitas & autokorelasi (cluster perusahaan)
coeftest(fem2, vcov = vcovHC(fem2, type = "HC1", cluster = "group"))
t test of coefficients:
Estimate Std. Error t value Pr(>|t|)
ln_tk 0.376545 0.050193 7.5019 1.017e-12 ***
ln_modal 0.465053 0.038079 12.2128 < 2.2e-16 ***
rnd 0.052952 0.016334 3.2419 0.001344 **
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
# Constant returns to scale: b_tk + b_modal = 1 ?
linearHypothesis(fem2, "ln_tk + ln_modal = 1",
vcov = vcovHC(fem2, type = "HC1", cluster = "group"))
Linear hypothesis test:
ln_tk + ln_modal = 1
Model 1: restricted model
Model 2: ln_output ~ ln_tk + ln_modal + rnd
Note: Coefficient covariance matrix supplied.
Res.Df Df Chisq Pr(>Chisq)
1 259
2 258 1 6.4806 0.01091 *
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
hasil <- data.frame(
Variabel = c("ln_tk", "ln_modal", "rnd"),
CEM = round(coef(cem)[-1], 3),
FEM = round(coef(fem), 3),
REM = round(coef(rem)[-1], 3),
FEM2 = round(coef(fem2), 3)
)
print(hasil, row.names = FALSE)
# write.csv(hasil, "ringkasan_koefisien.csv", row.names = FALSE)