Announcement

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

  • How to add a custom row (e.g., "Controls: Yes/No") to a collect table?

    Dear Statalist,

    I am using StataNow 18.5 and working with the new collect suite of commands to export regression results. I would like to add a custom row to the table, such as a note indicating whether a certain control was included in the model. Specifically, I would like to replicate what is easily done using esttab and estadd, as in the following example:
    Code:
    sysuse auto, clear
    eststo reg1: reg price mpg, r
    quietly estadd local foreign_controls "No", replace
    eststo reg2: reg price mpg foreign, r
    quietly estadd local foreign_controls "Yes", replace
    esttab reg1 reg2, b(2) se(2) parentheses star(* 0.10 ** 0.05 *** 0.01) keep(mpg) ///
        stats(foreign_controls N, fmt(0 0) labels("Control for Foreign" "Observations"))
    This produces a nicely formatted table with a row called “Control for Foreign” showing "No" and "Yes" for each model.

    I am now attempting to do something similar using the collect framework:
    Code:
    collect clear
    sysuse auto, clear
    collect: reg price mpg, r
    collect: reg price mpg foreign, r
    collect addtags extra[N], fortags(result[N]#cmdset[1])
    collect addtags extra[N], fortags(result[N]#cmdset[2])
    collect layout (colname[mpg]#result[_r_b _r_se] extra) (cmdset)
    This works well to show coefficient and observation rows, but I don’t see how to add a user-defined row like "Control for Foreign". I want this information included in the table layout, even though I am intentionally omitting the foreign coefficient itself.
    Is there a way to manually add a custom string result to a specific cell in a collect table? Or a better approach to achieve this kind of labeling?

    Thank you in advance for any guidance.
    Last edited by Theo Van Ostrom; 04 May 2025, 10:23. Reason: typos

  • #2
    Thanks for the reproducible example. See

    Code:
    help collect get

    Code:
    collect clear
    sysuse auto, clear
    collect: reg price mpg, r
    collect: reg price mpg foreign, r
    collect addtags extra[N], fortags(result[N]#cmdset[1])
    collect addtags extra[N], fortags(result[N]#cmdset[2])
    collect layout (colname[mpg]#result[_r_b _r_se] extra) (cmdset)
    collect get Whatever= "Yes", tags(Whatever[1] cmdset[1])
    collect get Whatever= "No", tags(Whatever[1] cmdset[2])
    collect label levels Whatever 1 "Whatever", modify
    collect layout (colname[mpg]#result[_r_b _r_se] extra Whatever) (cmdset)
    Res.:

    Code:
    . collect layout (colname[mpg]#result[_r_b _r_se] extra Whatever) (cmdset)
    
    Collection: default
          Rows: colname[mpg]#result[_r_b _r_se] extra Whatever
       Columns: cmdset
       Table 1: 5 x 2
    
    -----------------------------------
                  |         1         2
    --------------+--------------------
    Mileage (mpg) |                    
      Coefficient | -238.8943 -294.1955
      Std. error  |  57.47701  60.33645
    N             |        74        74
    Whatever      |       Yes        No
    -----------------------------------

    Comment


    • #3
      That did it! Thank you so much Andrew!

      Comment

      Working...
      X