Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions linearmodels/panel/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,11 +647,19 @@
Under the null, the statistic is asymptotically standard normal.

The shocks are the model's ``idiosyncratic`` values, so the weights of
a weighted model are not applied to them, and the shocks of
``FirstDifferenceOLS`` are in levels rather than the residuals of the
differenced equation. Since the correlations are computed over time,
the test assumes that the shocks are not serially correlated, and it
over-rejects if they are persistent.
a weighted model are not applied to them. The exception is
``FirstDifferenceOLS``, which uses ``resids``, the residuals of the
differenced equation, as ``plm::pcdtest`` does for a pooled regression
of the differenced data. Its ``idiosyncratic`` values are in levels,
and are persistent when the errors are, for example a random walk,
which is when first differences are used. Since the correlations are
computed over time, the test assumes that the shocks are not serially
correlated, and it over-rejects if they are persistent. Conversely, if
the errors in levels are serially uncorrelated, the residuals of
``FirstDifferenceOLS`` are negatively autocorrelated (an MA(1) with
autocorrelation -0.5) and the test over-rejects, with a size of about
11% at the nominal 5% level in large panels. The test is then better
applied to a ``PanelOLS`` model with entity effects.

The test is not valid for every model and an InapplicableTestStatistic
is returned for the following.
Expand Down Expand Up @@ -692,10 +700,15 @@
problem in testing for remaining cross-section correlation.
Journal of Business & Economic Statistics, 40(3), 1191-1203.
"""
from linearmodels.panel.model import FirstDifferenceOLS # noqa: PLC0415

reason = self._pesaran_cd_inapplicable()
if reason is not None:
return InapplicableTestStatistic(reason=reason, name="Pesaran CD test")
eps = self.idiosyncratic.iloc[:, 0]
if isinstance(self.model, FirstDifferenceOLS):
eps = self.resids
else:
eps = self.idiosyncratic.iloc[:, 0]
wide = eps.unstack(level=0)
wide = wide.loc[:, wide.notnull().any(axis=0)]
nentity = wide.shape[1]
Expand Down
Loading
Loading