I'm a beginner who just started Python last weekend.I want to create a tool to capture the net database and analyze it in a fixed-point manner, so I'm working on it while researching it.
If you are familiar with it, you may be able to find out the cause right away, but I would appreciate it if you could help me.
The following error message appears when executing the code:
ValueError Traceback (most recent call last)
<ipython-input-179-6e43b379bc6b>in<module>
6exog_vars = ['expertsq', 'union', 'married', 'year' ]
7# Specify data.lwage as the variable to be explained
---->8mod=PooledOLS(data.lwage, sm.add_constant(data[exog_vars]))
9 pooled_res=mod.fit()
10 print(pooled_res)
~/opt/anaconda3/lib/python3.7/site-packages/linearmodels/panel/model.py in __init__(self, dependent, exog, weights)
776 weights: Optional [PanelDataLike] = None,
777) - > None:
-->778 super().__init__(dependent,exog,weights=weights)
779
780@classmethod
~/opt/anaconda3/lib/python3.7/site-packages/linearmodels/panel/model.py in __init__(self, dependent, exog, weights)
228 weights: Optional [PanelDataLike] = None,
229) - > None:
-->230self.dependent=PanelData(dependent, "Dep")
231self.exog=PanelData(exog, "Exog")
232 self._original_shape = self.dependent.shape
~/opt/anaconda3/lib/python3.7/site-packages/linearmodels/panel/data.py in __init__(self, x, var_name, convert_dummy, drop_first, copy)
200 x = DataFrame(x)
201elif instance (x, Series):
-->202 raise ValueError ("Series can only be used with a 2-level MultiIndex")
203
204 if isinstance(x, DataFrame):
ValueError: Series can only be used with a2-level MultiIndex
Here's the
: from linear models import PooledOLS
import statsmodels.apiasm
exog_vars = ['expertsq', 'union', 'married', 'year']
mod=PooledOLS(data.lwage, sm.add_constant(data[exog_vars]))
pooled_res=mod.fit()
print(pooled_res)
It seems to be a problem with the environment, number of editions, and work procedures.
Or you might have done something else before the question, and you didn't restart the jupyter and continued to use it, which caused the condition to change and caused an error.
In the following environments:
Windows 1020H2
Anaconda3 Individual 2020.11
Anaconda environment is up to date with conda update conda
Python 3.8.6
Pandas 1.2.2
lineamodels 4.18conda install
From the following article:
Examples-linearmodels 4.19(+12)
After copying and executing [1] source:
from linearmodels.datasets import word_panel
import pandas aspd
data=wage_panel.load()
year=pd.Category(data.year)
data=data.set_index(["nr", "year"])
data["year"] = year
print(wage_panel.DESCR)
print(data.head())
Copy and run the source of the question:
from linear models import PooledOLS
import statsmodels.apiasm
exog_vars = ['expertsq', 'union', 'married', 'year']
mod=PooledOLS(data.lwage, sm.add_constant(data[exog_vars]))
pooled_res=mod.fit()
print(pooled_res)
Displays the results of successful processing.
PooledOLS Estimation Summary
================================================================================
Dep.Variable:lwage R-squared: 0.1246
Estimator: PooledOLSR-squared (Between): 0.0902
No. Observations:4360 R-squared (Within): 0.1646
Date: Wed, Feb 17 2021 R-squared (Overall): 0.1246
Time: 14:46:24 Log-like food-3149.2
Cov.Estimator: Unadjusted
F-static—61.920
Entities—545 P-value 0.0000
Avg Obs: 8.0000 Distribution: F(10,4349)
MinObs: 8.0000
Max Obs: 8.0000 F-statistic (robust): 61.920
P-value 0.0000
Time periods: 8 Distribution: F(10,4349)
Avg Obs:545.00
Min Obs:545.00
Max Obs:545.00
Parameter Estimates
==============================================================================
Parameter Std.Err.T-stat P-value Lower CI Upper CI
------------------------------------------------------------------------------
const1.34540.0222 60.606 0.0000 1.3019 1.3889
expersq-0.00210.0003-7.50810.0000-0.0026-0.0015
union 0.17680.0176 10.0320.0000.14230.2114
married 0.15210.01599.54170.0000.12090.1834
year.1980.11870.03033.91440.00010.05920.1781
year.1980.18430.0306 6.016800.0000.12430.2444
year.19830.24310.03137.75810.0000.18170.3046
year.19840.33220.0324 10.2360.0000.26850.3958
year.19850.41120.0341 12.0480.0000.34430.4781
year.19860.50390.036513.8060.0000.43230.5754
year.1987 0.59520.0396 15.0260.0000.51760.6729
==============================================================================
© 2024 OneMinuteCode. All rights reserved.