请尝试下面的操作-我已经从上面的链接复制了股票数据,并为x列添加了随机数据。对于面板回归,您需要注释中提到的“多索引”。df = pd.DataFrame(df.set_index('dates').stack())
df.columns = ['y']
df['x'] = np.random.random(size=len(df.index))
df.info()
MultiIndex: 100 entries, (2015-04-03 00:00:00, AB INBEV) to (2015-05-01 00:00:00, ZC.PA)
Data columns (total 2 columns):
y 100 non-null float64
x 100 non-null float64
dtypes: float64(2)
memory usage: 2.3+ KB
regression = PanelOLS(y=df['y'], x=df[['x']])
regression
-------------------------Summary of Regression Analysis-------------------------
Formula: Y ~ +
Number of Observations: 100
Number of Degrees of Freedom: 2
R-squared: 0.0042
Adj R-squared: -0.0060
Rmse: 0.2259
F-stat (1, 98): 0.4086, p-value: 0.5242
Degrees of Freedom: model 1, resid 98
-----------------------Summary of Estimated Coefficients------------------------
Variable Coef Std Err t-stat p-value CI 2.5% CI 97.5%
--------------------------------------------------------------------------------
x -0.0507 0.0794 -0.64 0.5242 -0.2063 0.1048
intercept 2.1952 0.0448 49.05 0.0000 2.1075 2.2829
---------------------------------End of Summary---------------------------------