• <legend id='m9g70'><style id='m9g70'><dir id='m9g70'><q id='m9g70'></q></dir></style></legend>

  • <i id='m9g70'><tr id='m9g70'><dt id='m9g70'><q id='m9g70'><span id='m9g70'><b id='m9g70'><form id='m9g70'><ins id='m9g70'></ins><ul id='m9g70'></ul><sub id='m9g70'></sub></form><legend id='m9g70'></legend><bdo id='m9g70'><pre id='m9g70'><center id='m9g70'></center></pre></bdo></b><th id='m9g70'></th></span></q></dt></tr></i><div id='m9g70'><tfoot id='m9g70'></tfoot><dl id='m9g70'><fieldset id='m9g70'></fieldset></dl></div>
  • <tfoot id='m9g70'></tfoot>

      <bdo id='m9g70'></bdo><ul id='m9g70'></ul>

        <small id='m9g70'></small><noframes id='m9g70'>

        任何 Python 库都会生成发布风格回归表

        时间:2023-10-18

              <tbody id='NPoyP'></tbody>
            <legend id='NPoyP'><style id='NPoyP'><dir id='NPoyP'><q id='NPoyP'></q></dir></style></legend>
            <i id='NPoyP'><tr id='NPoyP'><dt id='NPoyP'><q id='NPoyP'><span id='NPoyP'><b id='NPoyP'><form id='NPoyP'><ins id='NPoyP'></ins><ul id='NPoyP'></ul><sub id='NPoyP'></sub></form><legend id='NPoyP'></legend><bdo id='NPoyP'><pre id='NPoyP'><center id='NPoyP'></center></pre></bdo></b><th id='NPoyP'></th></span></q></dt></tr></i><div id='NPoyP'><tfoot id='NPoyP'></tfoot><dl id='NPoyP'><fieldset id='NPoyP'></fieldset></dl></div>
          1. <tfoot id='NPoyP'></tfoot>

            <small id='NPoyP'></small><noframes id='NPoyP'>

              <bdo id='NPoyP'></bdo><ul id='NPoyP'></ul>

                  本文介绍了任何 Python 库都会生成发布风格回归表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我一直在使用 Python 进行回归分析.得到回归结果后,我需要将所有结果汇总到一个表中,并将它们转换为 LaTex(用于发布).是否有任何包可以在 Python 中执行此操作?Stata 中的 estout 之类的东西给出了下表:

                  I've been using Python for regression analysis. After getting the regression results, I need to summarize all the results into one single table and convert them to LaTex (for publication). Is there any package that does this in Python? Something like estout in Stata that gives the following table:

                  推荐答案

                  嗯,statsmodels里面有summary_col;它没有 estout 的所有花里胡哨,但它确实具有您正在寻找的基本功能(包括导出到 LaTeX):

                  Well, there is summary_col in statsmodels; it doesn't have all the bells and whistles of estout, but it does have the basic functionality you are looking for (including export to LaTeX):

                  import statsmodels.api as sm
                  from statsmodels.iolib.summary2 import summary_col
                  
                  p['const'] = 1
                  reg0 = sm.OLS(p['p0'],p[['const','exmkt','smb','hml']]).fit()
                  reg1 = sm.OLS(p['p2'],p[['const','exmkt','smb','hml']]).fit()
                  reg2 = sm.OLS(p['p4'],p[['const','exmkt','smb','hml']]).fit()
                  
                  print summary_col([reg0,reg1,reg2],stars=True,float_format='%0.2f')
                  
                  ===============================
                           p0       p2      p4   
                  -------------------------------
                  const -1.03*** -0.01   0.62*** 
                        (0.11)   (0.04)  (0.07)  
                  exmkt 1.28***  0.97*** 0.98*** 
                         (0.02)   (0.01)  (0.01)  
                  smb   0.37***  0.28*** -0.14***
                        (0.03)   (0.01)  (0.02)  
                  hml   0.77***  0.46*** 0.69*** 
                        (0.04)   (0.01)  (0.02)  
                  ===============================
                  Standard errors in parentheses.
                  * p<.1, ** p<.05, ***p<.01
                  

                  或者这里是我添加 R-Squared 和观察次数的版本:

                  Or here is a version where I add R-Squared and the number of observations:

                  print summary_col([reg0,reg1,reg2],stars=True,float_format='%0.2f',
                                    info_dict={'N':lambda x: "{0:d}".format(int(x.nobs)),
                                               'R2':lambda x: "{:.2f}".format(x.rsquared)})
                  
                  ===============================
                           p0       p2      p4   
                  -------------------------------
                  const -1.03*** -0.01   0.62*** 
                        (0.11)   (0.04)  (0.07)  
                  exmkt 1.28***  0.97*** 0.98*** 
                        (0.02)   (0.01)  (0.01)  
                  smb   0.37***  0.28*** -0.14***
                        (0.03)   (0.01)  (0.02)  
                  hml   0.77***  0.46*** 0.69*** 
                        (0.04)   (0.01)  (0.02)  
                  R2    0.86     0.95    0.88    
                  N     1044     1044    1044    
                  ===============================
                  Standard errors in parentheses.
                  * p<.1, ** p<.05, ***p<.01
                  

                  另一个例子,这次展示了 model_names 选项的使用和自变量变化的回归:

                  Another example, this time showing the use of the model_names option and regressions where the independent variables vary:

                  reg3 = sm.OLS(p['p4'],p[['const','exmkt']]).fit()
                  reg4 = sm.OLS(p['p4'],p[['const','exmkt','smb','hml']]).fit()
                  reg5 = sm.OLS(p['p4'],p[['const','exmkt','smb','hml','umd']]).fit()
                  
                  print summary_col([reg3,reg4,reg5],stars=True,float_format='%0.2f',
                                    model_names=['p4
                  (0)','p4
                  (1)','p4
                  (2)'],
                                    info_dict={'N':lambda x: "{0:d}".format(int(x.nobs)),
                                               'R2':lambda x: "{:.2f}".format(x.rsquared)})
                  
                  ==============================
                           p4      p4       p4  
                          (0)     (1)      (2)  
                  ------------------------------
                  const 0.66*** 0.62***  0.15***
                        (0.10)  (0.07)   (0.04) 
                  exmkt 1.10*** 0.98***  1.08***
                        (0.02)  (0.01)   (0.01) 
                  hml           0.69***  0.72***
                                (0.02)   (0.01) 
                  smb           -0.14*** 0.07***
                                (0.02)   (0.01) 
                  umd                    0.46***
                                         (0.01) 
                  R2    0.78    0.88     0.96   
                  N     1044    1044     1044   
                  ==============================
                  Standard errors in
                  parentheses.
                  * p<.1, ** p<.05, ***p<.01
                  

                  要导出到 LaTeX,请使用 as_latex 方法.

                  To export to LaTeX use the as_latex method.

                  我可能是错的,但我认为没有实现 t-stats 选项而不是标准错误(如您的示例中).

                  I could be wrong but I don't think an option for t-stats instead of standard errors (like in your example) is implemented.

                  这篇关于任何 Python 库都会生成发布风格回归表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:将普通字符串转换为乳胶字符串以在 matplotlib 中使用 下一篇:使用 Latex 进行渲染时,如何更改 matplotlib 图中的轴刻度字体?

                  相关文章

                • <tfoot id='QqZj3'></tfoot>

                  <small id='QqZj3'></small><noframes id='QqZj3'>

                • <i id='QqZj3'><tr id='QqZj3'><dt id='QqZj3'><q id='QqZj3'><span id='QqZj3'><b id='QqZj3'><form id='QqZj3'><ins id='QqZj3'></ins><ul id='QqZj3'></ul><sub id='QqZj3'></sub></form><legend id='QqZj3'></legend><bdo id='QqZj3'><pre id='QqZj3'><center id='QqZj3'></center></pre></bdo></b><th id='QqZj3'></th></span></q></dt></tr></i><div id='QqZj3'><tfoot id='QqZj3'></tfoot><dl id='QqZj3'><fieldset id='QqZj3'></fieldset></dl></div>
                  • <bdo id='QqZj3'></bdo><ul id='QqZj3'></ul>

                      <legend id='QqZj3'><style id='QqZj3'><dir id='QqZj3'><q id='QqZj3'></q></dir></style></legend>