Announcement

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

  • Have etable put stars in the same cell of the coefficient

    I use the following to generate the regression tables:
    Code:
    quietly etable, estimates(h_1_1 h_1_2 h_1_3 h_1_4 h_1_5 h_1_6 h_1_7 h_1_8) ///
    cstat(_r_b) cstat(_r_se, nformat(%7.2f)) ///
    mstat(N) mstat(r2_p, nformat(%7.4f)) mstat(chi2) stars(.1 "*" .05 "**" .01 "***", attach(_r_b)) ///
    showstars showstarsnote column(estimates) title("Models for hypothesis H1")
    Then

    Code:
    quietly collect export "$outdir/tables/h1.xlsx", replace
    But in the resulting Excel file, coefficients and stars are in two separate columns.

    I need them in the same column, because Word won't format them as I want to if they are in two different columns.


  • #2
    Hi, I am facing a similar issue and wondered if you figured this out back a few months ago! Thanks

    Comment


    • #3
      Dear all, I have the same issue; significance stars are created in separate columns.

      When I generate a regression table with "etable" command, it seems the default layout is as below.

      Code:
      collect layout (coleq#colname#result[_r_b _r_se] result[N r2]) (cmdset#stars) (), name(ETable)
      I assume "cmdset#stars" option creates separate columns, so I tried the following layout instead. But now it generates a separate rows.
      Code:
      collect layout (coleq#colname#result[_r_b _r_se]#stars result[N r2]) (cmdset) (), name(ETable)
      Any way to attach significant stars in a same column?

      Thank you.

      Comment


      • #4
        Showing your code/example without the data to go with it makes it difficult for us to make suggestions and show that our ideas actually work properly.

        collect stars dynamically labels results given a set of significance rules for the labels. The labels are created depending on stars style type: result or dimension. result creates new items for the stars labels and tags them with result[stars]. dimension creates new items for the stars labels and tags them with stars[label] and all other already-existing items are tagged with stars[value]. In general collect defaults to type result, but etable defaults to dimension -- this is to accommodate vertically aligning the numeric items independently/separately from the stars labels.

        Use command collect stars to change the type.

        Here is a short example, using the publicly available auto data.
        Code:
        * data and model setup
        sysuse auto
        regress mpg turn
        estimates store m1
        regress mpg turn trunk
        estimates store m2
        
        * table of estimates, showing stars
        etable, estimates(m1 m2) column(estimates) showstars
        
        * show current stars specification; notice the type is dimension and the labels are attached to _r_b
        collect query stars
        * change the type to result
        collect stars, result
        * show that the only thing that changed was the type
        collect query stars
        
        * replay table to see that the stars are now attached to the coefficients
        collect preview
        Here is the resulting table.
        Code:
        -------------------------------
                                  mpg  
        -------------------------------
        Turn circle (ft.)      -0.761**
                                (0.131)
        Trunk space (cu. ft.)   -0.316*
                                (0.134)
        Intercept              55.820**
                                (4.354)
        Number of observations       74
        -------------------------------

        Comment


        • #5
          Jeff Pitblado (StataCorp) Thank you so much once again! Next time I will come up with a data example. "Collect" command seems a bit complicated, but is really interesting that allows greater flexibility! Will take some time to go through it more thoroughly.

          Comment


          • #6
            Dear Jeff Pitblado (StataCorp),

            I am following up on this post, as it is closely related to the topic. In my use case, I am exporting ten to twenty regression tables (robustness checks) to Word.
            Here is an MRE:
            Code:
            sysuse auto
            regress mpg turn
            estimates store m1
            regress mpg turn trunk
            estimates store m2
            
            eststo m3: regress price displacement
            eststo m4: regress price displacement weight
            Using esttab from the estout package, I can export the regressions in one file with two lines of code:
            Code:
            esttab m1 m2 using "Robustness-checks.rtf", replace
            esttab m3 m4 using "Robustness-checks.rtf", append title(\page)
            The shortest etable equivalent I could come up with is:
            Code:
            * etable
            *Tables of estimates, showing stars
            etable, estimates(m1 m2) column(estimates) showstars name(reg1)
            etable, estimates(m3 m4) showstars name(reg2)
            
            * Create a local with all regressions
            local regs reg1 reg2
            * Attach stars
            foreach x of local regs {
                collect stars, result
                collect export "`x'.docx", replace
            }
            
            * Putdocx append
            putdocx append reg1.docx reg2.docx, saving(Regressions.docx, replace) pagebreak
            This process is more complicated compared to esttab. If this is the shortest path (?), I would love the etable function to have an option that automatically adds the stars to the same cell. I have two reasons for this request. 1. Replicability: I generally want to limit the amount of manual formatting in Word. 2. Space-saving: Having the stars in the same columns saves much needed space when reporting five to sex regression models on one page (IV, IV+Controls, IV+Controls+Moderator 1, IV+Controls+Moderator 2).
            Last edited by Felix Kaysers; 23 Sep 2025, 04:44.
            Cheers,
            Felix
            Stata Version: MP 18.0
            OS: Windows 11

            Comment

            Working...
            X