Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
37 views14 pages

Kuis 2 1. Panggil Data Wages Penyelesaian: Script

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 14

Nama : Hilda Lailatul Ramadhania

Npm : 1817031056

Ekonomatrika B

KUIS 2

1. Panggil data Wages


Penyelesaian :

Script :
> library(plm)
> data("Wages",package="plm")
> data1<-Wages
> data1

Output :
exp wks bluecol ind south smsa married sex union ed black lwage
1 3 32 no 0 yes no yes male no 9 no 5.56068
2 4 43 no 0 yes no yes male no 9 no 5.72031
3 5 40 no 0 yes no yes male no 9 no 5.99645
4 6 39 no 0 yes no yes male no 9 no 5.99645
5 7 42 no 1 yes no yes male no 9 no 6.06146
6 8 35 no 1 yes no yes male no 9 no 6.17379
7 9 32 no 1 yes no yes male no 9 no 6.24417
8 30 34 yes 0 no no yes male no 11 no 6.16331
9 31 27 yes 0 no no yes male no 11 no 6.21461
10 32 33 yes 1 no no yes male yes 11 no 6.26340
11 33 30 yes 1 no no yes male no 11 no 6.54391
12 34 30 yes 1 no no yes male no 11 no 6.69703
13 35 37 yes 1 no no yes male no 11 no 6.79122
14 36 30 yes 1 no no yes male no 11 no 6.81564
15 6 50 yes 1 no no yes male yes 12 no 5.65249
16 7 51 yes 1 no no yes male yes 12 no 6.43615
17 8 50 yes 1 no no yes male yes 12 no 6.54822
18 9 52 yes 1 no no yes male yes 12 no 6.60259
19 10 52 yes 1 no no yes male yes 12 no 6.69580
20 11 52 yes 1 no no no male yes 12 no 6.77878
21 12 46 yes 1 no no no male yes 12 no 6.86066
22 31 52 yes 0 no yes no female no 10 yes 6.15698
23 32 46 yes 0 no yes no female no 10 yes 6.23832
24 33 46 yes 0 no yes no female no 10 yes 6.30079
25 34 49 yes 0 no yes no female no 10 yes 6.35957
26 35 44 yes 0 no yes no female no 10 yes 6.46925
27 36 52 yes 0 no yes no female no 10 yes 6.56244
28 37 46 yes 0 no yes no female no 10 yes 6.62141
29 10 50 yes 0 no no yes male yes 16 no 6.43775
30 11 46 yes 0 no no yes male yes 16 no 6.62007
31 12 40 yes 0 no no yes male yes 16 no 6.63332
32 13 50 no 0 no no yes male no 16 no 6.98286
33 14 47 yes 0 no yes yes male no 16 no 7.04752
34 15 47 no 0 no no yes male no 16 no 7.31322
35 16 49 no 0 no no yes male no 16 no 7.29574
36 26 44 yes 1 no yes yes male no 12 no 6.90575
37 27 47 yes 1 no yes yes male no 12 no 6.90575
38 28 47 yes 1 no yes yes male no 12 no 6.90776
39 29 47 yes 1 no yes yes male no 12 no 7.00307
40 30 44 yes 1 no yes yes male no 12 no 7.06902
41 31 45 yes 1 no yes yes male no 12 no 7.52023
42 32 47 yes 1 no yes yes male no 12 no 7.33889
43 15 46 yes 0 no no yes male yes 12 no 6.13340
44 16 48 yes 0 no no yes male yes 12 no 6.17379
45 17 49 yes 0 no no yes male yes 12 no 6.21261
46 18 46 yes 0 no no yes male yes 12 no 6.31355
47 19 47 yes 0 no no yes male yes 12 no 6.37502
48 20 47 yes 0 no no yes male yes 12 no 6.44572
49 21 48 yes 0 no no yes male yes 12 no 6.52209
50 23 51 yes 1 yes no yes male yes 10 no 6.33150
51 24 50 yes 1 yes no yes male yes 10 no 6.40357
52 25 50 yes 1 yes no yes male yes 10 no 6.54391
53 26 50 yes 1 yes no yes male yes 10 no 6.56244
54 27 44 yes 1 no yes yes male yes 10 no 6.59167
55 28 51 yes 1 no yes yes male yes 10 no 6.81783
56 29 51 yes 1 no yes yes male yes 10 no 6.89163
57 3 50 no 0 yes yes yes male no 16 no 6.55108
58 4 48 no 0 yes yes yes male no 16 no 6.55108
59 5 50 no 0 yes yes yes male no 16 no 6.80239
60 6 48 no 0 yes yes yes male no 16 no 6.90776
61 7 48 no 0 yes yes yes male no 16 no 7.09008
62 8 44 no 0 yes yes yes male no 16 no 7.17012
63 9 48 no 0 yes yes yes male no 16 no 7.20786
64 3 49 no 0 yes yes yes male no 16 no 6.39693
65 4 47 no 0 yes yes yes male no 16 no 6.43775
66 5 46 no 0 yes yes yes male no 16 no 6.43775
67 6 44 no 0 yes yes yes male no 16 no 6.43775
68 7 43 no 0 yes yes yes male no 16 no 6.52209
69 8 34 no 0 yes yes yes male no 16 no 6.61338
70 9 40 no 0 yes yes yes male no 16 no 6.73934
71 24 47 yes 0 no yes no male yes 12 no 6.65801
72 25 48 yes 0 no yes no male yes 12 no 6.72623
73 26 45 yes 0 no yes no male yes 12 no 6.80239
74 27 45 yes 0 no yes yes male yes 12 no 6.90776
75 28 47 yes 0 no yes yes male yes 12 no 7.03966
76 29 17 yes 0 no yes yes male yes 12 no 7.12769
77 30 47 yes 0 no yes yes male yes 12 no 7.24423
78 21 47 yes 0 yes yes yes male yes 12 no 6.55108
79 22 46 yes 0 yes yes yes male yes 12 no 6.62936
80 23 47 yes 0 yes yes yes male yes 12 no 6.72263
81 24 47 yes 0 yes yes yes male yes 12 no 6.73340
82 25 47 yes 0 yes yes yes male yes 12 no 6.72263
83 26 47 yes 0 yes yes yes male yes 12 no 6.95177
[ reached 'max' / getOption("max.print") -- omitted 4082 rows ]

