Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • ETable stars[value]

    I'd like to create a table summarizing results from several models by having a column with the coefficient and confidence intervals in a single row, with the models running across the table. I've gotten close with the help of the table builder, but found some odd behavior that I can't understand.



    Code:
    clear
    
    webuse kva
    stset failtime
    streg load bearings, distribution(weibull) time tratio
    
    gen notbearings=0 if bearings==1
    replace notbearings=1 if bearings==0
    
    streg load bearings, distribution(weibull) time tratio
    eststo bearings
    streg load notbearings, distribution(weibull) time tratio
    eststo notbearings
    
    collect clear
    
    etable, estimates(bearings notbearings) cstat(_r_b) cstat(_r_ci) column(estimates) 
    
    collect style cell result[_r_ci], warn cidelimiter(`","')
    collect composite define coefci = _r_b _r_ci, trim replace
    collect layout ( coleq#colname#result[coefci] result[N]) (etable_estimates#stars[value])
    
    
    Collection: ETable
          Rows:  coleq#colname#result[coefci] result[N]
       Columns: etable_estimates#stars[value]
       Table 1: 8 x 2
    
    ------------------------------------------------------------------------------
                                     bearings                  notbearings        
    ------------------------------------------------------------------------------
    Overload (kVA)             0.941 [0.930,    0.953]     0.941 [0.930,    0.953]
    Has new bearings           1.239 [1.070,    1.434]                            
    notbearings                                            0.807 [0.697,    0.934]
    Intercept              330.643 [234.533,  466.139] 409.656 [286.257,  586.248]
    ln_p                       2.052 [1.597,    2.506]     2.052 [1.597,    2.506]
    p                          7.780 [4.940,   12.252]     7.780 [4.940,   12.252]
    1/p                        0.129 [0.082,    0.202]     0.129 [0.082,    0.202]
    Number of observations                          12                          12
    ------------------------------------------------------------------------------

    So far so good, though it has not trimmed the space out of the confidence interval, and I would modestly prefer parentheses to brackets for the confidence interval. But I looked at the description of the layout that Table Builder created for me and saw the column stars[value]. I don't want significance stars, so when I went to write my code for the change in layout, I removed that from the column specification, and when I did, the table only provided the confidence interval, with no brackets around it and no _r_b.

    Code:
    collect layout ( coleq#colname#result[coefci] result[N]) (etable_estimates)
    
    
    
    Collection: ETable
          Rows:  coleq#colname#result[coefci] result[N]
       Columns: etable_estimates
       Table 1: 8 x 2
    
    ------------------------------------------------------------------
                                  bearings            notbearings     
    ------------------------------------------------------------------
    Overload (kVA)               0.930,    0.953       0.930,    0.953
    Has new bearings             1.070,    1.434                      
    notbearings                                        0.697,    0.934
    Intercept                  234.533,  466.139     286.257,  586.248
    ln_p                         1.597,    2.506       1.597,    2.506
    p                      7.780 4.940,   12.252 7.780 4.940,   12.252
    1/p                    0.129 0.082,    0.202 0.129 0.082,    0.202
    Number of observations                    12                    12
    ------------------------------------------------------------------
    Where am I going wrong?

  • #2
    Sorry, I should have specified that I'm using Stata/SE 19.0 for Mac, Revision 21 May 2025

    Comment


    • #3
      Consider:
      Code:
      clear
      
      webuse kva
      stset failtime
      streg load bearings, distribution(weibull) time tratio
      
      gen notbearings=0 if bearings==1
      replace notbearings=1 if bearings==0
      
      streg load bearings, distribution(weibull) time tratio
      eststo bearings
      streg load notbearings, distribution(weibull) time tratio
      eststo notbearings
      
      collect clear
      
      etable, estimates(bearings notbearings) column(estimates) stars(, clear)
      collect composite define ci = _r_lb _r_ub, delimiter(,) trim
      collect style cell result[ci], sformat("(%s)")
      collect composite define bci = _r_b ci
      collect style header result[bci], level(hide)
      collect layout (coleq#colname#result[bci] result[N]) (etable_estimates)
      which produces:
      Code:
      . collect preview
      
      --------------------------------------------------------------------------
                                      bearings                notbearings      
      --------------------------------------------------------------------------
      Overload (kVA)               0.941 (0.930,0.953)       0.941 (0.930,0.953)
      Has new bearings             1.239 (1.070,1.434)                          
      notbearings                                            0.807 (0.697,0.934)
      Intercept              330.643 (234.533,466.139) 409.656 (286.257,586.248)
      ln_p                         2.052 (1.597,2.506)       2.052 (1.597,2.506)
      p                           7.780 (4.940,12.252)      7.780 (4.940,12.252)
      1/p                          0.129 (0.082,0.202)       0.129 (0.082,0.202)
      Number of observations                        12                        12
      --------------------------------------------------------------------------
      Last edited by Hemanshu Kumar; 15 Aug 2025, 21:46.

      Comment


      • #4
        That is exactly what I wanted--thank you!
        I'm still curious why the composite needs to be defined in two steps and why removing stars[value] drops part of the composite. I'll follow up with Stata support

        Comment


        • #5
          Following up with the very helpful Stata support response on why _r_b disappears when stars[value] is removed from the specification:

          The reason why the numbers of _r_b disappear is related to duplicated matches for the result[_r_b] tag.

          The default star rules create corresponding star items (like: ***) with a new tag: stars[label], which are also tagged with result[_r_b]. The numbers of _r_b tagged with result[_r_b], are also tagged with stars[value].

          So, if you only include the tag result[_r_b] and other levels of row and column combination, the -collect layout- can find more than one item (the numbers of _r_b and star items), so nothing will be shown in those cells. You need to specify the stars[value] in order to let -collect layout- know which one to display.
          So I assume Hemanshu Kumar's stars(, clear) is removing that duplication and allowing the _r_b to show up.

          One other minor edit I made to Kumar's extremely helpful code is rather than delimiter(,), I specified delimiter(`", "'), which puts a space after the comma.


          Stata support also let me know that reason the brackets disappeared when stars[value] was removed is that the default style that places brackets around the confidence interval is specific to the confidence and credible interval layouts in etable with stars[value]:

          Go the the Contents, and find "Predefined styles" under the "Remarks and examples". Click the "etable", then click "etable_nformats". You will find the following default style:
          collect style cell result[_r_ci _r_cri]#stars[value], sformat("[%s]")
          Last edited by Molly Jeffery; 19 Aug 2025, 12:40.

          Comment

          Working...
          X