Announcement

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

  • how to use HonestDID results stored in s(HonestEventStudy)

    Hello

    I'm using the HonestDID package from SSC in Stata 18. It works fine, but I can't figure out how I can use the stored results after I run my honestdid command. Specifically, I'm interested in the results saved under `s(HonestEventStudy)'.CI but I have never used mata before or results stored in s(). I know I can type
    Code:
    mata `s(HonestEventStudy)'.CI
    and that will show me the results but I don't know how I can extract those results to a matrix.

    The reason I want to use these stored results is because I want to plot them on a graph. I know that honestdid can create a coefplot, but as far as I understand that only works with one set of results. I want to run honestdid several times for different post-treatment periods and then show all those results on one single graph.

    Any help would be much appreciated.

    Cristina

  • #2
    The result is a matrix in Mata. `s(HonestEventStudy)' refers to a local macro that stores part of the matrix’s name. You can use the Mata function st_matrix to export this matrix to Stata.

    Code:
    local mixtape https://raw.githubusercontent.com/Mixtape-Sessions
    use `mixtape'/Advanced-DID/main/Exercises/Data/ehec_data.dta, clear
    qui sum year, meanonly
    replace yexp2 = cond(mi(yexp2), r(max) + 1, yexp2)
    qui csdid dins, time(year) ivar(stfips) gvar(yexp2) long2 notyet
    csdid_estat event, window(-4 5) estore(csdid)
    estimates restore csdid
    
    local plotopts xtitle(Mbar) ytitle(95% Robust CI)
    honestdid, pre(3/6) post(7/12) mvec(0.5(0.5)2) coefplot `plotopts'
    mata `s(HonestEventStudy)'.CI
    
    mata: st_matrix("CI", `s(HonestEventStudy)'.CI)
    mat list CI

    Res.:

    Code:
    . honestdid, pre(3/6) post(7/12) mvec(0.5(0.5)2) coefplot `plotopts'
    
    |    M    |   lb   |   ub   |
    | ------- | ------ | ------ |
    |       . |  0.033 |  0.057 | (Original)
    |  0.5000 |  0.030 |  0.059 | 
    |  1.0000 |  0.023 |  0.064 | 
    |  1.5000 |  0.016 |  0.071 | 
    |  2.0000 |  0.008 |  0.078 | 
    (method = C-LF, Delta = DeltaRM, alpha = 0.050)
    
    . 
    . mata `s(HonestEventStudy)'.CI
                     1             2             3
        +-------------------------------------------+
      1 |            .   .0334787306   .0570716896  |
      2 |           .5   .0298482026   .0589743929  |
      3 |            1    .023418879   .0638467748  |
      4 |          1.5   .0159335787    .070739093  |
      5 |            2   .0081327981   .0781878814  |
        +-------------------------------------------+
    
    . 
    . 
    . 
    . mata: st_matrix("CI", `s(HonestEventStudy)'.CI)
    
    . 
    . mat list CI
    
    CI[5,3]
               c1         c2         c3
    r1          .  .03347873  .05707169
    r2         .5   .0298482  .05897439
    r3          1  .02341888  .06384677
    r4        1.5  .01593358  .07073909
    r5          2   .0081328  .07818788


    Comment


    • #3
      Thank you very much Andrew!

      Comment

      Working...
      X