2. Gunakan package yang sesuai untuk menganalisis data panel


Penyelesaian :
library(tidyverse) # Perpustakaan Ilmu Data Modern
library(plm) # Analisis Data Panel
library(car) # Pendamping Untuk Penerapan Regresi
library(gplots) # Berbagai Alat Pemograman Untuk Merencanakan Data
library(tseries) # Analisis Deret Waktu
library(lmtest) # Analisis Heteroskedastisitas

3. Set data panel


Penyelesaian :
> data1<-plm.data(Wages,595)
> View(data1)

4. Struktur data
Penyelesaian :

> str(data1)

Classes ‘plm.dim’ and 'data.frame': 4165 obs. of 14 variables:

$ id : Factor w/ 595 levels "1","2","3","4",..: 1 1 1 1 1 1 1 2 2 2 ...

$ time : Factor w/ 7 levels "1","2","3","4",..: 1 2 3 4 5 6 7 1 2 3 ...

$ exp : int 3 4 5 6 7 8 9 30 31 32 ...

$ wks : int 32 43 40 39 42 35 32 34 27 33 ...

$ bluecol: Factor w/ 2 levels "no","yes": 1 1 1 1 1 1 1 2 2 2 ...

$ ind : int 0 0 0 0 1 1 1 0 0 1 ...


$ south : Factor w/ 2 levels "no","yes": 2 2 2 2 2 2 2 1 1 1 ...

$ smsa : Factor w/ 2 levels "no","yes": 1 1 1 1 1 1 1 1 1 1 ...

$ married: Factor w/ 2 levels "no","yes": 2 2 2 2 2 2 2 2 2 2 ...

$ sex : Factor w/ 2 levels "male","female": 1 1 1 1 1 1 1 1 1 1 ...

