def _drop_missing(self) -> NDArray: data = (self.portfolios, self.factors) missing = np.any(np.c_[[dh.isnull for dh in data]], 0) if any(missing): if all(missing): raise ValueError("All observations contain missing data. " "Model cannot be estimated.") self.portfolios.drop(missing) self.factors.drop(missing) missing_warning(missing) return missing
def _drop_missing(self) -> ndarray: data = (self.dependent, self.exog, self.endog, self.instruments, self.weights) missing = any(c_[[dh.isnull for dh in data]], 0) # type: ndarray if any(missing): if npall(missing): raise ValueError('All observations contain missing data. ' 'Model cannot be estimated.') self.dependent.drop(missing) self.exog.drop(missing) self.endog.drop(missing) self.instruments.drop(missing) self.weights.drop(missing) missing_warning(missing) return missing
def _drop_missing(self) -> ndarray: missing = to_numpy(self.dependent.isnull) missing |= to_numpy(self.exog.isnull) missing |= to_numpy(self._absorb_inter.cat.isnull().any(1)) missing |= to_numpy(self._absorb_inter.cont.isnull().any(1)) for interact in self._interaction_list: missing |= to_numpy(interact.isnull) if npany(missing): self.dependent.drop(missing) self.exog.drop(missing) self._absorb_inter.drop(missing) for interact in self._interaction_list: interact.drop(missing) missing_warning(missing) return missing
def _drop_missing(self): k = len(self._dependent) nobs = self._dependent[0].shape[0] missing = np.zeros(nobs, dtype=np.bool) for i in range(k): missing |= self._dependent[i].isnull missing |= self._exog[i].isnull missing |= self._weights[i].isnull missing_warning(missing) if np.any(missing): for i in range(k): self._dependent[i].drop(missing) self._exog[i].drop(missing) self._weights[i].drop(missing)
def test_missing_warning(): missing = np.zeros(500, dtype=np.bool) with warnings.catch_warnings(record=True) as w: missing_warning(missing) assert len(w) == 0 missing[0] = True with warnings.catch_warnings(record=True) as w: missing_warning(missing) assert len(w) == 1 original = linearmodels.WARN_ON_MISSING linearmodels.WARN_ON_MISSING = False with warnings.catch_warnings(record=True) as w: missing_warning(missing) assert len(w) == 0 linearmodels.WARN_ON_MISSING = original
import numpy as np import linearmodels as lm lm.WARN_ON_MISSING = False from linearmodels import utility utility.missing_warning(np.array([True, True, False])) from linearmodels.panel import PanelOLS, RandomEffects, PooledOLS from linearmodels.datasets import wage_panel import statsmodels.api as sm data = wage_panel.load() data = data.set_index(['nr','year']) dependent = data.lwage exog = sm.add_constant(data[['expersq','married','union']]) mod = PanelOLS(dependent, exog, entity_effects=True, time_effects=True) res = mod.fit(cov_type='unadjusted') res2 = mod.fit(cov_type='robust') exog = sm.add_constant(data[['exper', 'expersq','married','union']]) mod = PanelOLS(dependent, exog, entity_effects=True) res3 = mod.fit(cov_type='clustered',cluster_entity=True) mod = RandomEffects(dependent, exog) res4 = mod.fit(cov_type='robust') from linearmodels.panel.results import compare exog = sm.add_constant(data[['exper', 'expersq','married','union']].copy()) import pandas as pd exog['year'] = pd.Categorical(data.reset_index()['year']) mod = PooledOLS(dependent, exog) res5 = mod.fit(cov_type='robust') print(compare([res,res2, res3, res4, res5])) print(data.columns)