0

I have fit a linearmodels.PanelOLS model and stored it in m. I now want to test if certain coefficients are simultaneously equal to zero.

Does a fitted linearmodels.PanelOLS object have an F-test function where I can pass my own restriction matrix?

I am looking for something like statsmodels' f_test method.


Here's a minimum reproducible example.

# Libraries
from linearmodels.panel import PanelOLS
from linearmodels.datasets import wage_panel

# Load data and set index
df = wage_panel.load()
df = df.set_index(['nr','year'])

# Add constant term
df['const'] = 1

# Fit model
m = PanelOLS(dependent=df['lwage'], exog=df[['const','expersq','married']])
m = m.fit(cov_type='clustered', cluster_entity=True)

# Is there an f_test method for m???
m.f_test(r_mat=some_matrix_here) # Something along these lines?
Arturo Sbr
  • 5,567
  • 4
  • 38
  • 76

1 Answers1

1

You can use wald_test (a standard F-test is numerically identical to a Walkd test under some assumptions on the covariance).

# Libraries
from linearmodels.panel import PanelOLS
from linearmodels.datasets import wage_panel

# Load data and set index
df = wage_panel.load()
df = df.set_index(['nr','year'])

# Add constant term
df['const'] = 1

# Fit model
m = PanelOLS(dependent=df['lwage'], exog=df[['const','expersq','married']])
m = m.fit(cov_type='clustered', cluster_entity=True)

Then the test

import numpy as np

# Use matrix notation RB - q = 0 where R is restr and q is value
# Restrictions: expersq = 0.001 & expersq+married = 0.2
restr = np.array([[0,1,0],[0,1,1]])
value = np.array([0.01, 0.2])
m.wald_test(restr, value)

This returns

Linear Equality Hypothesis Test
H0: Linear equality constraint is valid
Statistic: 0.2608
P-value: 0.8778
Distributed: chi2(2)
WaldTestStatistic, id: 0x2271cc6fdf0

You can also use formula syntax if you used formulas to define your model, which can be easier to code up.

fm = PanelOLS.from_formula("lwage~ 1 + expersq + married", data=df)
fm = fm.fit(cov_type='clustered', cluster_entity=True)
fm.wald_test(formula="expersq = 0.001,expersq+married = 0.2")

The result is the same as above.

Kevin S
  • 2,595
  • 16
  • 22
  • I did not realize fitted models had a `wald_test()` method. Thanks! I was considering fitting two models (a full one and a reduced one) to calculate the F-stat from their RSS ratios. This is much simpler. – Arturo Sbr May 24 '22 at 12:16