$ union : Factor w/ 2 levels "no","yes": 1 1 1 1 1 1 1 1 1 2 ...

$ ed : int 9 9 9 9 9 9 9 11 11 11 ...

$ black : Factor w/ 2 levels "no","yes": 1 1 1 1 1 1 1 1 1 1 ...

$ lwage : num 5.56 5.72 6 6 6.06 ...

Interpretasi :

Data tersebut merupakan jenis data frame yang terdisi dari 4165 data dan memiliki 14
variable yaitu i, time, exp, wks, bluecol,ind,south,smsa,married,sex,union,ed,black dan
iwage. Dengan lwage adalah merupakan variabel y atau yang merupakan variabel numerik
dan yang lainnya yaitu exp, wks, buecol, ind, south, smsa, married, sex, union, ed, black
merupakan variabel kategori

> summary(data1)

id time exp wks bluecol ind

1 : 7 1:595 Min. : 1.00 Min. : 5.00 no :2036 Min. :0.0000

2 : 7 2:595 1st Qu.:11.00 1st Qu.:46.00 yes:2129 1st Qu.:0.0000

3 : 7 3:595 Median :18.00 Median :48.00 Median :0.0000

4 : 7 4:595 Mean :19.85 Mean :46.81 Mean :0.3954

5 : 7 5:595 3rd Qu.:29.00 3rd Qu.:50.00 3rd Qu.:1.0000

6 : 7 6:595 Max. :51.00 Max. :52.00 Max. :1.0000

(Other):4123 7:595

south smsa married sex union ed

no :2956 no :1442 no : 773 male :3696 no :2649 Min. : 4.00

yes:1209 yes:2723 yes:3392 female: 469 yes:1516 1st Qu.:12.00

Median :12.00

Mean :12.85
3rd Qu.:16.00

Max. :17.00

black lwage

no :3864 Min. :4.605

yes: 301 1st Qu.:6.395

Median :6.685

Mean :6.676

3rd Qu.:6.953

Max. :8.537

> names(data1)

[1] "id" "time" "exp" "wks" "bluecol" "ind" "south" "smsa"

[9] "married" "sex" "union" "ed" "black" "lwage"

5. Model – model estimasi berikut ini, serta interpretasikan :

a. the fixed effects model ("within")

Penyelesaian :

Script :

plm(lwage~exp+wks+bluecol+ind+south+smsa+married+sex+union+ed+black, data

= data1, model = "within")

summary(data1)

Output :

> data1<-

+ plm(lwage~exp+wks+bluecol+ind+south+smsa+married+sex+union+ed+black, data

+ = data1, model = "within")

> summary(data1)
Oneway (individual) effect Within Model

Call:

plm(formula = lwage ~ exp + wks + bluecol + ind + south + smsa +

married + sex + union + ed + black, data = data1, model = "within")

Balanced Panel: n = 595, T = 7, N = 4165

Residuals:

Min. 1st Qu. Median 3rd Qu. Max.

-1.7984511 -0.0535263 0.0042525 0.0628480 1.9452352

Coefficients:

Estimate Std. Error t-value Pr(>|t|)

exp 0.09657698 0.00119085 81.0992 < 2e-16 ***

wks 0.00114223 0.00060316 1.8937 0.05834 .

bluecolyes -0.02486403 0.01388776 -1.7904 0.07348 .

ind 0.02075656 0.01556962 1.3331 0.18257

southyes -0.00319792 0.03457562 -0.0925 0.92631

smsayes -0.04372702 0.01958444 -2.2327 0.02563 *

marriedyes -0.03025961 0.01913663 -1.5812 0.11391

unionyes 0.03415826 0.01504220 2.2708 0.02322 *

---

Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Total Sum of Squares: 240.65

Residual Sum of Squares: 83.624


R-Squared: 0.65251

Adj. R-Squared: 0.59378

F-statistic: 836.082 on 8 and 3562 DF, p-value: < 2.22e-16

b. the pooling model ("pooling")

Penyelesaian :

Script :

data1<-

plm(lwage~exp+wks+bluecol+ind+south+smsa+married+sex+union+ed+black, data

= data1, model = "pooling")

