1
2R version 4.1.1 (2021-08-10) -- "Kick Things"
3Copyright (C) 2021 The R Foundation for Statistical Computing
4Platform: x86_64-w64-mingw32/x64 (64-bit)
5
6R is free software and comes with ABSOLUTELY NO WARRANTY.
7You are welcome to redistribute it under certain conditions.
8Type 'license()' or 'licence()' for distribution details.
9
10R is a collaborative project with many contributors.
11Type 'contributors()' for more information and
12'citation()' on how to cite R or R packages in publications.
13
14Type 'demo()' for some demos, 'help()' for on-line help, or
15'help.start()' for an HTML browser interface to help.
16Type 'q()' to quit R.
17
18> library(plm)
19> data("Grunfeld", package = "plm")
20> Grunfeld_unbal <- Grunfeld[1:199, ]
21> # ercomp(plm(inv ~ value, Grunfeld, model = "random"))
22> # ercomp(plm(inv ~ value, Grunfeld, model = "random", random.method = "amemiya"))
23> # ercomp(plm(inv ~ value + capital, Grunfeld_unbal, model = "random"))
24>
25>
26> # these resulted in errors pre rev. 523 due to missing drop = FALSE
27> plm(inv ~ value, Grunfeld_unbal, model = "random", random.method = "amemiya")
28
29Model Formula: inv ~ value
30
31Coefficients:
32(Intercept)       value
33  -40.07159     0.17196
34
35> plm(inv ~ value, Grunfeld_unbal, model = "random", random.method = "amemiya", effect = "time")
36
37Model Formula: inv ~ value
38
39Coefficients:
40(Intercept)       value
41   -6.26072     0.14083
42
43>
44>
45> # test case for illegal pseries in pmerge's return value:
46> # up to rev. 675, pmerge produced a data.frame with a column declared to be a pseries but with lacking index,
47> # and there should be no 'pseries' in the resulting data.frame in first place
48> pGrunfeld <- pdata.frame(Grunfeld)
49> df_after_pmerge <- plm:::pmerge(pGrunfeld$inv, pGrunfeld$value)
50> if (inherits(df_after_pmerge$ind, "pseries") && is.null(attr(df_after_pmerge$ind, "index"))) stop("illegal pseries (no index) produced by pmerge")
51> if ("pseries" %in% unlist(lapply(df_after_pmerge, class))) stop("pmerge returned a column with pseries")
52> if (!"data.frame" == class(df_after_pmerge)) stop("pmerge did not return a pure data.frame according to class()")
53>
54>
55> # pmodel.response: test case for illegal pseries
56> form <- formula(inv ~ value + capital)
57> if (!is.pseries(pmodel.response(form, data = pGrunfeld, model = "pooling"))) stop("pmodel.response's return value is not a valid pseries")
58> if (!is.pseries(pmodel.response(form, data = pGrunfeld, model = "within"))) stop("pmodel.response's return value is not a valid pseries")
59> if (!is.pseries(pmodel.response(form, data = pGrunfeld, model = "Between"))) stop("pmodel.response's return value is not a valid pseries")
60> if (!is.pseries(pmodel.response(plm(form, data = pGrunfeld, model = "random")))) stop("pmodel.response's return value is not a valid pseries")
61> # for FD and between models, it should be a numeric as a pseries does not make sense due to the data compression
62> if (inherits(pmodel.response(form, data = pGrunfeld, model = "fd"), "pseries")) stop("pmodel.response's return value shall not be a pseries for fd models")
63> if (inherits(pmodel.response(form, data = pGrunfeld, model = "between"), "pseries")) stop("pmodel.response's return value shall not be a pseries for between models")
64> if (plm:::has.index(pmodel.response(plm(form, data = pGrunfeld, model = "fd")))) stop("pmodel.response's return value shall not have an index for fd models")
65> if (plm:::has.index(pmodel.response(plm(form, data = pGrunfeld, model = "between")))) stop("pmodel.response's return value shall not have an index for between models")
66>
67>
68> # residuals.plm: test case for illegal pseries
69> if (!is.pseries(residuals(plm(form, data = pGrunfeld, model = "pooling")))) stop("residuals.plm's return value is not a valid pseries")
70> if (!is.pseries(residuals(plm(form, data = pGrunfeld, model = "within")))) stop("residuals.plm's return value is not a valid pseries")
71> if (!is.pseries(residuals(plm(form, data = pGrunfeld, model = "random")))) stop("residuals.plm's return value is not a valid pseries")
72> # for FD and between models, it should be a numeric as a pseries does not make sense due to the data compression
73> if (inherits(residuals(plm(form, data = pGrunfeld, model = "fd")), "pseries")) stop("residuals.plm's return value shall not be a pseries for fd models")
74> if (inherits(residuals(plm(form, data = pGrunfeld, model = "between")), "pseries")) stop("residuals.plm's return value shall not be a pseries for between models")
75> if (plm:::has.index(residuals(plm(form, data = pGrunfeld, model = "fd")))) stop("residuals.plm's return value shall not have an index for fd models")
76> if (plm:::has.index(residuals(plm(form, data = pGrunfeld, model = "between")))) stop("residuals.plm's return value shall not have an index for between models")
77>
78>
79> # fitted.plm: test case for illegal pseries
80> if (!is.pseries(fitted(plm(form, data = pGrunfeld, model = "pooling")))) stop("fitted.plm's return value is not a valid pseries")
81> if (!is.pseries(fitted(plm(form, data = pGrunfeld, model = "within")))) stop("fitted.plm's return value is not a valid pseries")
82> if (!is.pseries(fitted(plm(form, data = pGrunfeld, model = "random")))) stop("fitted.plm's return value is not a valid pseries")
83> # for FD and between models, it should be a numeric as a pseries does not make sense due to the data compression
84> if (inherits(fitted(plm(form, data = pGrunfeld, model = "fd")), "pseries")) stop("fitted.plm's return value shall not be a pseries for fd models")
85> if (inherits(fitted(plm(form, data = pGrunfeld, model = "between")), "pseries")) stop("fitted.plm's return value shall not be a pseries for between models")
86> if (plm:::has.index(fitted(plm(form, data = pGrunfeld, model = "fd")))) stop("fitted.plm's return value shall not have an index for fd models")
87> if (plm:::has.index(fitted(plm(form, data = pGrunfeld, model = "between")))) stop("fitted.plm's return value shall not have an index for between models")
88>
89> ## WLS
90> p <- plm(inv ~ value, Grunfeld, model = "pooling")
91> pwls <- plm(inv ~ value + capital, data = Grunfeld, weights = Grunfeld$capital, model = "pooling")
92>
93> if (!is.null(p$weights)) stop("element 'weights' in plm object albeit it should not be there")
94> if (is.null(pwls$weights)) stop("element 'weights' missing in plm object")
95>
96> ## aneweytest
97> data("RiceFarms", package = "plm")
98> aneweytest(log(goutput) ~ log(seed) + log(totlabor) + log(size), RiceFarms, index = "id")
99
100	Angrist and Newey's test of within model
101
102data:  log(goutput) ~ log(seed) + log(totlabor) + log(size)
103chisq = 141.89, df = 87, p-value = 0.0001851
104alternative hypothesis: within specification does not apply
105
106>
107> ## piest
108> pirice <- piest(log(goutput) ~ log(seed) + log(totlabor) + log(size), RiceFarms, index = "id")
109> summary(pirice)
110                  Estimate Std. Error z-value  Pr(>|z|)
111log(seed)        0.1096449  0.0157087  6.9799 2.954e-12 ***
112log(totlabor)    0.2261224  0.0168539 13.4166 < 2.2e-16 ***
113log(size)        0.6575833  0.0226042 29.0912 < 2.2e-16 ***
114log(seed).1      0.1168747  0.0282226  4.1412 3.455e-05 ***
115log(totlabor).1  0.0440505  0.0352284  1.2504 0.2111448
116log(size).1     -0.2315263  0.0451630 -5.1265 2.952e-07 ***
117log(seed).2     -0.0190152  0.0119321 -1.5936 0.1110215
118log(totlabor).2 -0.0261597  0.0290088 -0.9018 0.3671718
119log(size).2      0.0314256  0.0233416  1.3463 0.1781949
120log(seed).3     -0.0687868  0.0247259 -2.7820 0.0054030 **
121log(totlabor).3  0.1221667  0.0294784  4.1443 3.409e-05 ***
122log(size).3      0.0487253  0.0238871  2.0398 0.0413683 *
123log(seed).4      0.0132149  0.0285666  0.4626 0.6436509
124log(totlabor).4  0.0526304  0.0272371  1.9323 0.0533221 .
125log(size).4     -0.0046384  0.0443225 -0.1047 0.9166526
126log(seed).5     -0.1105456  0.0291603 -3.7910 0.0001501 ***
127log(totlabor).5 -0.2277151  0.0390801 -5.8269 5.647e-09 ***
128log(size).5      0.2376872  0.0437637  5.4311 5.599e-08 ***
129log(seed).6      0.2556306  0.0364290  7.0172 2.263e-12 ***
130log(totlabor).6  0.1535560  0.0354287  4.3342 1.463e-05 ***
131log(size).6     -0.3550436  0.0422203 -8.4093 < 2.2e-16 ***
132---
133Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
134
135	Chamberlain's pi test
136
137data:  log(goutput) ~ log(seed) + log(totlabor) + log(size)
138chisq = 113.72, df = 87, p-value = 0.02882
139alternative hypothesis: within specification does not apply
140
141>
142> ## mtest
143> data("EmplUK", package = "plm")
144> ar <- pgmm(log(emp) ~ lag(log(emp), 1:2) + lag(log(wage), 0:1) +
145+              lag(log(capital), 0:2) + lag(log(output), 0:2) | lag(log(emp), 2:99),
146+            data = EmplUK, effect = "twoways", model = "twosteps")
147> mtest(ar, order = 1)
148
149	Arellano-Bond autocorrelation test of degree 1
150
151data:  log(emp) ~ lag(log(emp), 1:2) + lag(log(wage), 0:1) + lag(log(capital),  ...
152normal = -2.9998, p-value = 0.002702
153alternative hypothesis: autocorrelation present
154
155> mtest(ar, order = 2, vcov = vcovHC)
156
157	Arellano-Bond autocorrelation test of degree 2, vcov: vcovHC
158
159data:  log(emp) ~ lag(log(emp), 1:2) + lag(log(wage), 0:1) + lag(log(capital),  ...
160normal = -0.36744, p-value = 0.7133
161alternative hypothesis: autocorrelation present
162
163>
164> ## pcdtest
165> pcdtest(inv ~ value + capital, data = Grunfeld,
166+         index = c("firm", "year"))
167
168	Pesaran CD test for cross-sectional dependence in panels
169
170data:  inv ~ value + capital
171z = 5.3401, p-value = 9.292e-08
172alternative hypothesis: cross-sectional dependence
173
174>
175> ## test on two-way fixed effects homogeneous model
176> pcdtest(inv ~ value + capital, data = Grunfeld, model = "within",
177+         effect = "twoways", index = c("firm", "year"))
178
179	Pesaran CD test for cross-sectional dependence in panels
180
181data:  inv ~ value + capital
182z = 0.1162, p-value = 0.9075
183alternative hypothesis: cross-sectional dependence
184
185>
186> ## test on panelmodel object
187> g <- plm(inv ~ value + capital, data = Grunfeld, index = c("firm", "year"))
188> pcdtest(g)
189
190	Pesaran CD test for cross-sectional dependence in panels
191
192data:  inv ~ value + capital
193z = 4.6612, p-value = 3.144e-06
194alternative hypothesis: cross-sectional dependence
195
196>
197> ## scaled LM test
198> pcdtest(g, test = "sclm")
199
200	Scaled LM test for cross-sectional dependence in panels
201
202data:  inv ~ value + capital
203z = 21.222, p-value < 2.2e-16
204alternative hypothesis: cross-sectional dependence
205
206>
207> ## test on pseries
208> pGrunfeld <- pdata.frame(Grunfeld)
209> pcdtest(pGrunfeld$value)
210
211	Pesaran CD test for cross-sectional dependence in panels
212
213data:  pGrunfeld$value
214z = 13.843, p-value < 2.2e-16
215alternative hypothesis: cross-sectional dependence
216
217>
218> ## local test
219> ## define neighbours for individual 2: 1, 3, 4, 5 in lower triangular matrix
220> w <- matrix(0, ncol= 10, nrow=10)
221> w[2,1] <- w[3,2] <- w[4,2] <- w[5,2] <- 1
222> pcdtest(g, w = w)
223
224	Pesaran CD test for local cross-sectional dependence in panels
225
226data:  inv ~ value + capital
227z = -0.87759, p-value = 0.3802
228alternative hypothesis: cross-sectional dependence
229
230>
231>
232> ## cortab
233> pGrunfeld <- pdata.frame(Grunfeld)
234> grp <- c(rep(1, 100), rep(2, 50), rep(3, 50)) # make 3 groups
235> cortab(pGrunfeld$value, grouping = grp, groupnames = c("A", "B", "C"))
236          A         B          C
237A 0.5562310        NA         NA
238B 0.5431652 0.5406152         NA
239C 0.3799585 0.2999645 -0.1665637
240>
241> ## ercomp
242> data("Produc", package = "plm")
243> ercomp(log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp, data = Produc,
244+        method = "walhus", effect = "time")
245                    var   std.dev share
246idiosyncratic 0.0075942 0.0871449 0.985
247time          0.0001192 0.0109175 0.015
248theta: 0.2448
249> z <- plm(log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp,
250+          data = Produc, random.method = "walhus",
251+          effect = "time", model = "random")
252> ercomp(z)
253                    var   std.dev share
254idiosyncratic 0.0075942 0.0871449 0.985
255time          0.0001192 0.0109175 0.015
256theta: 0.2448
257> ercomp(log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp, data = Produc,
258+        method = "amemiya", effect = "twoways")
259                    var   std.dev share
260idiosyncratic 0.0011695 0.0341975 0.046
261individual    0.0238635 0.1544780 0.929
262time          0.0006534 0.0255613 0.025
263theta: 0.9464 (id) 0.8104 (time) 0.8084 (total)
264>
265> ## index
266> data("Grunfeld", package = "plm")
267> Gr <- pdata.frame(Grunfeld, index = c("firm", "year"))
268> m <- plm(inv ~ value + capital, data = Gr)
269> index(Gr, "firm")
270  [1] 1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  2  2  2  2  2
271 [26] 2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  3  3  3  3  3  3  3  3  3  3
272 [51] 3  3  3  3  3  3  3  3  3  3  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4
273 [76] 4  4  4  4  4  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5
274[101] 6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  7  7  7  7  7
275[126] 7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  8  8  8  8  8  8  8  8  8  8
276[151] 8  8  8  8  8  8  8  8  8  8  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9
277[176] 9  9  9  9  9  10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10
278Levels: 1 2 3 4 5 6 7 8 9 10
279> index(Gr, "time")
280  [1] 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949
281 [16] 1950 1951 1952 1953 1954 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944
282 [31] 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1935 1936 1937 1938 1939
283 [46] 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954
284 [61] 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949
285 [76] 1950 1951 1952 1953 1954 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944
286 [91] 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1935 1936 1937 1938 1939
287[106] 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954
288[121] 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949
289[136] 1950 1951 1952 1953 1954 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944
290[151] 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1935 1936 1937 1938 1939
291[166] 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954
292[181] 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949
293[196] 1950 1951 1952 1953 1954
29420 Levels: 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 ... 1954
295> index(Gr$inv, c(2, 1))
296    year firm
2971   1935    1
2982   1936    1
2993   1937    1
3004   1938    1
3015   1939    1
3026   1940    1
3037   1941    1
3048   1942    1
3059   1943    1
30610  1944    1
30711  1945    1
30812  1946    1
30913  1947    1
31014  1948    1
31115  1949    1
31216  1950    1
31317  1951    1
31418  1952    1
31519  1953    1
31620  1954    1
31721  1935    2
31822  1936    2
31923  1937    2
32024  1938    2
32125  1939    2
32226  1940    2
32327  1941    2
32428  1942    2
32529  1943    2
32630  1944    2
32731  1945    2
32832  1946    2
32933  1947    2
33034  1948    2
33135  1949    2
33236  1950    2
33337  1951    2
33438  1952    2
33539  1953    2
33640  1954    2
33741  1935    3
33842  1936    3
33943  1937    3
34044  1938    3
34145  1939    3
34246  1940    3
34347  1941    3
34448  1942    3
34549  1943    3
34650  1944    3
34751  1945    3
34852  1946    3
34953  1947    3
35054  1948    3
35155  1949    3
35256  1950    3
35357  1951    3
35458  1952    3
35559  1953    3
35660  1954    3
35761  1935    4
35862  1936    4
35963  1937    4
36064  1938    4
36165  1939    4
36266  1940    4
36367  1941    4
36468  1942    4
36569  1943    4
36670  1944    4
36771  1945    4
36872  1946    4
36973  1947    4
37074  1948    4
37175  1949    4
37276  1950    4
37377  1951    4
37478  1952    4
37579  1953    4
37680  1954    4
37781  1935    5
37882  1936    5
37983  1937    5
38084  1938    5
38185  1939    5
38286  1940    5
38387  1941    5
38488  1942    5
38589  1943    5
38690  1944    5
38791  1945    5
38892  1946    5
38993  1947    5
39094  1948    5
39195  1949    5
39296  1950    5
39397  1951    5
39498  1952    5
39599  1953    5
396100 1954    5
397101 1935    6
398102 1936    6
399103 1937    6
400104 1938    6
401105 1939    6
402106 1940    6
403107 1941    6
404108 1942    6
405109 1943    6
406110 1944    6
407111 1945    6
408112 1946    6
409113 1947    6
410114 1948    6
411115 1949    6
412116 1950    6
413117 1951    6
414118 1952    6
415119 1953    6
416120 1954    6
417121 1935    7
418122 1936    7
419123 1937    7
420124 1938    7
421125 1939    7
422126 1940    7
423127 1941    7
424128 1942    7
425129 1943    7
426130 1944    7
427131 1945    7
428132 1946    7
429133 1947    7
430134 1948    7
431135 1949    7
432136 1950    7
433137 1951    7
434138 1952    7
435139 1953    7
436140 1954    7
437141 1935    8
438142 1936    8
439143 1937    8
440144 1938    8
441145 1939    8
442146 1940    8
443147 1941    8
444148 1942    8
445149 1943    8
446150 1944    8
447151 1945    8
448152 1946    8
449153 1947    8
450154 1948    8
451155 1949    8
452156 1950    8
453157 1951    8
454158 1952    8
455159 1953    8
456160 1954    8
457161 1935    9
458162 1936    9
459163 1937    9
460164 1938    9
461165 1939    9
462166 1940    9
463167 1941    9
464168 1942    9
465169 1943    9
466170 1944    9
467171 1945    9
468172 1946    9
469173 1947    9
470174 1948    9
471175 1949    9
472176 1950    9
473177 1951    9
474178 1952    9
475179 1953    9
476180 1954    9
477181 1935   10
478182 1936   10
479183 1937   10
480184 1938   10
481185 1939   10
482186 1940   10
483187 1941   10
484188 1942   10
485189 1943   10
486190 1944   10
487191 1945   10
488192 1946   10
489193 1947   10
490194 1948   10
491195 1949   10
492196 1950   10
493197 1951   10
494198 1952   10
495199 1953   10
496200 1954   10
497> index(m, "id")
498  [1] 1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  2  2  2  2  2
499 [26] 2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  3  3  3  3  3  3  3  3  3  3
500 [51] 3  3  3  3  3  3  3  3  3  3  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4
501 [76] 4  4  4  4  4  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5
502[101] 6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  7  7  7  7  7
503[126] 7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  8  8  8  8  8  8  8  8  8  8
504[151] 8  8  8  8  8  8  8  8  8  8  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9
505[176] 9  9  9  9  9  10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10
506Levels: 1 2 3 4 5 6 7 8 9 10
507>
508> # with additional group index
509> data("Produc", package = "plm")
510> pProduc <- pdata.frame(Produc, index = c("state", "year", "region"))
511> index(pProduc, 3)
512  [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
513 [38] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
514 [75] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2
515[112] 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
516[149] 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
517[186] 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
518[223] 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
519[260] 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
520[297] 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
521[334] 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 5
522[371] 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5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8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8
580[667] 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8
581[704] 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8
582[741] 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 9 9 9
583[778] 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
584[815] 9 9
585Levels: 1 2 3 4 5 6 7 8 9
586>
587> ## is.pbalanced
588> Grunfeld_missing_period <- Grunfeld[-2, ]
589> is.pbalanced(Grunfeld_missing_period)     # check if balanced: FALSE
590[1] FALSE
591> pdim(Grunfeld_missing_period)$balanced    # same
592[1] FALSE
593> pGrunfeld_missing_period <- pdata.frame(Grunfeld_missing_period)
594> is.pbalanced(Grunfeld_missing_period)
595[1] FALSE
596> is.pbalanced(pGrunfeld_missing_period$inv)
597[1] FALSE
598>
599> ## is.pconsecutive
600> is.pconsecutive(Grunfeld)
601   1    2    3    4    5    6    7    8    9   10
602TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
603> is.pconsecutive(Grunfeld, index=c("firm", "year"))
604   1    2    3    4    5    6    7    8    9   10
605TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
606>
607> # delete 2nd row (2nd time period for first individual)
608> # -> non consecutive
609> Grunfeld_missing_period <- Grunfeld[-2, ]
610> is.pconsecutive(Grunfeld_missing_period)
611    1     2     3     4     5     6     7     8     9    10
612FALSE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
613> all(is.pconsecutive(Grunfeld_missing_period)) # FALSE
614[1] FALSE
615>
616> # delete rows 1 and 2 (1st and 2nd time period for first individual)
617> # -> consecutive
618> Grunfeld_missing_period_other <- Grunfeld[-c(1,2), ]
619> is.pconsecutive(Grunfeld_missing_period_other) # all TRUE
620   1    2    3    4    5    6    7    8    9   10
621TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
622>
623> # delete year 1937 (3rd period) for _all_ individuals
624> Grunfeld_wo_1937 <- Grunfeld[Grunfeld$year != 1937, ]
625> is.pconsecutive(Grunfeld_wo_1937) # all FALSE
626    1     2     3     4     5     6     7     8     9    10
627FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
628>
629> # pdata.frame interface
630> pGrunfeld <- pdata.frame(Grunfeld)
631> pGrunfeld_missing_period <- pdata.frame(Grunfeld_missing_period)
632> is.pconsecutive(pGrunfeld) # all TRUE
633   1    2    3    4    5    6    7    8    9   10
634TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
635> is.pconsecutive(pGrunfeld_missing_period) # first FALSE, others TRUE
636    1     2     3     4     5     6     7     8     9    10
637FALSE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
638>
639> # panelmodel interface (first, estimate some models)
640> mod_pGrunfeld <- plm(inv ~ value + capital, data = Grunfeld)
641> mod_pGrunfeld_missing_period <- plm(inv ~ value + capital, data = Grunfeld_missing_period)
642>
643> is.pconsecutive(mod_pGrunfeld)
644   1    2    3    4    5    6    7    8    9   10
645TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
646> is.pconsecutive(mod_pGrunfeld_missing_period)
647    1     2     3     4     5     6     7     8     9    10
648FALSE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
649>
650> nobs(mod_pGrunfeld) # 200
651[1] 200
652> nobs(mod_pGrunfeld_missing_period) # 199
653[1] 199
654>
655> # pseries interface
656> pinv <- pGrunfeld$inv
657> pinv_missing_period <- pGrunfeld_missing_period$inv
658>
659> is.pconsecutive(pinv)
660   1    2    3    4    5    6    7    8    9   10
661TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
662> is.pconsecutive(pinv_missing_period)
663    1     2     3     4     5     6     7     8     9    10
664FALSE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
665>
666> # default method for arbitrary vectors or NULL
667> inv <- Grunfeld$inv
668> inv_missing_period <- Grunfeld_missing_period$inv
669> is.pconsecutive(inv, id = Grunfeld$firm, time = Grunfeld$year)
670   1    2    3    4    5    6    7    8    9   10
671TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
672> is.pconsecutive(inv_missing_period, id = Grunfeld_missing_period$firm,
673+                 time = Grunfeld_missing_period$year)
674    1     2     3     4     5     6     7     8     9    10
675FALSE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
676>
677> # only id and time are needed for evaluation
678> is.pconsecutive(NULL, id = Grunfeld$firm, time = Grunfeld$year)
679   1    2    3    4    5    6    7    8    9   10
680TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
681>
682> ## is.pseries
683> Em <- pdata.frame(EmplUK)
684> z <- Em$output
685>
686> class(z) # pseries as indicated by class
687[1] "pseries" "numeric"
688> is.pseries(z) # and confirmed by check
689[1] TRUE
690>
691> # destroy index of pseries and re-check
692> attr(z, "index") <- NA
693> is.pseries(z) # now FALSE
694[1] FALSE
695>
696> ## model.frame, model.matrix
697> pGrunfeld <- pdata.frame(Grunfeld)
698>
699> # then make a model frame from a formula and a pdata.frame
700> form <- inv ~ value
701> mf <- model.frame(pGrunfeld, form)
702>
703> # then construct the (transformed) model matrix (design matrix)
704> # from model frame
705> modmat <- model.matrix(mf, model = "within")
706>
707> ## retrieve model frame and model matrix from an estimated plm object
708> fe_model <- plm(form, data = pGrunfeld, model = "within")
709> model.frame(fe_model)
710            inv   value
7111-1935   317.60 3078.50
7121-1936   391.80 4661.70
7131-1937   410.60 5387.10
7141-1938   257.70 2792.20
7151-1939   330.80 4313.20
7161-1940   461.20 4643.90
7171-1941   512.00 4551.20
7181-1942   448.00 3244.10
7191-1943   499.60 4053.70
7201-1944   547.50 4379.30
7211-1945   561.20 4840.90
7221-1946   688.10 4900.90
7231-1947   568.90 3526.50
7241-1948   529.20 3254.70
7251-1949   555.10 3700.20
7261-1950   642.90 3755.60
7271-1951   755.90 4833.00
7281-1952   891.20 4924.90
7291-1953  1304.40 6241.70
7301-1954  1486.70 5593.60
7312-1935   209.90 1362.40
7322-1936   355.30 1807.10
7332-1937   469.90 2676.30
7342-1938   262.30 1801.90
7352-1939   230.40 1957.30
7362-1940   361.60 2202.90
7372-1941   472.80 2380.50
7382-1942   445.60 2168.60
7392-1943   361.60 1985.10
7402-1944   288.20 1813.90
7412-1945   258.70 1850.20
7422-1946   420.30 2067.70
7432-1947   420.50 1796.70
7442-1948   494.50 1625.80
7452-1949   405.10 1667.00
7462-1950   418.80 1677.40
7472-1951   588.20 2289.50
7482-1952   645.50 2159.40
7492-1953   641.00 2031.30
7502-1954   459.30 2115.50
7513-1935    33.10 1170.60
7523-1936    45.00 2015.80
7533-1937    77.20 2803.30
7543-1938    44.60 2039.70
7553-1939    48.10 2256.20
7563-1940    74.40 2132.20
7573-1941   113.00 1834.10
7583-1942    91.90 1588.00
7593-1943    61.30 1749.40
7603-1944    56.80 1687.20
7613-1945    93.60 2007.70
7623-1946   159.90 2208.30
7633-1947   147.20 1656.70
7643-1948   146.30 1604.40
7653-1949    98.30 1431.80
7663-1950    93.50 1610.50
7673-1951   135.20 1819.40
7683-1952   157.30 2079.70
7693-1953   179.50 2371.60
7703-1954   189.60 2759.90
7714-1935    40.29  417.50
7724-1936    72.76  837.80
7734-1937    66.26  883.90
7744-1938    51.60  437.90
7754-1939    52.41  679.70
7764-1940    69.41  727.80
7774-1941    68.35  643.60
7784-1942    46.80  410.90
7794-1943    47.40  588.40
7804-1944    59.57  698.40
7814-1945    88.78  846.40
7824-1946    74.12  893.80
7834-1947    62.68  579.00
7844-1948    89.36  694.60
7854-1949    78.98  590.30
7864-1950   100.66  693.50
7874-1951   160.62  809.00
7884-1952   145.00  727.00
7894-1953   174.93 1001.50
7904-1954   172.49  703.20
7915-1935    39.68  157.70
7925-1936    50.73  167.90
7935-1937    74.24  192.90
7945-1938    53.51  156.70
7955-1939    42.65  191.40
7965-1940    46.48  185.50
7975-1941    61.40  199.60
7985-1942    39.67  189.50
7995-1943    62.24  151.20
8005-1944    52.32  187.70
8015-1945    63.21  214.70
8025-1946    59.37  232.90
8035-1947    58.02  249.00
8045-1948    70.34  224.50
8055-1949    67.42  237.30
8065-1950    55.74  240.10
8075-1951    80.30  327.30
8085-1952    85.40  359.40
8095-1953    91.90  398.40
8105-1954    81.43  365.70
8116-1935    20.36  197.00
8126-1936    25.98  210.30
8136-1937    25.94  223.10
8146-1938    27.53  216.70
8156-1939    24.60  286.40
8166-1940    28.54  298.00
8176-1941    43.41  276.90
8186-1942    42.81  272.60
8196-1943    27.84  287.40
8206-1944    32.60  330.30
8216-1945    39.03  324.40
8226-1946    50.17  401.90
8236-1947    51.85  407.40
8246-1948    64.03  409.20
8256-1949    68.16  482.20
8266-1950    77.34  673.80
8276-1951    95.30  676.90
8286-1952    99.49  702.00
8296-1953   127.52  793.50
8306-1954   135.72  927.30
8317-1935    24.43  138.00
8327-1936    23.21  200.10
8337-1937    32.78  210.10
8347-1938    32.54  161.20
8357-1939    26.65  161.70
8367-1940    33.71  145.10
8377-1941    43.50  110.60
8387-1942    34.46   98.10
8397-1943    44.28  108.80
8407-1944    70.80  118.20
8417-1945    44.12  126.50
8427-1946    48.98  156.70
8437-1947    48.51  119.40
8447-1948    50.00  129.10
8457-1949    50.59  134.80
8467-1950    42.53  140.80
8477-1951    64.77  179.00
8487-1952    72.68  178.10
8497-1953    73.86  186.80
8507-1954    89.51  192.70
8518-1935    12.93  191.50
8528-1936    25.90  516.00
8538-1937    35.05  729.00
8548-1938    22.89  560.40
8558-1939    18.84  519.90
8568-1940    28.57  628.50
8578-1941    48.51  537.10
8588-1942    43.34  561.20
8598-1943    37.02  617.20
8608-1944    37.81  626.70
8618-1945    39.27  737.20
8628-1946    53.46  760.50
8638-1947    55.56  581.40
8648-1948    49.56  662.30
8658-1949    32.04  583.80
8668-1950    32.24  635.20
8678-1951    54.38  723.80
8688-1952    71.78  864.10
8698-1953    90.08 1193.50
8708-1954    68.60 1188.90
8719-1935    26.63  290.60
8729-1936    23.39  291.10
8739-1937    30.65  335.00
8749-1938    20.89  246.00
8759-1939    28.78  356.20
8769-1940    26.93  289.80
8779-1941    32.08  268.20
8789-1942    32.21  213.30
8799-1943    35.69  348.20
8809-1944    62.47  374.20
8819-1945    52.32  387.20
8829-1946    56.95  347.40
8839-1947    54.32  291.90
8849-1948    40.53  297.20
8859-1949    32.54  276.90
8869-1950    43.48  274.60
8879-1951    56.49  339.90
8889-1952    65.98  474.80
8899-1953    66.11  496.00
8909-1954    49.34  474.50
89110-1935    2.54   70.91
89210-1936    2.00   87.94
89310-1937    2.19   82.20
89410-1938    1.99   58.72
89510-1939    2.03   80.54
89610-1940    1.81   86.47
89710-1941    2.14   77.68
89810-1942    1.86   62.16
89910-1943    0.93   62.24
90010-1944    1.18   61.82
90110-1945    1.36   65.85
90210-1946    2.24   69.54
90310-1947    3.81   64.97
90410-1948    5.66   68.00
90510-1949    4.21   71.24
90610-1950    3.42   69.05
90710-1951    4.67   83.04
90810-1952    6.00   74.42
90910-1953    6.53   63.51
91010-1954    5.12   58.12
911> model.matrix(fe_model)
912            value
9131-1935  -1255.345
9141-1936    327.855
9151-1937   1053.255
9161-1938  -1541.645
9171-1939    -20.645
9181-1940    310.055
9191-1941    217.355
9201-1942  -1089.745
9211-1943   -280.145
9221-1944     45.455
9231-1945    507.055
9241-1946    567.055
9251-1947   -807.345
9261-1948  -1079.145
9271-1949   -633.645
9281-1950   -578.245
9291-1951    499.155
9301-1952    591.055
9311-1953   1907.855
9321-1954   1259.755
9332-1935   -609.425
9342-1936   -164.725
9352-1937    704.475
9362-1938   -169.925
9372-1939    -14.525
9382-1940    231.075
9392-1941    408.675
9402-1942    196.775
9412-1943     13.275
9422-1944   -157.925
9432-1945   -121.625
9442-1946     95.875
9452-1947   -175.125
9462-1948   -346.025
9472-1949   -304.825
9482-1950   -294.425
9492-1951    317.675
9502-1952    187.575
9512-1953     59.475
9522-1954    143.675
9533-1935   -770.725
9543-1936     74.475
9553-1937    861.975
9563-1938     98.375
9573-1939    314.875
9583-1940    190.875
9593-1941   -107.225
9603-1942   -353.325
9613-1943   -191.925
9623-1944   -254.125
9633-1945     66.375
9643-1946    266.975
9653-1947   -284.625
9663-1948   -336.925
9673-1949   -509.525
9683-1950   -330.825
9693-1951   -121.925
9703-1952    138.375
9713-1953    430.275
9723-1954    818.575
9734-1935   -275.710
9744-1936    144.590
9754-1937    190.690
9764-1938   -255.310
9774-1939    -13.510
9784-1940     34.590
9794-1941    -49.610
9804-1942   -282.310
9814-1943   -104.810
9824-1944      5.190
9834-1945    153.190
9844-1946    200.590
9854-1947   -114.210
9864-1948      1.390
9874-1949   -102.910
9884-1950      0.290
9894-1951    115.790
9904-1952     33.790
9914-1953    308.290
9924-1954      9.990
9935-1935    -73.770
9945-1936    -63.570
9955-1937    -38.570
9965-1938    -74.770
9975-1939    -40.070
9985-1940    -45.970
9995-1941    -31.870
10005-1942    -41.970
10015-1943    -80.270
10025-1944    -43.770
10035-1945    -16.770
10045-1946      1.430
10055-1947     17.530
10065-1948     -6.970
10075-1949      5.830
10085-1950      8.630
10095-1951     95.830
10105-1952    127.930
10115-1953    166.930
10125-1954    134.230
10136-1935   -222.865
10146-1936   -209.565
10156-1937   -196.765
10166-1938   -203.165
10176-1939   -133.465
10186-1940   -121.865
10196-1941   -142.965
10206-1942   -147.265
10216-1943   -132.465
10226-1944    -89.565
10236-1945    -95.465
10246-1946    -17.965
10256-1947    -12.465
10266-1948    -10.665
10276-1949     62.335
10286-1950    253.935
10296-1951    257.035
10306-1952    282.135
10316-1953    373.635
10326-1954    507.435
10337-1935    -11.790
10347-1936     50.310
10357-1937     60.310
10367-1938     11.410
10377-1939     11.910
10387-1940     -4.690
10397-1941    -39.190
10407-1942    -51.690
10417-1943    -40.990
10427-1944    -31.590
10437-1945    -23.290
10447-1946      6.910
10457-1947    -30.390
10467-1948    -20.690
10477-1949    -14.990
10487-1950     -8.990
10497-1951     29.210
10507-1952     28.310
10517-1953     37.010
10527-1954     42.910
10538-1935   -479.410
10548-1936   -154.910
10558-1937     58.090
10568-1938   -110.510
10578-1939   -151.010
10588-1940    -42.410
10598-1941   -133.810
10608-1942   -109.710
10618-1943    -53.710
10628-1944    -44.210
10638-1945     66.290
10648-1946     89.590
10658-1947    -89.510
10668-1948     -8.610
10678-1949    -87.110
10688-1950    -35.710
10698-1951     52.890
10708-1952    193.190
10718-1953    522.590
10728-1954    517.990
10739-1935    -43.050
10749-1936    -42.550
10759-1937      1.350
10769-1938    -87.650
10779-1939     22.550
10789-1940    -43.850
10799-1941    -65.450
10809-1942   -120.350
10819-1943     14.550
10829-1944     40.550
10839-1945     53.550
10849-1946     13.750
10859-1947    -41.750
10869-1948    -36.450
10879-1949    -56.750
10889-1950    -59.050
10899-1951      6.250
10909-1952    141.150
10919-1953    162.350
10929-1954    140.850
109310-1935    -0.011
109410-1936    17.019
109510-1937    11.279
109610-1938   -12.201
109710-1939     9.619
109810-1940    15.549
109910-1941     6.759
110010-1942    -8.761
110110-1943    -8.681
110210-1944    -9.101
110310-1945    -5.071
110410-1946    -1.381
110510-1947    -5.951
110610-1948    -2.921
110710-1949     0.319
110810-1950    -1.871
110910-1951    12.119
111010-1952     3.499
111110-1953    -7.411
111210-1954   -12.801
1113attr(,"assign")
1114[1] 0 1
1115attr(,"index")
1116    firm year
11171      1 1935
11182      1 1936
11193      1 1937
11204      1 1938
11215      1 1939
11226      1 1940
11237      1 1941
11248      1 1942
11259      1 1943
112610     1 1944
112711     1 1945
112812     1 1946
112913     1 1947
113014     1 1948
113115     1 1949
113216     1 1950
113317     1 1951
113418     1 1952
113519     1 1953
113620     1 1954
113721     2 1935
113822     2 1936
113923     2 1937
114024     2 1938
114125     2 1939
114226     2 1940
114327     2 1941
114428     2 1942
114529     2 1943
114630     2 1944
114731     2 1945
114832     2 1946
114933     2 1947
115034     2 1948
115135     2 1949
115236     2 1950
115337     2 1951
115438     2 1952
115539     2 1953
115640     2 1954
115741     3 1935
115842     3 1936
115943     3 1937
116044     3 1938
116145     3 1939
116246     3 1940
116347     3 1941
116448     3 1942
116549     3 1943
116650     3 1944
116751     3 1945
116852     3 1946
116953     3 1947
117054     3 1948
117155     3 1949
117256     3 1950
117357     3 1951
117458     3 1952
117559     3 1953
117660     3 1954
117761     4 1935
117862     4 1936
117963     4 1937
118064     4 1938
118165     4 1939
118266     4 1940
118367     4 1941
118468     4 1942
118569     4 1943
118670     4 1944
118771     4 1945
118872     4 1946
118973     4 1947
119074     4 1948
119175     4 1949
119276     4 1950
119377     4 1951
119478     4 1952
119579     4 1953
119680     4 1954
119781     5 1935
119882     5 1936
119983     5 1937
120084     5 1938
120185     5 1939
120286     5 1940
120387     5 1941
120488     5 1942
120589     5 1943
120690     5 1944
120791     5 1945
120892     5 1946
120993     5 1947
121094     5 1948
121195     5 1949
121296     5 1950
121397     5 1951
121498     5 1952
121599     5 1953
1216100    5 1954
1217101    6 1935
1218102    6 1936
1219103    6 1937
1220104    6 1938
1221105    6 1939
1222106    6 1940
1223107    6 1941
1224108    6 1942
1225109    6 1943
1226110    6 1944
1227111    6 1945
1228112    6 1946
1229113    6 1947
1230114    6 1948
1231115    6 1949
1232116    6 1950
1233117    6 1951
1234118    6 1952
1235119    6 1953
1236120    6 1954
1237121    7 1935
1238122    7 1936
1239123    7 1937
1240124    7 1938
1241125    7 1939
1242126    7 1940
1243127    7 1941
1244128    7 1942
1245129    7 1943
1246130    7 1944
1247131    7 1945
1248132    7 1946
1249133    7 1947
1250134    7 1948
1251135    7 1949
1252136    7 1950
1253137    7 1951
1254138    7 1952
1255139    7 1953
1256140    7 1954
1257141    8 1935
1258142    8 1936
1259143    8 1937
1260144    8 1938
1261145    8 1939
1262146    8 1940
1263147    8 1941
1264148    8 1942
1265149    8 1943
1266150    8 1944
1267151    8 1945
1268152    8 1946
1269153    8 1947
1270154    8 1948
1271155    8 1949
1272156    8 1950
1273157    8 1951
1274158    8 1952
1275159    8 1953
1276160    8 1954
1277161    9 1935
1278162    9 1936
1279163    9 1937
1280164    9 1938
1281165    9 1939
1282166    9 1940
1283167    9 1941
1284168    9 1942
1285169    9 1943
1286170    9 1944
1287171    9 1945
1288172    9 1946
1289173    9 1947
1290174    9 1948
1291175    9 1949
1292176    9 1950
1293177    9 1951
1294178    9 1952
1295179    9 1953
1296180    9 1954
1297181   10 1935
1298182   10 1936
1299183   10 1937
1300184   10 1938
1301185   10 1939
1302186   10 1940
1303187   10 1941
1304188   10 1942
1305189   10 1943
1306190   10 1944
1307191   10 1945
1308192   10 1946
1309193   10 1947
1310194   10 1948
1311195   10 1949
1312196   10 1950
1313197   10 1951
1314198   10 1952
1315199   10 1953
1316200   10 1954
1317>
1318> # same as constructed before
1319> all.equal(mf, model.frame(fe_model), check.attributes = FALSE) # TRUE
1320[1] TRUE
1321> all.equal(modmat, model.matrix(fe_model), check.attributes = FALSE) # TRUE
1322[1] TRUE
1323>
1324>
1325> ## pmodel.response
1326>
1327> form <- inv ~ value + capital
1328> mf <- model.frame(pGrunfeld, form)
1329> # construct (transformed) response of the within model
1330> resp <- pmodel.response(form, data = mf, model = "within", effect = "individual")
1331> # retrieve (transformed) response directly from model frame
1332> resp_mf <- pmodel.response(mf, model = "within", effect = "individual")
1333>
1334> # retrieve (transformed) response from a plm object, i.e., an estimated model
1335> fe_model <- plm(form, data = pGrunfeld, model = "within")
1336> pmodel.response(fe_model)
1337   1-1935    1-1936    1-1937    1-1938    1-1939    1-1940    1-1941    1-1942
1338-290.4200 -216.2200 -197.4200 -350.3200 -277.2200 -146.8200  -96.0200 -160.0200
1339   1-1943    1-1944    1-1945    1-1946    1-1947    1-1948    1-1949    1-1950
1340-108.4200  -60.5200  -46.8200   80.0800  -39.1200  -78.8200  -52.9200   34.8800
1341   1-1951    1-1952    1-1953    1-1954    2-1935    2-1936    2-1937    2-1938
1342 147.8800  283.1800  696.3800  878.6800 -200.5750  -55.1750   59.4250 -148.1750
1343   2-1939    2-1940    2-1941    2-1942    2-1943    2-1944    2-1945    2-1946
1344-180.0750  -48.8750   62.3250   35.1250  -48.8750 -122.2750 -151.7750    9.8250
1345   2-1947    2-1948    2-1949    2-1950    2-1951    2-1952    2-1953    2-1954
1346  10.0250   84.0250   -5.3750    8.3250  177.7250  235.0250  230.5250   48.8250
1347   3-1935    3-1936    3-1937    3-1938    3-1939    3-1940    3-1941    3-1942
1348 -69.1900  -57.2900  -25.0900  -57.6900  -54.1900  -27.8900   10.7100  -10.3900
1349   3-1943    3-1944    3-1945    3-1946    3-1947    3-1948    3-1949    3-1950
1350 -40.9900  -45.4900   -8.6900   57.6100   44.9100   44.0100   -3.9900   -8.7900
1351   3-1951    3-1952    3-1953    3-1954    4-1935    4-1936    4-1937    4-1938
1352  32.9100   55.0100   77.2100   87.3100  -45.8335  -13.3635  -19.8635  -34.5235
1353   4-1939    4-1940    4-1941    4-1942    4-1943    4-1944    4-1945    4-1946
1354 -33.7135  -16.7135  -17.7735  -39.3235  -38.7235  -26.5535    2.6565  -12.0035
1355   4-1947    4-1948    4-1949    4-1950    4-1951    4-1952    4-1953    4-1954
1356 -23.4435    3.2365   -7.1435   14.5365   74.4965   58.8765   88.8065   86.3665
1357   5-1935    5-1936    5-1937    5-1938    5-1939    5-1940    5-1941    5-1942
1358 -22.1225  -11.0725   12.4375   -8.2925  -19.1525  -15.3225   -0.4025  -22.1325
1359   5-1943    5-1944    5-1945    5-1946    5-1947    5-1948    5-1949    5-1950
1360   0.4375   -9.4825    1.4075   -2.4325   -3.7825    8.5375    5.6175   -6.0625
1361   5-1951    5-1952    5-1953    5-1954    6-1935    6-1936    6-1937    6-1938
1362  18.4975   23.5975   30.0975   19.6275  -35.0510  -29.4310  -29.4710  -27.8810
1363   6-1939    6-1940    6-1941    6-1942    6-1943    6-1944    6-1945    6-1946
1364 -30.8110  -26.8710  -12.0010  -12.6010  -27.5710  -22.8110  -16.3810   -5.2410
1365   6-1947    6-1948    6-1949    6-1950    6-1951    6-1952    6-1953    6-1954
1366  -3.5610    8.6190   12.7490   21.9290   39.8890   44.0790   72.1090   80.3090
1367   7-1935    7-1936    7-1937    7-1938    7-1939    7-1940    7-1941    7-1942
1368 -23.1655  -24.3855  -14.8155  -15.0555  -20.9455  -13.8855   -4.0955  -13.1355
1369   7-1943    7-1944    7-1945    7-1946    7-1947    7-1948    7-1949    7-1950
1370  -3.3155   23.2045   -3.4755    1.3845    0.9145    2.4045    2.9945   -5.0655
1371   7-1951    7-1952    7-1953    7-1954    8-1935    8-1936    8-1937    8-1938
1372  17.1745   25.0845   26.2645   41.9145  -29.9615  -16.9915   -7.8415  -20.0015
1373   8-1939    8-1940    8-1941    8-1942    8-1943    8-1944    8-1945    8-1946
1374 -24.0515  -14.3215    5.6185    0.4485   -5.8715   -5.0815   -3.6215   10.5685
1375   8-1947    8-1948    8-1949    8-1950    8-1951    8-1952    8-1953    8-1954
1376  12.6685    6.6685  -10.8515  -10.6515   11.4885   28.8885   47.1885   25.7085
1377   9-1935    9-1936    9-1937    9-1938    9-1939    9-1940    9-1941    9-1942
1378 -15.2590  -18.4990  -11.2390  -20.9990  -13.1090  -14.9590   -9.8090   -9.6790
1379   9-1943    9-1944    9-1945    9-1946    9-1947    9-1948    9-1949    9-1950
1380  -6.1990   20.5810   10.4310   15.0610   12.4310   -1.3590   -9.3490    1.5910
1381   9-1951    9-1952    9-1953    9-1954   10-1935   10-1936   10-1937   10-1938
1382  14.6010   24.0910   24.2210    7.4510   -0.5445   -1.0845   -0.8945   -1.0945
1383  10-1939   10-1940   10-1941   10-1942   10-1943   10-1944   10-1945   10-1946
1384  -1.0545   -1.2745   -0.9445   -1.2245   -2.1545   -1.9045   -1.7245   -0.8445
1385  10-1947   10-1948   10-1949   10-1950   10-1951   10-1952   10-1953   10-1954
1386   0.7255    2.5755    1.1255    0.3355    1.5855    2.9155    3.4455    2.0355
1387>
1388> # same as constructed before
1389> all.equal(resp, pmodel.response(fe_model), check.attributes = FALSE) # TRUE
1390[1] TRUE
1391>
1392>
1393>
1394> ## nobs
1395> z <- plm(log(gsp)~log(pcap)+log(pc)+log(emp)+unemp,data=Produc,
1396+          model="random", subset = gsp > 5000)
1397>
1398> nobs(z)       # total observations used in estimation
1399[1] 808
1400> pdim(z)$nT$N  # same information
1401[1] 808
1402> pdim(z)       # more information about the dimensions (no. of individuals and time periods)
1403Unbalanced Panel: n = 48, T = 9-17, N = 808
1404>
1405> # illustrate difference between nobs and pdim for first-difference model
1406> data("Grunfeld", package = "plm")
1407> fdmod <- plm(inv ~ value + capital, data = Grunfeld, model = "fd")
1408> nobs(fdmod)      # 190
1409[1] 190
1410> pdim(fdmod)$nT$N # 200
1411[1] 200
1412>
1413> ## pgmm
1414> ## Arellano and Bond (1991), table 4 col. b
1415> z1 <- pgmm(log(emp) ~ lag(log(emp), 1:2) + lag(log(wage), 0:1)
1416+            + log(capital) + lag(log(output), 0:1) | lag(log(emp), 2:99),
1417+            data = EmplUK, effect = "twoways", model = "twosteps")
1418> summary(z1, robust = FALSE)
1419Twoways effects Two-steps model Difference GMM
1420
1421Call:
1422pgmm(formula = log(emp) ~ lag(log(emp), 1:2) + lag(log(wage),
1423    0:1) + log(capital) + lag(log(output), 0:1) | lag(log(emp),
1424    2:99), data = EmplUK, effect = "twoways", model = "twosteps")
1425
1426Unbalanced Panel: n = 140, T = 7-9, N = 1031
1427
1428Number of Observations Used: 611
1429Residuals:
1430      Min.    1st Qu.     Median       Mean    3rd Qu.       Max.
1431-0.6190677 -0.0255683  0.0000000 -0.0001339  0.0332013  0.6410272
1432
1433Coefficients:
1434                        Estimate Std. Error  z-value  Pr(>|z|)
1435lag(log(emp), 1:2)1     0.474151   0.085303   5.5584 2.722e-08 ***
1436lag(log(emp), 1:2)2    -0.052967   0.027284  -1.9413 0.0522200 .
1437lag(log(wage), 0:1)0   -0.513205   0.049345 -10.4003 < 2.2e-16 ***
1438lag(log(wage), 0:1)1    0.224640   0.080063   2.8058 0.0050192 **
1439log(capital)            0.292723   0.039463   7.4177 1.191e-13 ***
1440lag(log(output), 0:1)0  0.609775   0.108524   5.6188 1.923e-08 ***
1441lag(log(output), 0:1)1 -0.446373   0.124815  -3.5763 0.0003485 ***
1442---
1443Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
1444
1445Sargan test: chisq(25) = 30.11247 (p-value = 0.22011)
1446Autocorrelation test (1): normal = -2.427829 (p-value = 0.01519)
1447Autocorrelation test (2): normal = -0.3325401 (p-value = 0.73948)
1448Wald test for coefficients: chisq(7) = 371.9877 (p-value = < 2.22e-16)
1449Wald test for time dummies: chisq(6) = 26.9045 (p-value = 0.0001509)
1450>
1451> ## Blundell and Bond (1998) table 4 (cf. DPD for OX p. 12 col. 4)
1452> z2 <- pgmm(log(emp) ~ lag(log(emp), 1)+ lag(log(wage), 0:1) +
1453+              lag(log(capital), 0:1) | lag(log(emp), 2:99) +
1454+              lag(log(wage), 2:99) + lag(log(capital), 2:99),
1455+            data = EmplUK, effect = "twoways", model = "onestep",
1456+            transformation = "ld")
1457> summary(z2, robust = TRUE)
1458Twoways effects One-step model System GMM
1459
1460Call:
1461pgmm(formula = log(emp) ~ lag(log(emp), 1) + lag(log(wage), 0:1) +
1462    lag(log(capital), 0:1) | lag(log(emp), 2:99) + lag(log(wage),
1463    2:99) + lag(log(capital), 2:99), data = EmplUK, effect = "twoways",
1464    model = "onestep", transformation = "ld")
1465
1466Unbalanced Panel: n = 140, T = 7-9, N = 1031
1467
1468Number of Observations Used: 1642
1469Residuals:
1470      Min.    1st Qu.     Median       Mean    3rd Qu.       Max.
1471-0.7530341 -0.0369030  0.0000000  0.0002882  0.0466069  0.6001503
1472
1473Coefficients:
1474                         Estimate Std. Error z-value  Pr(>|z|)
1475lag(log(emp), 1)         0.935605   0.026295 35.5810 < 2.2e-16 ***
1476lag(log(wage), 0:1)0    -0.630976   0.118054 -5.3448 9.050e-08 ***
1477lag(log(wage), 0:1)1     0.482620   0.136887  3.5257 0.0004224 ***
1478lag(log(capital), 0:1)0  0.483930   0.053867  8.9838 < 2.2e-16 ***
1479lag(log(capital), 0:1)1 -0.424393   0.058479 -7.2572 3.952e-13 ***
1480---
1481Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
1482
1483Sargan test: chisq(100) = 118.763 (p-value = 0.097096)
1484Autocorrelation test (1): normal = -4.808434 (p-value = 1.5212e-06)
1485Autocorrelation test (2): normal = -0.2800133 (p-value = 0.77947)
1486Wald test for coefficients: chisq(5) = 11174.82 (p-value = < 2.22e-16)
1487Wald test for time dummies: chisq(7) = 14.71138 (p-value = 0.039882)
1488>
1489> # Same with the old formula or dynformula interface
1490> # Arellano and Bond (1991), table 4, col. b
1491> z1 <- pgmm(log(emp) ~ log(wage) + log(capital) + log(output),
1492+              lag.form = list(2,1,0,1), data = EmplUK,
1493+              effect = "twoways", model = "twosteps",
1494+              gmm.inst = ~log(emp), lag.gmm = list(c(2,99)))
1495Warning messages:
14961: use of 'dynformula()' is deprecated, use a multi-part formula instead
14972: use of 'dynformula()' is deprecated, use a multi-part formula instead
1498> summary(z1, robust = FALSE)
1499Twoways effects Two-steps model Difference GMM
1500
1501Call:
1502pgmm(formula = log(emp) ~ log(wage) + log(capital) + log(output),
1503    data = EmplUK, effect = "twoways", model = "twosteps", lag.form = list(2,
1504        1, 0, 1), gmm.inst = ~log(emp), lag.gmm = list(c(2, 99)))
1505
1506Unbalanced Panel: n = 140, T = 7-9, N = 1031
1507
1508Number of Observations Used: 611
1509Residuals:
1510      Min.    1st Qu.     Median       Mean    3rd Qu.       Max.
1511-0.6190677 -0.0255683  0.0000000 -0.0001339  0.0332013  0.6410272
1512
1513Coefficients:
1514                         Estimate Std. Error  z-value  Pr(>|z|)
1515lag(log(emp), c(1, 2))1  0.474151   0.085303   5.5584 2.722e-08 ***
1516lag(log(emp), c(1, 2))2 -0.052967   0.027284  -1.9413 0.0522200 .
1517log(wage)               -0.513205   0.049345 -10.4003 < 2.2e-16 ***
1518lag(log(wage), 1)        0.224640   0.080063   2.8058 0.0050192 **
1519log(capital)             0.292723   0.039463   7.4177 1.191e-13 ***
1520log(output)              0.609775   0.108524   5.6188 1.923e-08 ***
1521lag(log(output), 1)     -0.446373   0.124815  -3.5763 0.0003485 ***
1522---
1523Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
1524
1525Sargan test: chisq(25) = 30.11247 (p-value = 0.22011)
1526Autocorrelation test (1): normal = -2.427829 (p-value = 0.01519)
1527Autocorrelation test (2): normal = -0.3325401 (p-value = 0.73948)
1528Wald test for coefficients: chisq(7) = 371.9877 (p-value = < 2.22e-16)
1529Wald test for time dummies: chisq(6) = 26.9045 (p-value = 0.0001509)
1530>
1531> ## Blundell and Bond (1998) table 4 (cf DPD for OX p. 12 col. 4)
1532> z2 <- pgmm(dynformula(log(emp) ~ log(wage) + log(capital), list(1,1,1)),
1533+              data = EmplUK, effect = "twoways", model = "onestep",
1534+              gmm.inst = ~log(emp) + log(wage) + log(capital),
1535+              lag.gmm = c(2,99), transformation = "ld")
1536Warning messages:
15371: use of 'dynformula()' is deprecated, use a multi-part formula instead
15382: use of 'dynformula()' is deprecated, use a multi-part formula instead
1539> summary(z2, robust = TRUE)
1540Twoways effects One-step model System GMM
1541
1542Call:
1543pgmm(formula = dynformula(log(emp) ~ log(wage) + log(capital),
1544    list(1, 1, 1)), data = EmplUK, effect = "twoways", model = "onestep",
1545    transformation = "ld", gmm.inst = ~log(emp) + log(wage) +
1546        log(capital), lag.gmm = c(2, 99))
1547
1548Unbalanced Panel: n = 140, T = 7-9, N = 1031
1549
1550Number of Observations Used: 1642
1551Residuals:
1552      Min.    1st Qu.     Median       Mean    3rd Qu.       Max.
1553-0.7530341 -0.0369030  0.0000000  0.0002882  0.0466069  0.6001503
1554
1555Coefficients:
1556                      Estimate Std. Error z-value  Pr(>|z|)
1557lag(log(emp), 1)      0.935605   0.026295 35.5810 < 2.2e-16 ***
1558log(wage)            -0.630976   0.118054 -5.3448 9.050e-08 ***
1559lag(log(wage), 1)     0.482620   0.136887  3.5257 0.0004224 ***
1560log(capital)          0.483930   0.053867  8.9838 < 2.2e-16 ***
1561lag(log(capital), 1) -0.424393   0.058479 -7.2572 3.952e-13 ***
1562---
1563Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
1564
1565Sargan test: chisq(100) = 118.763 (p-value = 0.097096)
1566Autocorrelation test (1): normal = -4.808434 (p-value = 1.5212e-06)
1567Autocorrelation test (2): normal = -0.2800133 (p-value = 0.77947)
1568Wald test for coefficients: chisq(5) = 11174.82 (p-value = < 2.22e-16)
1569Wald test for time dummies: chisq(7) = 14.71138 (p-value = 0.039882)
1570>
1571> ## pht (deprecated)
1572> # deprecated way with pht() for HT
1573> data("Wages", package = "plm")
1574> ht <- pht(lwage ~ wks + south + smsa + married + exp + I(exp^2) +
1575+          bluecol + ind + union + sex + black + ed |
1576+          sex + black + bluecol + south + smsa + ind,
1577+          data = Wages, model = "ht", index = 595)
1578Warning message:
1579uses of 'pht()' and 'plm(., model = "ht")' are discouraged, better use 'plm(., model = "random", random.method = "ht", inst.method = "baltagi"/"am"/"bms")' for Hausman-Taylor, Amemiya-MaCurdy, and Breusch-Mizon-Schmidt estimator
1580> summary(ht)
1581Oneway (individual) effect Hausman-Taylor Model
1582(Hausman-Taylor estimator)
1583
1584Call:
1585pht(formula = lwage ~ wks + south + smsa + married + exp + I(exp^2) +
1586    bluecol + ind + union + sex + black + ed | sex + black +
1587    bluecol + south + smsa + ind, data = Wages, model = "ht",
1588    index = 595)
1589
1590T.V. exo  : bluecol, south, smsa, ind
1591T.V. endo : wks, married, exp, I(exp^2), union
1592T.I. exo  : sex, black
1593T.I. endo : ed
1594
1595Balanced Panel: n = 595, T = 7, N = 4165
1596
1597Effects:
1598                  var std.dev share
1599idiosyncratic 0.02304 0.15180 0.025
1600individual    0.88699 0.94180 0.975
1601theta: 0.9392
1602
1603Residuals:
1604      Min.    1st Qu.     Median    3rd Qu.       Max.
1605-1.9193535 -0.0707404  0.0065708  0.0796568  2.0250882
1606
1607Coefficients:
1608               Estimate  Std. Error z-value  Pr(>|z|)
1609(Intercept)  2.9127e+00  2.8365e-01 10.2687 < 2.2e-16 ***
1610wks          8.3740e-04  5.9973e-04  1.3963   0.16263
1611southyes     7.4398e-03  3.1955e-02  0.2328   0.81590
1612smsayes     -4.1833e-02  1.8958e-02 -2.2066   0.02734 *
1613marriedyes  -2.9851e-02  1.8980e-02 -1.5728   0.11578
1614exp          1.1313e-01  2.4710e-03 45.7851 < 2.2e-16 ***
1615I(exp^2)    -4.1886e-04  5.4598e-05 -7.6718 1.696e-14 ***
1616bluecolyes  -2.0705e-02  1.3781e-02 -1.5024   0.13299
1617ind          1.3604e-02  1.5237e-02  0.8928   0.37196
1618unionyes     3.2771e-02  1.4908e-02  2.1982   0.02794 *
1619sexfemale   -1.3092e-01  1.2666e-01 -1.0337   0.30129
1620blackyes    -2.8575e-01  1.5570e-01 -1.8352   0.06647 .
1621ed           1.3794e-01  2.1248e-02  6.4919 8.474e-11 ***
1622---
1623Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
1624
1625Total Sum of Squares:    886.9
1626Residual Sum of Squares: 95.947
1627Chisq: 6891.87 on 12 DF, p-value: < 2.22e-16
1628>
1629> am <- pht(lwage ~ wks + south + smsa + married + exp + I(exp^2) +
1630+          bluecol + ind + union + sex + black + ed |
1631+          sex + black + bluecol + south + smsa + ind,
1632+          data = Wages, model = "am", index = 595)
1633Warning message:
1634uses of 'pht()' and 'plm(., model = "ht")' are discouraged, better use 'plm(., model = "random", random.method = "ht", inst.method = "baltagi"/"am"/"bms")' for Hausman-Taylor, Amemiya-MaCurdy, and Breusch-Mizon-Schmidt estimator
1635> summary(am)
1636Oneway (individual) effect Hausman-Taylor Model
1637(Amemiya-MaCurdy estimator)
1638
1639Call:
1640pht(formula = lwage ~ wks + south + smsa + married + exp + I(exp^2) +
1641    bluecol + ind + union + sex + black + ed | sex + black +
1642    bluecol + south + smsa + ind, data = Wages, model = "am",
1643    index = 595)
1644
1645T.V. exo  : bluecol, south, smsa, ind
1646T.V. endo : wks, married, exp, I(exp^2), union
1647T.I. exo  : sex, black
1648T.I. endo : ed
1649
1650Balanced Panel: n = 595, T = 7, N = 4165
1651
1652Effects:
1653                  var std.dev share
1654idiosyncratic 0.02304 0.15180 0.025
1655individual    0.88699 0.94180 0.975
1656theta: 0.9392
1657
1658Residuals:
1659      Min.    1st Qu.     Median    3rd Qu.       Max.
1660-1.9192710 -0.0705595  0.0065602  0.0794836  2.0248644
1661
1662Coefficients:
1663               Estimate  Std. Error z-value  Pr(>|z|)
1664(Intercept)  2.9273e+00  2.7513e-01 10.6399 < 2.2e-16 ***
1665wks          8.3806e-04  5.9945e-04  1.3980   0.16210
1666southyes     7.2818e-03  3.1936e-02  0.2280   0.81964
1667smsayes     -4.1951e-02  1.8947e-02 -2.2141   0.02682 *
1668marriedyes  -3.0089e-02  1.8967e-02 -1.5864   0.11266
1669exp          1.1297e-01  2.4688e-03 45.7584 < 2.2e-16 ***
1670I(exp^2)    -4.2140e-04  5.4554e-05 -7.7244 1.124e-14 ***
1671bluecolyes  -2.0850e-02  1.3765e-02 -1.5147   0.12986
1672ind          1.3629e-02  1.5229e-02  0.8949   0.37082
1673unionyes     3.2475e-02  1.4894e-02  2.1804   0.02922 *
1674sexfemale   -1.3201e-01  1.2660e-01 -1.0427   0.29709
1675blackyes    -2.8590e-01  1.5549e-01 -1.8388   0.06595 .
1676ed           1.3720e-01  2.0570e-02  6.6703 2.553e-11 ***
1677---
1678Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
1679
1680Total Sum of Squares:    886.9
1681Residual Sum of Squares: 95.871
1682Chisq: 6879.2 on 12 DF, p-value: < 2.22e-16
1683>
1684> ## pldv
1685> pder.avail <- if (!requireNamespace("pder", quietly = TRUE)) FALSE else TRUE
1686> if(pder.avail) {
1687+ data("Donors", package = "pder")
1688+ pDonors <- pdata.frame(Donors, index = "id")
1689+ modA <- pldv(donation ~ treatment +  prcontr, data = pDonors,
1690+              model = "random", method = "bfgs")
1691+ summary(modA)
1692+ modB <- pldv(donation ~ treatment * prcontr - prcontr, data = pDonors,
1693+            model = "random", method = "bfgs")
1694+ summary(modB)
1695+ invisible(NULL)
1696+ }
1697There were 50 or more warnings (use warnings() to see the first 50)
1698>
1699> ## pwartest
1700> pwartest(log(emp) ~ log(wage) + log(capital), data = EmplUK)
1701
1702	Wooldridge's test for serial correlation in FE panels
1703
1704data:  plm.model
1705F = 312.3, df1 = 1, df2 = 889, p-value < 2.2e-16
1706alternative hypothesis: serial correlation
1707
1708> pwartest(log(emp) ~ log(wage) + log(capital), data = EmplUK, type = "HC3")
1709
1710	Wooldridge's test for serial correlation in FE panels
1711
1712data:  plm.model
1713F = 305.17, df1 = 1, df2 = 889, p-value < 2.2e-16
1714alternative hypothesis: serial correlation
1715
1716>
1717> ## pwfdtest
1718> pwfdtest(log(emp) ~ log(wage) + log(capital), data = EmplUK)
1719
1720	Wooldridge's first-difference test for serial correlation in panels
1721
1722data:  plm.model
1723F = 1.5251, df1 = 1, df2 = 749, p-value = 0.2172
1724alternative hypothesis: serial correlation in differenced errors
1725
1726> pwfdtest(log(emp) ~ log(wage) + log(capital), data = EmplUK, h0 = "fe")
1727
1728	Wooldridge's first-difference test for serial correlation in panels
1729
1730data:  plm.model
1731F = 131.55, df1 = 1, df2 = 749, p-value < 2.2e-16
1732alternative hypothesis: serial correlation in original errors
1733
1734> pwfdtest(log(emp) ~ log(wage) + log(capital), data = EmplUK, type = "HC3", h0 = "fe")
1735
1736	Wooldridge's first-difference test for serial correlation in panels
1737
1738data:  plm.model
1739F = 123.79, df1 = 1, df2 = 749, p-value < 2.2e-16
1740alternative hypothesis: serial correlation in original errors
1741
1742>
1743> mod <- plm(log(emp) ~ log(wage) + log(capital), data = EmplUK, model = "fd")
1744> pwfdtest(mod)
1745
1746	Wooldridge's first-difference test for serial correlation in panels
1747
1748data:  mod
1749F = 1.5251, df1 = 1, df2 = 749, p-value = 0.2172
1750alternative hypothesis: serial correlation in differenced errors
1751
1752> pwfdtest(mod, h0 = "fe")
1753
1754	Wooldridge's first-difference test for serial correlation in panels
1755
1756data:  mod
1757F = 131.55, df1 = 1, df2 = 749, p-value < 2.2e-16
1758alternative hypothesis: serial correlation in original errors
1759
1760> pwfdtest(mod, type = "HC3", h0 = "fe")
1761
1762	Wooldridge's first-difference test for serial correlation in panels
1763
1764data:  mod
1765F = 123.79, df1 = 1, df2 = 749, p-value < 2.2e-16
1766alternative hypothesis: serial correlation in original errors
1767
1768>
1769> # pwtest
1770> pwtest(log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp, data = Produc)
1771
1772	Wooldridge's test for unobserved individual effects
1773
1774data:  formula
1775z = 3.9383, p-value = 8.207e-05
1776alternative hypothesis: unobserved effect
1777
1778> pwtest(log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp, data = Produc, effect = "time")
1779
1780	Wooldridge's test for unobserved time effects
1781
1782data:  formula
1783z = 1.3143, p-value = 0.1888
1784alternative hypothesis: unobserved effect
1785
1786>
1787> ## panelmodel interface
1788> # first, estimate a pooling model, than compute test statistics
1789> form <- formula(log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp)
1790> pool_prodc <- plm(form, data = Produc, model = "pooling")
1791> pwtest(pool_prodc) # == effect="individual"
1792
1793	Wooldridge's test for unobserved individual effects
1794
1795data:  formula
1796z = 3.9383, p-value = 8.207e-05
1797alternative hypothesis: unobserved effect
1798
1799> pwtest(pool_prodc, effect="time")
1800
1801	Wooldridge's test for unobserved time effects
1802
1803data:  formula
1804z = 1.3143, p-value = 0.1888
1805alternative hypothesis: unobserved effect
1806
1807>
1808> proc.time()
1809   user  system elapsed
1810  19.03    0.54   20.32
1811