代码之家  ›  专栏  ›  技术社区  ›  msh855

使用outreg2导出结果

  •  0
  • msh855  · 技术社区  · 6 年前

    我正在使用 社区贡献 命令 outreg2 在stata中,创建基于分类变量的多元回归表:

    bysort Sector: outreg2 using results_by_sectors.xls, replace dec(2) ///
    keep(log_tfp_leader_growth years_schooling_normalized ///
    tfp_gap_years_school_norm i_rd_go tfp_gap_i_rd) title("Regressions By Sectors") ///
    label: reg log_tfp_growth log_tfp_leader_growth years_schooling_normalized ///
    tfp_gap_years_school_norm, robust
    

    除了一件事之外,一切都很好;表而不是使用分类变量扇区的名称/标签弹出为 Sector 1 , Sector 2 , Sector 3 等等:

    enter image description here

    但是,每个扇区的标签/名称是:

    tab Sector
    
            ind |      Freq.     Percent        Cum.
    ------------+-----------------------------------
          10-12 |        236        3.88        3.88
          13-15 |        236        3.88        7.76
          16-18 |        236        3.88       11.64
             19 |        220        3.62       15.26
          20-21 |        220        3.62       18.88
          22-23 |        236        3.88       22.76
          24-25 |        220        3.62       26.38
          26-27 |        220        3.62       30.00
             28 |        220        3.62       33.62
          29-30 |        220        3.62       37.24
          31-33 |        220        3.62       40.86
              A |        284        4.67       45.53
              B |        284        4.67       50.20
            D-E |        252        4.14       54.34
              F |        284        4.67       59.01
              G |        284        4.67       63.68
    

    我该如何修改 外加2 编码,而不是获取 扇区1 , 扇区2 在每个回归的列名中获取每个扇区的标签,如上面所示(例如 10-12 等等?

    1 回复  |  直到 6 年前
        1
  •  1
  •   Pearly Spencer Paul Cruz    6 年前

    你不能那样做 outreg2 因为它是由其作者编码的,返回变量名加上因子级别号:

    . sysuse auto, clear
    (1978 Automobile Data)
    
    . bysort foreign: outreg2 using myfile, side replace: quietly reg price weight mpg
    dir : seeout
    
    . type myfile.txt
            (1)     (2)     (3)     (4)
            foreign 0               foreign 1       
    VARIABLES       price   se      price   se
    
    price                           
    weight  4.415***        (0.948) 5.156***        (0.881)
    mpg     237.7*  (139.0) -19.78  (57.68)
    Constant        -13,285**       (5,726) -5,066  (3,203)
    
    Observations    52              22      
    R-squared       0.483           0.785   
    Standard errors in parentheses                          
    *** p<0.01, ** p<0.05, * p<0.1                          
    

    你可以看到,如果你真的是这样的话 recode 用于的变量 bysort :

    . recode foreign (0 = 1) (1 = 2)
    (foreign: 74 changes made)
    
    . bysort foreign: outreg2 using myfile, side replace: quietly reg price weight mpg
    dir : seeout
    
    . type myfile.txt
            (1)     (2)     (3)     (4)
            foreign 1               foreign 2       
    VARIABLES       price   se      price   se
    
    price                           
    weight  4.415***        (0.948) 5.156***        (0.881)
    mpg     237.7*  (139.0) -19.78  (57.68)
    Constant        -13,285**       (5,726) -5,066  (3,203)
    
    Observations    52              22      
    R-squared       0.483           0.785   
    Standard errors in parentheses                          
    *** p<0.01, ** p<0.05, * p<0.1                          
    

    但是,您可以使用 estout 社区贡献 命令:

    . sysuse auto, clear
    (1978 Automobile Data)
    
    . quietly bysort foreign: eststo: quietly reg price weight mpg
    
    . esttab, label nodepvar
    
    ----------------------------------------------------
                                  (1)             (2)   
                             Domestic         Foreign   
    ----------------------------------------------------
    Weight (lbs.)               4.415***        5.156***
                               (4.66)          (5.85)   
    
    Mileage (mpg)               237.7          -19.78   
                               (1.71)         (-0.34)   
    
    Constant                 -13285.4*        -5065.8   
                              (-2.32)         (-1.58)   
    ----------------------------------------------------
    Observations                   52              22   
    ----------------------------------------------------
    t statistics in parentheses
    * p<0.05, ** p<0.01, *** p<0.001
    

    显然,您必须使用各种选项来获得所需的内容(例如,指定选项 cells(b se) 以便在表中包含标准错误)。