summary(data1)

Output :

> data1<-

+ plm(lwage~exp+wks+bluecol+ind+south+smsa+married+sex+union+ed+black, data

+ = data1, model = "pooling")

Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors) :

cannot coerce class ‘c("plm", "panelmodel")’ to a data.frame

> summary(data1)

Oneway (individual) effect Within Model

Call:

plm(formula = lwage ~ exp + wks + bluecol + ind + south + smsa +

married + sex + union + ed + black, data = data1, model = "within")

Balanced Panel: n = 595, T = 7, N = 4165

Residuals:
Min. 1st Qu. Median 3rd Qu. Max.

-1.7984511 -0.0535263 0.0042525 0.0628480 1.9452352

Coefficients:

Estimate Std. Error t-value Pr(>|t|)

exp 0.09657698 0.00119085 81.0992 < 2e-16 ***

wks 0.00114223 0.00060316 1.8937 0.05834 .

bluecolyes -0.02486403 0.01388776 -1.7904 0.07348 .

ind 0.02075656 0.01556962 1.3331 0.18257

southyes -0.00319792 0.03457562 -0.0925 0.92631

smsayes -0.04372702 0.01958444 -2.2327 0.02563 *

marriedyes -0.03025961 0.01913663 -1.5812 0.11391

unionyes 0.03415826 0.01504220 2.2708 0.02322 *

---

Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Total Sum of Squares: 240.65

Residual Sum of Squares: 83.624

R-Squared: 0.65251

Adj. R-Squared: 0.59378

F-statistic: 836.082 on 8 and 3562 DF, p-value: < 2.22e-16

c. the first-difference model ("fd")

Penyelesaian :

> #Nomor 5c

> #estimasi dengan metode first-difference


> Data1.fd <-
plm(lwage~exp+wks+bluecol+ind+south+smsa+married+sex+union+ed+black, data = data1,
model = "fd")

> summary(data1)

Oneway (individual) effect First-Difference Model

Call:

plm(formula = lwage ~ exp + wks + bluecol + ind + south + smsa +

married + sex + union + ed + black, data = DataW, model = "fd")

Balanced Panel: n = 595, T = 7, N = 4165

Observations used in estimation: 3570

Residuals:

Min. 1st Qu. Median 3rd Qu. Max.

-2.0975375 -0.0649861 -0.0096534 0.0491749 2.3463506

Coefficients:

Estimate Std. Error t-value Pr(>|t|)

(Intercept) 0.09548937 0.00304143 31.3962 < 2e-16 ***

wks -0.00021593 0.00056534 -0.3819 0.70253

bluecolyes -0.02425814 0.01380497 -1.7572 0.07897 .

ind 0.02127236 0.01607177 1.3236 0.18573

southyes -0.01349266 0.04589312 -0.2940 0.76877

smsayes -0.05539323 0.02347122 -2.3600 0.01833 *

marriedyes -0.05356497 0.02292810 -2.3362 0.01954 *

unionyes 0.01707094 0.01493070 1.1433 0.25297

---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Total Sum of Squares: 118.06

Residual Sum of Squares: 117.47

R-Squared: 0.0049904

Adj. R-Squared: 0.003035

F-statistic: 2.55212 on 7 and 3562 DF, p-value: 0.012748

d. the between model ("between")

Penyelesaiaan :

> #Nomor 5d

> #estimasi dengan metode between

> Data1.bt <- plm(lwage~exp+wks+bluecol+ind+south+smsa+married+sex+union+ed+black,


data = Data1, model = "between")

> summary(Data1.bt)

Oneway (individual) effect Between Model

Call:

plm(formula = lwage ~ exp + wks + bluecol + ind + south + smsa +

married + sex + union + ed + black, data = DataW, model = "between")

Balanced Panel: n = 595, T = 7, N = 4165

Observations used in estimation: 595

Residuals:

Min. 1st Qu. Median 3rd Qu. Max.

-0.818558 -0.186448 0.016169 0.189032 0.717144


Coefficients:

Estimate Std. Error t-value Pr(>|t|)

(Intercept) 5.2633537 0.2073718 25.3812 < 2.2e-16 ***

