Announcement

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

  • -collect composite- and -collect stars- issue

    Hello,
    I'm trying to display significance stars to the right of composite results (the lower and upper bounds of confidence intervals) using collect machinery. And it seems like -collect stars- doesn't interact with composite results in the same manner as it does with regular collect results, or perhaps I'm misunderstanding how either of those works.

    Here's the code I'm running:

    Code:
    version 18
    
    * version 1 - significance stars next to coefficients - works as expected.
    clear all
    sysuse auto
    
    collect: reg price c.mpg c.headroom
    
    collect composite define ci = _r_lb _r_ub, trim delimiter(" - ")
    collect composite define beta_ci = _r_b ci
    collect style cell result[ci], sformat("[%s]")
    collect style header result[beta_ci], level(hide)
    collect layout (coleq#colname#result[beta_ci] result[_cons r2 N]) 
    collect stars _r_p .05 "*" .01 "**", result attach(_r_b)
    
    collect preview
    
    * version 2 - the goal is to display significance stars to the right of beta_ci composite result, but they are not displayed.
    clear all
    sysuse auto
    
    collect: reg price c.mpg c.headroom
    
    collect composite define ci = _r_lb _r_ub, trim delimiter(" - ")
    collect composite define beta_ci = _r_b ci
    collect style cell result[ci], sformat("[%s]")
    collect style header result[beta_ci], level(hide)
    collect layout (coleq#colname#result[beta_ci] result[_cons r2 N]) 
    collect stars _r_p .05 "*" .01 "**", result attach(beta_ci)
    
    collect preview
    It's a minor inconvenience, but still I'd like to learn how to solve this programmatically in Stata rather than move those stars manually in Excel or other software.

    Thanks.

  • #2
    Composite results do not exist as items in the collection, they are built dynamically when collect builds the tables. Thus the attach() option has no effect; we will look into getting collect stars to produce a warning or error in this case.

    I notice you are using the result option with collect stars, which is the default. You can use stars in your composite definition. Something like
    Code:
    * version 3
    clear all
    sysuse auto
    
    collect: reg price c.mpg c.headroom
    
    collect stars _r_p .05 "*" .01 "**"
    collect composite define ci = _r_lb _r_ub, trim delimiter(" - ")
    collect composite define beta_ci = _r_b ci stars
    collect style cell result[ci], sformat("[%s]")
    collect style header result[beta_ci], level(hide)
    collect layout (coleq#colname#result[beta_ci] result[_cons r2 N])
    The resulting table in this case is
    Code:
    -------------------------------------------------------------
    Price                  |                                     
      Mileage (mpg)        | -259.1057 [-375.6015 - -142.6098] **
      Headroom (in.)       |     -334.0215 [-1130.701 - 462.6585]
      Intercept            |    12683.31 [8546.885 - 16819.74] **
    R-squared              |                               .22719
    Number of observations |                                   74
    -------------------------------------------------------------
    Alternatively, if you would rather have the stars align in a separate column, consider using dimension instead and add stars as the column specification in your layout. It's dimension title and levels are hidden from the headers by default, and what you'll get is a column with stars. Something like
    Code:
    * version 4
    clear all
    sysuse auto
    
    collect: reg price c.mpg c.headroom
    
    collect composite define ci = _r_lb _r_ub, trim delimiter(" - ")
    collect composite define beta_ci = _r_b ci
    collect style cell result[ci], sformat("[%s]")
    collect style header result[beta_ci], level(hide)
    collect stars _r_p .05 "*" .01 "**", dimension attach(beta_ci)
    collect layout (coleq#colname#result[beta_ci] result[_cons r2 N]) (stars)
    The resulting table in this case is
    Code:
    -------------------------------------------------------------
    Price                  |                                     
      Mileage (mpg)        | -259.1057 [-375.6015 - -142.6098] **
      Headroom (in.)       |  -334.0215 [-1130.701 - 462.6585]   
      Intercept            |    12683.31 [8546.885 - 16819.74] **
    R-squared              |                            .22719   
    Number of observations |                                74   
    -------------------------------------------------------------

    Comment


    • #3
      Thank you Jeff!

      Regarding this point:
      Composite results do not exist as items in the collection, they are built dynamically when collect builds the tables.
      What threw me off a bit is the fact that composite results do appear as proper levels of the result dimension after you construct them:
      Code:
      clear all
      sysuse auto
      
      collect: reg price c.mpg c.headroom
      
      collect stars _r_p .05 "*" .01 "**"
      collect composite define ci = _r_lb _r_ub, trim delimiter(" - ")
      collect composite define beta_ci = _r_b ci stars
      collect levelsof result
      Code:
      . collect levelsof result
      Collection: default
       Dimension: result
          Levels: F N _r_b _r_ci _r_df _r_lb _r_p _r_se _r_ub _r_z _r_z_abs beta beta_ci ci cmd cmdline depvar df_m df_r estat_cmd ll ll_0 marginsok model mss predict properties r2 r2_a rank rmse rss stars sum_w title vce

      And regarding your first solution - is it possible to remove the white space between the stars and the rightmost square brackets?

      Comment


      • #4
        Composite result levels are like regular result levels in every other way, they are just not part of the tags attached to the collected items.

        We will look into adding a nodelimiter option to collect composite define.

        Until then, and depending on the document you want to export to, you could use the UNICODE zero width space. While Stata's SMCL (viewer) output will render a single display width for this character, other output formats like LaTeX, HTML, PDF, MS Word, and MS Excel will render it with zero-width. For example
        Code:
        * version 5
        clear all
        sysuse auto
        
        collect: reg price c.mpg c.headroom
        
        collect stars _r_p .05 "*" .01 "**"
        collect composite define ci = _r_lb _r_ub, trim delimiter(" - ")
        collect composite define beta_ci = _r_b ci
        * delimiter() option contains unicode zero width space [U+200B] in ""
        collect composite define beta_ci_stars = beta_ci stars, trim delimiter("​")
        collect style cell result[ci], sformat("[%s]")
        collect style header result[beta_ci], level(hide)
        collect layout (coleq#colname#result[beta_ci_stars] result[_cons r2 N])
        collect export table.tex, replace
        Here is a screenshot of table.pdf (after lualatex table.tex) from Preview on my Mac.
        Click image for larger version

Name:	Screenshot 2026-06-25 at 2.07.19 PM.png
Views:	1
Size:	57.3 KB
ID:	1786412

        Last edited by Jeff Pitblado (StataCorp); 25 Jun 2026, 13:18.

        Comment


        • #5
          Thanks again Jeff.

          Comment

          Working...
          X