Announcement

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

  • Make a Command Esttab-able

    When you use my user written command fdid to do
    Code:
    clear *
    cls
    net install fdid, from("https://raw.githubusercontent.com/jgreathouse9/FDIDTutorial/main") replace
    
    net get fdid, from("https://raw.githubusercontent.com/jgreathouse9/FDIDTutorial/main") replace
    
    qui u smoking, clear
    
    fdid cigsale, tr(treated) unitnames(state)
    
    ereturn list
    you get
    Code:
    scalars:
                     e(T1) =  19
                     e(T0) =  20
                     e(T2) =  12
                      e(T) =  31
                     e(r2) =  .9989
                   e(DDr2) =  .6039
                   e(rmse) =  1.2821
                    e(N0U) =  4
                  e(DDATT) =  -27.3491
                 e(pDDATT) =  -31.1852
                   e(pATT) =  -18.4423
                   e(CILB) =  -14.5486
                    e(ATT) =  -13.6467
                   e(CIUB) =  -12.7448
                     e(se) =  .4602
                  e(tstat) =  29.66
    
    macros:
                    e(cmd) : "."
                      e(U) : "Montana, Colorado, Nevada, Connecticut,"
    
    matrices:
                 e(series) :  31 x 9
                e(results) :  1 x 8
    The table of interest, specifically, is
    Code:
    Forward Difference-in-Differences          T0 R2:     0.999     T0 RMSE:     1.282
    -----------------------------------------------------------------------------------------
         cigsale |     ATT       Std. Err.      t       P>|t|    [95% Conf. Interval]
    -------------+---------------------------------------------------------------------------
         treated | -13.64671     0.46016      29.66     0.000    -14.54861  -12.74481
    -----------------------------------------------------------------------------------------
    Treated Unit: California
    FDID selects Montana, Colorado, Nevada, Connecticut, as the optimal donors.
    See Li (2024) for technical details.
    Okay, this is well and good. But, I want to make this esttab-able (by Ben Jann, of course, on ssc). At present, when I do
    Code:
    clear *
    cls
    //net install fdid, from("https://raw.githubusercontent.com/jgreathouse9/FDIDTutorial/main") replace
    
    //net get fdid, from("https://raw.githubusercontent.com/jgreathouse9/FDIDTutorial/main") replace
    
    qui u smoking, clear
    
    fdid cigsale, tr(treated) unitnames(state)
    esttab
    I get
    Code:
    ----------------------------
                          (1)   
                                
    ----------------------------
    ----------------------------
    N                           
    ----------------------------
    t statistics in parentheses
    * p<0.05, ** p<0.01, *** p<0.001
    Okay, well.... how would I be able to reproduce the table fdid prints, with esttab. Presumably, I must do something under the hood. For reference, the table to start with would be
    Code:
    mat l e(results)
    
    e(results)[1,8]
                       ATT        PATT          SE           t          LB          UB          R2        RMSE
    Statistics  -13.646711  -18.442321   .46016222   29.656305  -14.548612   -12.74481   .99890459     1.28215
    Perhaps daniel klein or Bjarte Aagnes would be able to comment, should they be available?

  • #2
    The default for esttab is to use the coefficients matrix e(b) and the variance matrix e(V). Of course, the user can refer to any stored matrix via the -cells()- option, but you need the two aforementioned matrices to make the output available by simply running esttab.

    Comment


    • #3
      Andrew has answered the question. esttab looks for e(b) and e(V). I cannot readily recall whether it re-computes the remaining elements (test statistics, p-values, CIs); it might, and in this case, you probably want to put auxiliary information, like degrees of freedom, into the right places, too. As Andrew notes, esttab and similar alternatives (that must not be named) typically have hooks to specify where the necessary information is stored.

      When you do make e(b) and e(V) available, you might want to be sure other post-estimation commands, like test, predict, etc., work -- or fail -- as expected.

      Comment


      • #4
        Very well. I was looking through the help for sdid (a command quite similar to mine), and I (don't think) they did it like that, but I suspected it had something to do with it being e(b) and such.

        So, I'll do that at some point before I submit to SJ. Thanks so much!


        EDIT: yep, here it is for SDID

        Code:
        *for esttab and eststo
        if "`vce'"!="noinference" {
        matrix b=`ATT'
        matrix V=`se'^2
        matrix colnames b=`4'
        matrix rownames b=`1'
        matrix colnames V=`4'
        matrix rownames V=`4'
        ereturn post b V, depname(`1') obs(`Ntotal')
        }
        I'll adapt it to my own, then.
        Last edited by Jared Greathouse; 30 Jul 2024, 16:18.

        Comment


        • #5
          Don't know it this is helpful, but you could also type:

          Code:
          fdid cigsale, tr(treated) unitnames(state)
          esttab, cell(results)
          ben

          Comment


          • #6
            I didn't know it could be done like that, but yeah that's helpful!

            Comment

            Working...
            X