0
from statsmodels.datasets import grunfeld
data = grunfeld.load_pandas().data
data = data.set_index(['firm','year'])

from linearmodels import PanelOLS
mod = PanelOLS.from_formula('invest ~ value + capital + EntityEffects + TimeEffects', 
                           data=data) 

and have:

KeyError: 'This Formula instance does not have structure @ 1.'

full output: full output

Alex W
  • 1
  • 1
  • [Please do not upload images of code/data/errors when asking a question.](//meta.stackoverflow.com/q/285551) – Dani3le_ Sep 13 '22 at 09:43

1 Answers1

0

I'm having the same issue. One workaround would be to use the formulaic library directly. This is the same library used by linearmodels to process the formula. It takes the formula and returns the equivalent matrices to be used directly:

from formulaic import Formula

y, X = Formula('invest ~ value + capital').get_model_matrix(data)

mod = PanelOLS(y, X, entity_effects=True)
res = mod.fit(cov_type='clustered', cluster_entity=True)
  • Your answer could be improved by adding more information on what the code does and how it solves the problem. – AlexK Oct 17 '22 at 07:35