1

如何将拟合的线性模型对象的汇总表打印为乳胶?

例如,如何打印res为乳胶代码?

# Libraries
import pandas as pd
from linearmodels.panel import PanelOLS
from linearmodels.datasets import wage_panel

# Load silly data
df = wage_panel.load()

# Set indexes
df = df.set_index(['nr','year'])

# Fit silly model
mod = PanelOLS(dependent=df['lwage'], exog=df[['hours','married','educ']], time_effects=True)
res = mod.fit()

# Print results
print(res)
                          PanelOLS Estimation Summary                           
================================================================================
Dep. Variable:                  lwage   R-squared:                        0.0933
Estimator:                   PanelOLS   R-squared (Between):              0.7056
No. Observations:                4360   R-squared (Within):               0.0373
Date:                Thu, Nov 04 2021   R-squared (Overall):              0.6764
Time:                        23:48:11   Log-likelihood                   -3055.6
Cov. Estimator:            Unadjusted                                           
                                        F-statistic:                      149.14
Entities:                         545   P-value                           0.0000
Avg Obs:                       8.0000   Distribution:                  F(3,4349)
Min Obs:                       8.0000                                           
Max Obs:                       8.0000   F-statistic (robust):             149.14
                                        P-value                           0.0000
Time periods:                       8   Distribution:                  F(3,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
------------------------------------------------------------------------------
hours      -7.571e-05  1.357e-05    -5.5805     0.0000     -0.0001  -4.911e-05
married        0.1573     0.0157     10.017     0.0000      0.1265      0.1881
educ           0.0765     0.0042     18.048     0.0000      0.0682      0.0848
==============================================================================

F-test for Poolability: 41.795
P-value: 0.0000
Distribution: F(7,4349)

Included effects: Time
4

1 回答 1

1

您可以使用summary属性执行此操作。请注意,您必须使用booktabsLatex 中的包。

print(res.summary.as_latex())

哪个打印:

\begin{center} \begin{tabular}{lclc} \toprule \textbf{Dep. 变量:} & lwage & \textbf{ R-squared: } & 0.0933 \ \textbf{Estimator:} & PanelOLS & \textbf{ R-squared (Between):} & 0.7056 \ \textbf{No. 观察结果:} & 4360 & \textbf{ R-squared (Within):}
& 0.0373 \ \textbf{Date:} & Thu, Nov 04 2021 & \textbf{ R-squared (Overall):} & 0.6764 \ \textbf{时间:} & 23:50:24 & \textbf{ 对数似然 } & -3055.6 \ \textbf{Cov. Estimator:} & Unadjusted & \textbf{ } &
\ \textbf{} & & \textbf{ F-statistic: } & 149.
& 545 & \textbf{ P-value } & 0.0000 \ \textbf{Avg Obs:} & 8.0000 & \textbf{ Distribution: } & F(3,4349) \ \textbf{Min Obs:}
& 8.0000 & \textbf{ } &
\ \textbf{Max Obs:} & 8.0000 & \textbf{ F-statistic (robust):} & 149.14 \ \textbf{}
& & \textbf{ P-value } & 0.0000 \ \textbf{Time period:} & 8 & \textbf{ 分布:} & F(3,4349) \ \textbf{Avg Obs:}
& 545.00 & \textbf{ } &
\ \textbf{Min Obs:} & 545.00 & \textbf{
} &\ \textbf{最大观测值:} & 545.00
& \textbf{ } & \ \textbf{}
& & \textbf{ } &
\ \bottomrule \end{tabular} \begin{tabular}{lcccccc} & \textbf{参数} & \textbf{Std. Err.} & \textbf{T-stat} & \textbf{P-value} & \textbf{Lower CI} & \textbf{Upper CI} \ \midrule \textbf{hours} & -7.571e-05 & 1.357e -05 & -5.5805 & 0.0000 & -0.0001 &
-4.911e-05 \ \textbf{已婚} & 0.1573 & 0.0157 & 10.017 & 0.0000 & 0.1265 &
0.1881 \ \textbf{educ} & 0.0765 & 0.0042 & 008.40 & 08.0.40 &

可合并性的 F 检验:41.795 \newline P 值:0.0000 \newline 分布:F(7,4349) \newline \newline 包含的影响:时间

于 2021-11-04T23:59:57.173 回答