def test_incorrect_type(data): dependent = data.set_index(['nr', 'year']).lwage exog = sm.add_constant( data.set_index(['nr', 'year'])[['expersq', 'married', 'union']]) mod = PanelOLS(dependent, exog) res = mod.fit() mod2 = IV2SLS(mod.dependent.dataframe, mod.exog.dataframe, None, None) res2 = mod2.fit() with pytest.raises(TypeError): compare(dict(model1=res, model2=res2))
def test_incorrect_type(data): dependent = data.set_index(["nr", "year"]).lwage exog = add_constant( data.set_index(["nr", "year"])[["expersq", "married", "union"]]) mod = PanelOLS(dependent, exog) res = mod.fit() mod2 = IV2SLS(mod.dependent.dataframe, mod.exog.dataframe, None, None) res2 = mod2.fit() with pytest.raises(TypeError): compare(dict(model1=res, model2=res2))
def test_multiple_no_effects(data): dependent = data.set_index(["nr", "year"]).lwage exog = add_constant( data.set_index(["nr", "year"])[["expersq", "married", "union"]]) res = PanelOLS(dependent, exog).fit() exog = add_constant(data.set_index(["nr", "year"])[["married", "union"]]) res3 = PooledOLS(dependent, exog).fit() exog = data.set_index(["nr", "year"])[["exper"]] res4 = RandomEffects(dependent, exog).fit() comp = compare(dict(a=res, model2=res3, model3=res4)) assert len(comp.rsquared) == 3 d = dir(comp) for value in d: if value.startswith("_"): continue getattr(comp, value) compare(dict(a=res, model2=res3, model3=res4))
def test_multiple_no_effects(data): dependent = data.set_index(['nr', 'year']).lwage exog = sm.add_constant( data.set_index(['nr', 'year'])[['expersq', 'married', 'union']]) res = PanelOLS(dependent, exog).fit() exog = sm.add_constant( data.set_index(['nr', 'year'])[['married', 'union']]) res3 = PooledOLS(dependent, exog).fit() exog = data.set_index(['nr', 'year'])[['exper']] res4 = RandomEffects(dependent, exog).fit() comp = compare(dict(a=res, model2=res3, model3=res4)) assert len(comp.rsquared) == 3 d = dir(comp) for value in d: if value.startswith('_'): continue getattr(comp, value) compare(OrderedDict(a=res, model2=res3, model3=res4))
def test_single(data, precision): dependent = data.set_index(["nr", "year"]).lwage exog = add_constant( data.set_index(["nr", "year"])[["expersq", "married", "union"]]) res = PanelOLS(dependent, exog, entity_effects=True).fit() comp = compare([res]) assert len(comp.rsquared) == 1 d = dir(comp) for value in d: if value.startswith("_"): continue getattr(comp, value)
def test_single(data): dependent = data.set_index(['nr', 'year']).lwage exog = sm.add_constant( data.set_index(['nr', 'year'])[['expersq', 'married', 'union']]) res = PanelOLS(dependent, exog, entity_effects=True).fit() comp = compare([res]) assert len(comp.rsquared) == 1 d = dir(comp) for value in d: if value.startswith('_'): continue getattr(comp, value)
def test_multiple(data, precision): dependent = data.set_index(["nr", "year"]).lwage exog = add_constant( data.set_index(["nr", "year"])[["expersq", "married", "union"]]) res = PanelOLS(dependent, exog, entity_effects=True, time_effects=True).fit() res2 = PanelOLS(dependent, exog, entity_effects=True).fit(cov_type="clustered", cluster_entity=True) exog = add_constant(data.set_index(["nr", "year"])[["married", "union"]]) res3 = PooledOLS(dependent, exog).fit() exog = data.set_index(["nr", "year"])[["exper"]] res4 = RandomEffects(dependent, exog).fit() comp = compare([res, res2, res3, res4], precision=precision) assert len(comp.rsquared) == 4 d = dir(comp) for value in d: if value.startswith("_"): continue getattr(comp, value) with pytest.raises(ValueError): compare([res, res2, res3, res4], precision="unknown")
def test_multiple(data, precision): dependent = data.set_index(['nr', 'year']).lwage exog = sm.add_constant( data.set_index(['nr', 'year'])[['expersq', 'married', 'union']]) res = PanelOLS(dependent, exog, entity_effects=True, time_effects=True).fit() res2 = PanelOLS(dependent, exog, entity_effects=True).fit(cov_type='clustered', cluster_entity=True) exog = sm.add_constant( data.set_index(['nr', 'year'])[['married', 'union']]) res3 = PooledOLS(dependent, exog).fit() exog = data.set_index(['nr', 'year'])[['exper']] res4 = RandomEffects(dependent, exog).fit() comp = compare([res, res2, res3, res4], precision=precision) assert len(comp.rsquared) == 4 d = dir(comp) for value in d: if value.startswith('_'): continue getattr(comp, value) with pytest.raises(ValueError): compare([res, res2, res3, res4], precision='unknown')
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) from linearmodels.panel.data import PanelData import numpy as np import pandas as pd from statsmodels.datasets import grunfeld from linearmodels.panel.model import RandomEffects from linearmodels.tests.panel._utility import generate_data data = pd.read_stata(r'C:\git\linearmodels\linearmodels\tests\panel\results\simulated-panel.dta') data= data.set_index(['firm','time']) mod = RandomEffects(data.y, data[['intercept', 'x1','x2','x3','x4','x5']])