Announcement

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

  • Exporting xthdidregress to an event_plot

    Hello,
    I am using the new xthdidregress command to estimate the following model:
    Code:
    webuse akc, clear
    xtset breed year
    
    xthdidregress aipw (registered best) (movie), group(breed) vce(cluster breed) controlg(never) basetime(common)
    estat aggregation, dynamic graph(ciopts(recast(rcap)))
    My aim is to plot these aggregated results using event_plot, which I can use to combine with other estimators. The problem I am having is to extract the the coefficient vector and the variance-covariance matrix of the aggregate estimators into two matrices. Does anyone knows how I could do it?

    I was only able to extract the vector of coefficients, but I am struggling into creating a matrix aipw_V with the variance covariance. This is what I have done

    Code:
    * Extract my coefficients
    matrix aipw_b = r(table)["b", 1 ...]
    * manually re-name them so that they can be used with event_plot
    matrix colnames aipw_b = F_6 F_5 F_4 F_3 F_2 L_0 L_1 L_2 L_3 L_4 L_5 L_6
    matrix list aipw_b

    thanks a lot in advance for your help

  • #2
    Code:
    mat list r(b)
    mat list r(V)

    Comment


    • #3
      Thanks this was helpful:

      I am coping a complete workaround I've written that does the whole process from estimation to event_plot for those that are interested. There may be more efficient ways. but this works should work.
      Code:
      xthdidregress aipw (registered best) (movie), group(breed) vce(cluster breed) controlg(never) basetime(common)
      estat aggregation, dynamic graph(ciopts(recast(rcap)))
      * Step 1: Extract values from r(b) and r(V)
      
      * Save coeff vector in a new matrix with clean names
      matrix raw_b = r(b)
      local ncols = colsof(raw_b)
      
      matrix csdid_b = J(1, `ncols', .)  // empty 1xN matrix with missing values
      
      forvalues j = 1/`ncols' {
          matrix csdid_b[1, `j'] = raw_b[1, `j']
      }
      mat list csdid_b
      matrix colnames csdid_b = F_6 F_5 F_4 F_3 F_2 L_0 L_1 L_2 L_3 L_4 L_5 L_6
      
      * Save VCoV matrix in a new matrix with clean names
      matrix raw_v = r(V)
      local ncols = colsof(raw_v)
      
      matrix csdid_v = J(`ncols', `ncols', .)
      
      forvalues i = 1/`ncols' {
          forvalues j = 1/`ncols' {
              matrix csdid_v[`i', `j'] = raw_v[`i', `j']
          }
      }
      matrix colnames csdid_v = F_6 F_5 F_4 F_3 F_2 L_0 L_1 L_2 L_3 L_4 L_5 L_6
      matrix rownames csdid_v = F_6 F_5 F_4 F_3 F_2 L_0 L_1 L_2 L_3 L_4 L_5 L_6
      mat list raw_v
      mat list csdid_v
      
      
      
      event_plot csdid_b#csdid_v, ///
          stub_lag(L_#) ///
          stub_lead(F_#) //

      Comment


      • #4
        s
        Last edited by Tom Ford; 13 May 2025, 05:46.

        Comment

        Working...
        X