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> ## tests for pcdtest
19>
20> ## test pcdtest for NaN value in result
21> ##  * due to non-intersecting pairs, fixed in rev. 339
22> ##  * due to only ony period in intersection, fixed in rev. 345
23>
24> library(plm)
25> data("Grunfeld", package = "plm")
26>
27> ## just a run test without obstacles
28> mod_pool <- plm(inv ~ value + capital, data = Grunfeld, model = "pooling")
29> testres1 <- pcdtest(mod_pool, test = "cd")
30> if (is.nan(testres1$statistic)) stop("statistic is NaN")
31> if (is.na(testres1$statistic)) stop("statistic is NA")
32> if (is.na(testres1$p.value)) stop("p-value is NA")
33>
34> ## no intersection for firm 1 and 2:
35> # firm 1 years: 1935 to 1944
36> # firm 2 years: 1945 to 1954
37> Grunfeld_no_intersect <- Grunfeld[-c(11:20, 21:30), ]
38> mod_pool_no_intersect <- plm(inv ~ value + capital, data = Grunfeld_no_intersect, model = "pooling")
39>
40> testres2 <- pcdtest(mod_pool_no_intersect, test = "cd")
41Warning message:
42In pcdres(tres = tres, n = n, w = w, form = paste(deparse(x$formula)),  :
43  Some pairs of individuals (4.4 percent) do not have any or just one time period in common and have been omitted from calculation
44> if (is.nan(testres2$statistic)) stop("statistic is NaN")
45> if (is.na(testres2$statistic)) stop("statistic is NA")
46> if (is.na(testres2$p.value)) stop("p-value is NA")
47>
48>
49> ## fixed in rev. 345
50> ## only 1 intersection for firm 1 and 2:
51> # firm 1 years: 1935 to 1945
52> # firm 2 years: 1945 to 1954
53> Grunfeld_one_intersect <- Grunfeld[-c(12:20, 20:30), ]
54> mod_pool_one_intersect <- plm(inv ~ value + capital, data = Grunfeld_one_intersect, model = "pooling")
55> testres3 <- pcdtest(mod_pool_one_intersect, test = "cd")
56Warning message:
57In pcdres(tres = tres, n = n, w = w, form = paste(deparse(x$formula)),  :
58  Some pairs of individuals (4.4 percent) do not have any or just one time period in common and have been omitted from calculation
59>
60> if (is.nan(testres3$statistic)) stop("statistic is NaN")
61> if (is.na(testres3$statistic)) stop("statistic is NA")
62> if (is.na(testres3$p.value)) stop("p-value is NA")
63>
64>
65> ## make it also unbalanced for other individuals
66> Grunfeld_no_intersect_unbal <- Grunfeld_no_intersect[-c(65:66, 71, 103:110), ]
67> mod_pool_no_intersect_unbal <- plm(inv ~ value + capital, data = Grunfeld_no_intersect_unbal, model = "pooling")
68> testres4 <- pcdtest(mod_pool_no_intersect_unbal, test = "cd")
69Warning message:
70In pcdres(tres = tres, n = n, w = w, form = paste(deparse(x$formula)),  :
71  Some pairs of individuals (4.4 percent) do not have any or just one time period in common and have been omitted from calculation
72> if (is.nan(testres4$statistic)) stop("statistic is NaN")
73> if (is.na(testres4$statistic)) stop("statistic is NA")
74> if (is.na(testres4$p.value)) stop("p-value is NA")
75>
76>
77> ## test case for regression of variable on constant
78> ## resulted in error pre rev. 342:
79> ## "Error in lm.fit(tX, ty) : 'x' must be a matrix"
80> pcdtest(value ~ 1, data = Grunfeld)
81
82	Pesaran CD test for cross-sectional dependence in panels
83
84data:  value ~ 1
85z = 13.843, p-value < 2.2e-16
86alternative hypothesis: cross-sectional dependence
87
88>
89> ## tests of local test (with arg w)
90> w <- diag(1, nrow = 10)
91> w[2,1] <- 1
92> testres5 <- pcdtest(mod_pool, test = "cd", w = w)
93> if (is.nan(testres5$statistic)) stop("statistic is NaN")
94> if (is.na(testres5$statistic)) stop("statistic is NA")
95> if (is.na(testres5$p.value)) stop("p-value is NA")
96>
97> ### should result in meaningful errors
98> ## upper and lower triangular part define different neighbours
99> # w1 <- diag(1, nrow = 10)
100> # w1[1,3] <- 1
101> # w1[2,1] <- 1
102> # pcdtest(mod_pool, test = "cd", w = w1)
103> ## wrong dimension
104> # w2 <- diag(1, nrow = 10, ncol = 11)
105> # pcdtest(mod_pool, test = "cd", w = w2)
106>
107> proc.time()
108   user  system elapsed
109   4.06    0.67    4.81
110