Skip to content

Commit 391e90b

Browse files
Jesse Farnhamjreback
Jesse Farnham
authored andcommitted
BUG: OLS with clustering and nw_lags does not error (GH5884)
Added statement to raise ValueError when OLS is run with clustering and Newey-West adjustments. Closes GH5884.
1 parent aa431bc commit 391e90b

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

doc/source/v0.15.0.txt

+7-4
Original file line numberDiff line numberDiff line change
@@ -383,17 +383,17 @@ Rolling/Expanding Moments API changes
383383

384384
rolling_sum(Series(range(4)), window=3, min_periods=0, center=True)
385385

386-
- :func:`rolling_window` now normalizes the weights properly in rolling mean mode (`mean=True`) so that
387-
the calculated weighted means (e.g. 'triang', 'gaussian') are distributed about the same means as those
388-
calculated without weighting (i.e. 'boxcar'). See :ref:`the note on normalization
386+
- :func:`rolling_window` now normalizes the weights properly in rolling mean mode (`mean=True`) so that
387+
the calculated weighted means (e.g. 'triang', 'gaussian') are distributed about the same means as those
388+
calculated without weighting (i.e. 'boxcar'). See :ref:`the note on normalization
389389
<stats.moments.normalization>` for further details. (:issue:`7618`)
390390

391391
.. ipython:: python
392392

393393
s = Series([10.5, 8.8, 11.4, 9.7, 9.3])
394394

395395
Behavior prior to 0.15.0:
396-
396+
397397
.. code-block:: python
398398

399399
In [39]: rolling_window(s, window=3, win_type='triang', center=True)
@@ -968,3 +968,6 @@ Bug Fixes
968968
- Bug where ``col_space`` was ignored in ``DataFrame.to_string()`` when ``header=False`` (:issue:`8230`).
969969

970970
- Bug in DataFrame terminal display: Setting max_column/max_rows to zero did not trigger auto-resizing of dfs to fit terminal width/height (:issue:`7180`).
971+
- Bug in OLS where running with "cluster" and "nw_lags" parameters did not work correctly, but also did not throw an error
972+
(:issue:`5884').
973+

pandas/stats/interface.py

+8
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ def ols(**kwargs):
8383
The appropriate OLS object, which allows you to obtain betas and various
8484
statistics, such as std err, t-stat, etc.
8585
"""
86+
87+
if (kwargs.get('cluster') is not None and
88+
kwargs.get('nw_lags') is not None):
89+
raise ValueError(
90+
'Pandas OLS does not work with Newey-West correction '
91+
'and clustering.')
92+
93+
8694
pool = kwargs.get('pool')
8795
if 'pool' in kwargs:
8896
del kwargs['pool']

pandas/stats/tests/test_ols.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -682,13 +682,15 @@ def testRollingWithTimeCluster(self):
682682
cluster='time')
683683

684684
def testRollingWithNeweyWestAndEntityCluster(self):
685-
self.checkMovingOLS(self.panel_x, self.panel_y,
686-
nw_lags=1, cluster='entity')
685+
self.assertRaises(ValueError, self.checkMovingOLS,
686+
self.panel_x, self.panel_y,
687+
nw_lags=1, cluster='entity')
687688

688689
def testRollingWithNeweyWestAndTimeEffectsAndEntityCluster(self):
689-
self.checkMovingOLS(self.panel_x, self.panel_y,
690-
nw_lags=1, cluster='entity',
691-
time_effects=True)
690+
self.assertRaises(ValueError,
691+
self.checkMovingOLS, self.panel_x, self.panel_y,
692+
nw_lags=1, cluster='entity',
693+
time_effects=True)
692694

693695
def testExpanding(self):
694696
self.checkMovingOLS(

0 commit comments

Comments
 (0)