KeyError for PanelOLS from_formula example
jhuang2023 opened this issue · 3 comments
jhuang2023 commented
I try to run the example in PanelOLS from_formula, but I get the error and have no idea how to solve it:
panel_data = generate_panel_data()
mod = PanelOLS.from_formula("y ~ x1 + x0 + EntityEffects", panel_data.data)
res = mod.fit(cov_type="clustered", cluster_entity=True)
Error Massage is:
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
[<ipython-input-6-538f694ebc58>](https://localhost:8080/#) in <module>
1 panel_data = generate_panel_data()
----> 2 mod = PanelOLS.from_formula("y ~ x1 + x0 + EntityEffects", panel_data.data)
3 res = mod.fit(cov_type="clustered", cluster_entity=True)
4 frames
[/usr/local/lib/python3.7/dist-packages/formulaic/parser/types/structured.py](https://localhost:8080/#) in __getitem__(self, key)
327 return self._structure[key]
328 raise KeyError(
--> 329 f"This `{self.__class__.__name__}` instance does not have structure @ `{repr(key)}`."
330 )
331
KeyError: 'This `Formula` instance does not have structure @ `1`.
I am using colab to run this example. Can anyone help?
bashtage commented
Hmm, I'll need to look into this. It is surprising.
bashtage commented
I can't reproduce on Python 3.9.
from linearmodels import PanelOLS
from linearmodels.panel import generate_panel_data
panel_data = generate_panel_data()
mod = PanelOLS.from_formula("y ~ 1 + x1 + EntityEffects", panel_data.data)
res = mod.fit(cov_type="clustered", cluster_entity=True)
If you copy and paste this code, does it not work?
jhuang2023 commented
I can't reproduce on Python 3.9.
from linearmodels import PanelOLS from linearmodels.panel import generate_panel_data panel_data = generate_panel_data() mod = PanelOLS.from_formula("y ~ 1 + x1 + EntityEffects", panel_data.data) res = mod.fit(cov_type="clustered", cluster_entity=True)If you copy and paste this code, does it not work?
Hi, bashtage,
Thank you for your reply. Since currently Colab still uses python 3.7 and it is hard to change the python version in Colab, so I switch to my local machine and use python 3.8. I do not have this problem then.
Thank you.