Announcement

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

  • using collect layout after rdrobust

    I was trying to use collect layout after rdrobust. Everything works fine example the sample size does not appear. I have adapted the example in https://users.ssc.wisc.edu/~dimond/r...ld_tables/reg3.
    First, I rerun the example with "reg" to show that it produces the coefficients and sample sizes. Second, I run the example with "rdrobust" to show that it produces the coefficient but not the sample sizes. Any suggestions on how to fix this?

    clear all
    use https://sscc.wisc.edu/~rdimond/real_world_tables/reg3
    gen x = runiform(0,1)
    gen y = 0.9*x + 0.1*nicu

    local model 1
    foreach outcome in mort6 mort364 {
    foreach low in 0 1 {
    quietly: collect, tag(outcome[`outcome'] wt[`low'] model[`model']): reg `outcome' nets y if low==`low', robust
    collect get controls = "N", tag(outcome[`outcome'] wt[`low'] model[`model'])
    local model = `model' + 1
    quietly: collect, tag(outcome[`outcome'] wt[`low'] controls[Y] model[`model']): reg `outcome' nets y employed if low==`low', robust
    collect get controls = "Y", tag(outcome[`outcome'] wt[`low'] model[`model'])
    local model = `model' + 1
    }
    }
    collect layout (colname[nets y]#result[_r_b _r_se] result[controls N]) (outcome#wt#model)


    clear all
    use https://sscc.wisc.edu/~rdimond/real_world_tables/reg3
    gen x = runiform(0,1)
    gen y = 0.9*x + 0.1*nicu


    local model 1
    foreach outcome in mort6 mort364 {
    foreach low in 0 1 {
    quietly: collect, tag(outcome[`outcome'] wt[`low'] model[`model']): rdrobust `outcome' y if low==`low', c(0.5)
    collect get controls = "N", tag(outcome[`outcome'] wt[`low'] model[`model'])
    local model = `model' + 1
    quietly: collect, tag(outcome[`outcome'] wt[`low'] controls[Y] model[`model']): rdrobust `outcome' y if low==`low', c(0.5)
    collect get controls = "Y", tag(outcome[`outcome'] wt[`low'] model[`model'])
    local model = `model' + 1
    }
    }
    collect layout (colname[RD_Estimate]#result[_r_b _r_se] result[controls N]) (outcome#wt#model)



  • #2
    The trouble here is that rdrobust leaves extra stuff in r(), like a scalar r(N), and the collect: prefix consumes both scalar items tagged as result[N], one that is tagged program_class[rclass] and the one you want that is tagged program_class[eclass]. Duplicate items for a cell specification are ignored.

    The easiest work-around for this is to use collect get e() after the calls to rdrobust instead of the collect: prefix syntax.

    BTW, you have an extra/unused tag element controls[Y] in the second collected model in the nested foreach loops.

    Here is a modified version of your rdrobust code.
    Code:
    clear all
    use https://sscc.wisc.edu/~rdimond/real_world_tables/reg3
    gen x = runiform(0,1)
    gen y = 0.9*x + 0.1*nicu
    
    
    local model 1
    foreach outcome in mort6 mort364 {
    foreach low in 0 1 {
    quietly rdrobust `outcome' y if low==`low', c(0.5)
    collect get e(), tag(outcome[`outcome'] wt[`low'] model[`model'])
    collect get controls = "N", tag(outcome[`outcome'] wt[`low'] model[`model'])
    local model = `model' + 1
    quietly rdrobust `outcome' y if low==`low', c(0.5)
    collect get e(), tag(outcome[`outcome'] wt[`low'] model[`model'])
    collect get controls = "Y", tag(outcome[`outcome'] wt[`low'] model[`model'])
    local model = `model' + 1
    }
    }
    collect layout (colname[RD_Estimate]#result[_r_b _r_se] result[controls N]) (outcome#wt#model)
    Here is the resulting table.
    Code:
    -------------------------------------------------------------------------------------------
                  |    mort6    mort6     mort6     mort6  mort364  mort364   mort364   mort364
                  |        0        0         1         1        0        0         1         1
                  |        1        2         3         4        5        6         7         8
    --------------+----------------------------------------------------------------------------
    RD_Estimate   |                                                                            
      Coefficient | .0427648 .0427648 -.0041633 -.0041633 .0420607 .0420607 -.0176258 -.0176258
      Std. error  | .0461336 .0461336  .0669074  .0669074 .0393692 .0393692  .0675356  .0675356
    controls      |        N        Y         N         Y        N        Y         N         Y
    N             |     6922     6922      3078      3078     6922     6922      3078      3078
    -------------------------------------------------------------------------------------------

    Comment


    • #3
      Thank you so much for the explanation for why my program was not working and for the fixed version of my program

      Comment

      Working...
      X