exp 0.0068181 0.0011207 6.0839 2.125e-09 ***

wks 0.0101379 0.0036858 2.7505 0.0061352 **

bluecolyes -0.1757451 0.0345877 -5.0811 5.059e-07 ***

ind 0.0635796 0.0261274 2.4334 0.0152555 *

southyes -0.0549649 0.0265833 -2.0676 0.0391143 *

smsayes 0.1704995 0.0263512 6.4703 2.075e-10 ***

marriedyes 0.1348008 0.0486854 2.7688 0.0058051 **

sexfemale -0.3000472 0.0559355 -5.3642 1.174e-07 ***

unionyes 0.1185015 0.0298744 3.9667 8.196e-05 ***

ed 0.0517282 0.0056866 9.0965 < 2.2e-16 ***

blackyes -0.1572054 0.0460838 -3.4113 0.0006913 ***

---

Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Total Sum of Squares: 92.322

Residual Sum of Squares: 44.176

R-Squared: 0.5215

Adj. R-Squared: 0.51247

F-statistic: 57.7624 on 11 and 583 DF, p-value: < 2.22e-16


e. the error components model ("random")

Penyelesaian :

> #Nomor 5e

> #estimasi dengan metode REM

> DataW.ra <-


plm(lwage~exp+wks+bluecol+ind+south+smsa+married+sex+union+ed+black, data =
DataW, model = "random")

> summary(DataW.ra)

Oneway (individual) effect Random Effect Model

(Swamy-Arora's transformation)

Call:

plm(formula = lwage ~ exp + wks + bluecol + ind + south + smsa +

married + sex + union + ed + black, data = DataW, model = "random")

Balanced Panel: n = 595, T = 7, N = 4165

Effects:

var std.dev share

idiosyncratic 0.02348 0.15322 0.245

individual 0.07242 0.26911 0.755

theta: 0.7896

Residuals:

Min. 1st Qu. Median 3rd Qu. Max.

-2.04946924 -0.11853444 -0.00021574 0.12339053 2.07663451

Coefficients:
Estimate Std. Error z-value Pr(>|z|)

(Intercept) 4.45723817 0.09871702 45.1517 < 2.2e-16 ***

exp 0.04858479 0.00105868 45.8921 < 2.2e-16 ***

wks 0.00163642 0.00078399 2.0873 0.0368607 *

bluecolyes -0.05647110 0.01692847 -3.3359 0.0008503 ***

ind 0.00724624 0.01759465 0.4118 0.6804541

southyes -0.01346703 0.02719483 -0.4952 0.6204552

smsayes -0.02243588 0.02040428 -1.0996 0.2715207

marriedyes -0.07348239 0.02340504 -3.1396 0.0016918 **

sexfemale -0.33345404 0.05278293 -6.3175 2.659e-10 ***

unionyes 0.06820389 0.01738559 3.9230 8.745e-05 ***

ed 0.10203378 0.00591314 17.2554 < 2.2e-16 ***

blackyes -0.21591338 0.05977852 -3.6119 0.0003040 ***

---

Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Total Sum of Squares: 269.25

Residual Sum of Squares: 169.88

R-Squared: 0.36909

Adj. R-Squared: 0.36742

Chisq: 2429.56 on 11 DF, p-value: < 2.22e-16ai


6. Uji spesifikasi model, yakni:
a. Uji Chow
Penyelesaian :

> #Nomor 6a
> #Uji chow
> pFtest(1ata1.fe , data1.ce)

F test for individual effects

data: lwage ~ exp + wks + bluecol + ind + south + smsa + married + ...
F = 32.269, df1 = 591, df2 = 3562, p-value < 2.2e-16
alternative hypothesis: significant effects

b. Uji Hausman
Penyelesaian :
> #Nomor 6b
> #uji hausman
> phtest(data1.ra,data1.fe)

Hausman Test

data: lwage ~ exp + wks + bluecol + ind + south + smsa + married + ...
chisq = 6529.5, df = 8, p-value < 2.2e-16
alternative hypothesis: one model is inconsistent

You might also like