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
3 changes: 2 additions & 1 deletion linearmodels/system/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def _missing_weights(
missing = [key for key in weights if weights[key] is None]
if missing:
msg = "Weights not found for equation labels:\n{}".format(", ".join(missing))
warnings.warn(msg, UserWarning)
warnings.warn(msg, UserWarning, stacklevel=2)


def _parameters_from_xprod(
Expand Down Expand Up @@ -1917,6 +1917,7 @@ def __init__(
"matrix not unadjusted (homoskedastic). sigma will "
"be ignored.",
UserWarning,
stacklevel=1,
)
weight_type = COV_TYPES[weight_type]
self._weight_est = GMM_W_EST[weight_type](**weight_config)
Expand Down
20 changes: 15 additions & 5 deletions linearmodels/tests/panel/_utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,23 @@ def generate_data(


def assert_results_equal(res1, res2, test_fit=True, test_df=True, strict=True):
from pandas import Index

def fix_index(x: Series | DataFrame, n: int):
if isinstance(x, Series):
out = x.iloc[:n].copy()
else:
out = x.iloc[:n, :n].copy()
out.index = Index(out.index.to_list())
return out

n = min(res1.params.shape[0], res2.params.shape[0])

assert_series_equal(res1.params.iloc[:n], res2.params.iloc[:n])
assert_series_equal(res1.pvalues.iloc[:n], res2.pvalues.iloc[:n])
assert_series_equal(res1.tstats.iloc[:n], res2.tstats.iloc[:n])
assert_frame_equal(res1.cov.iloc[:n, :n], res2.cov.iloc[:n, :n])
assert_frame_equal(res1.conf_int().iloc[:n], res2.conf_int().iloc[:n])
assert_series_equal(res1.params.iloc[:n], fix_index(res2.params, n))
assert_series_equal(res1.pvalues.iloc[:n], fix_index(res2.pvalues, n))
assert_series_equal(res1.tstats.iloc[:n], fix_index(res2.tstats, n))
assert_frame_equal(res1.cov.iloc[:n, :n], fix_index(res2.cov, n))
assert_frame_equal(res1.conf_int().iloc[:n], fix_index(res2.conf_int(), n))

assert_allclose(res1.s2, res2.s2)

Expand Down
28 changes: 22 additions & 6 deletions linearmodels/tests/panel/test_panel_ols.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,9 @@ def test_panel_entity_lsdv(data):
d_demean = d.values

xd = np.c_[x.values, d_demean]
xd = pd.DataFrame(xd, index=x.index, columns=list(x.columns) + list(d.columns))
xd = pd.DataFrame(
xd, index=x.index, columns=list(x.columns) + [f"fe_{col}" for col in d.columns]
)

ols_mod = IV2SLS(y, xd, None, None)
res2 = ols_mod.fit(cov_type="unadjusted", debiased=False)
Expand Down Expand Up @@ -388,7 +390,9 @@ def test_panel_time_lsdv(large_data):
d = d - z @ lstsq(z, d, rcond=None)[0]

xd = np.c_[x.values, d]
xd = pd.DataFrame(xd, index=x.index, columns=list(x.columns) + d_cols)
xd = pd.DataFrame(
xd, index=x.index, columns=list(x.columns) + [f"fe_{col}" for col in d_cols]
)

ols_mod = IV2SLS(y, xd, None, None)
res2 = ols_mod.fit(cov_type="unadjusted")
Expand Down Expand Up @@ -490,7 +494,11 @@ def test_panel_both_lsdv(data):

xd = np.c_[x.values, d]
xd = pd.DataFrame(
xd, index=x.index, columns=list(x.columns) + list(d1.columns) + list(d2.columns)
xd,
index=x.index,
columns=list(x.columns)
+ [f"fe_{col}" for col in d1.columns]
+ [f"te_{col}" for col in d2.columns],
)

ols_mod = IV2SLS(y, xd, None, None)
Expand Down Expand Up @@ -597,7 +605,9 @@ def test_panel_entity_lsdv_weighted(data):
d = d - z @ lstsq(wz, wd, rcond=None)[0]

xd = np.c_[x.values, d]
xd = pd.DataFrame(xd, index=x.index, columns=list(x.columns) + list(d_cols))
xd = pd.DataFrame(
xd, index=x.index, columns=list(x.columns) + [f"fe_{col}" for col in d_cols]
)

ols_mod = IV2SLS(y, xd, None, None, weights=w)
res2 = ols_mod.fit(cov_type="unadjusted")
Expand Down Expand Up @@ -677,7 +687,9 @@ def test_panel_time_lsdv_weighted(large_data):
d = d - z @ lstsq(wz, wd, rcond=None)[0]

xd = np.c_[x.values, d]
xd = pd.DataFrame(xd, index=x.index, columns=list(x.columns) + list(d_cols))
xd = pd.DataFrame(
xd, index=x.index, columns=list(x.columns) + [f"te_{col}" for col in d_cols]
)

ols_mod = IV2SLS(y, xd, None, None, weights=w)
res2 = ols_mod.fit(cov_type="unadjusted")
Expand Down Expand Up @@ -760,7 +772,11 @@ def test_panel_both_lsdv_weighted(data):

xd = np.c_[x.values, d]
xd = pd.DataFrame(
xd, index=x.index, columns=list(x.columns) + list(d1.columns) + list(d2.columns)
xd,
index=x.index,
columns=list(x.columns)
+ [f"fe_{col}" for col in d1.columns]
+ [f"te_{col}" for col in d2.columns],
)

ols_mod = IV2SLS(y, xd, None, None, weights=w)
Expand Down
Loading