Announcement

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

  • Bootstrap error.

    Hi All,

    Still hoping for some help to resolve a bootstrap error message. Here is the code I am trying to run with the error message:

    Code:
    . capture program drop myboot
    
    . program define myboot, rclass
      1. 
    . * first stage
    . reghdfe COVID Female age75plus Asian Black Hispanic lnPopDensity tavg lnprcp CumMonthsSAH lnnursing_visits deaths_rate  cum_
    > num_vacpct, absorb(grpatid monthlydate state, save) cluster(grpatid) residuals(resid) 
      2. predict double COVID_fe, r
      3. 
    . * second stage  
    . eststo: stcrreg Female age75plus Asian Black Hispanic COVID COVID_fe, compete(d2=2)
      4. estimates store twoSLS1
      5. 
    . end
    
    . xtset, clear
    
    . bootstrap _b, reps(1000) seed(123): myboot
    (running myboot on estimation sample)
    
    Bootstrap replications (1,000): xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx done
    x: Error occurred when bootstrap executed myboot.
    insufficient observations to compute bootstrap standard errors
    no results will be saved
    r(2000);
    
    end of do-file
    
    r(2000);
    Without the bootstrapping the competing risk regression runs fine. d2 is the failure variable with d2=1 as the main failure event and d2=2 being the competing risk event, with the following distribution:

    . tab d2, miss

    d2 | Freq. Percent Cum.
    ------------+-----------------------------------
    0 | 47,948 94.98 94.98
    1 | 158 0.31 95.30
    2 | 2,374 4.70 100.00
    ------------+-----------------------------------
    Total | 50,480 100.00


    Could the error message be because the failure event is rare (i.e., only 0.31%)? I have also tried more reps (up to a million) and get the same error message.

    I would be grateful for any help you may be able to offer.
    Many thanks in advance,
    Sumedha

    P.S. Here is a dataex in case helpful.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(COVID Female age75plus) byte(Asian Black Hispanic) float(lnPopDensity tavg lnprcp CumMonthsSAH lnnursing_visits deaths_rate cum_num_vacpct grpatid monthlydate) str24 state float d2 byte(_st _d _t _t0)
    0 0 0 0 0 0 4.597138  26.89387  4.625463 0  11.36908 0 0 7389284 714 "AL" 0 1 0 1 0
    0 1 1 0 0 0 4.597138  26.89387  4.625463 0  11.36908 0 0 5707464 714 "AL" 0 1 0 1 0
    0 1 1 1 0 0 4.597138  26.89387  4.625463 0  11.36908 0 0 7312555 714 "AL" 2 1 0 1 0
    0 1 1 0 0 0 4.597138  26.89387  4.625463 0  11.36908 0 0 6168903 714 "AL" 2 1 0 1 0
    0 1 0 0 1 0 4.597138  26.89387  4.625463 0  11.36908 0 0 7009023 714 "AL" 0 1 0 1 0
    0 1 1 0 1 0 4.597138  26.89387  4.625463 0  11.36908 0 0 6340785 714 "AL" 0 1 0 1 0
    0 0 0 0 1 0 4.597138  26.89387  4.625463 0  11.36908 0 0  861670 714 "AL" 2 1 0 1 0
    0 1 0 0 1 0 4.597138  26.89387  4.625463 0  11.36908 0 0 1170181 714 "AL" 0 1 0 1 0
    0 0 1 0 0 0 4.597138  26.89387  4.625463 0  11.36908 0 0 1921660 714 "AL" 0 1 0 1 0
    0 1 0 0 0 0 4.597138  26.89387  4.625463 0  11.36908 0 0 2971145 714 "AL" 0 1 0 1 0
    0 1 1 0 1 0 4.597138  26.89387  4.625463 0  11.36908 0 0  706786 714 "AL" 0 1 0 1 0
    0 1 0 0 1 0 4.597138  26.89387  4.625463 0  11.36908 0 0 4296355 714 "AL" 0 1 0 1 0
    0 0 0 0 1 0 4.597138  26.89387  4.625463 0  11.36908 0 0 7212486 714 "AL" 0 1 0 1 0
    0 1 0 0 1 0 4.597138  26.89387  4.625463 0  11.36908 0 0 7042124 714 "AL" 2 1 0 1 0
    0 0 0 0 0 0 4.597138  26.89387  4.625463 0  11.36908 0 0 6317893 714 "AL" 2 1 0 1 0
    0 1 1 0 0 0 4.597138  26.89387  4.625463 0  11.36908 0 0 6502335 714 "AL" 0 1 0 1 0
    0 1 0 0 1 0 4.597138  26.89387  4.625463 0  11.36908 0 0 4968653 714 "AL" 0 1 0 1 0
    0 1 1 0 0 0 4.597138  26.89387  4.625463 0  11.36908 0 0 1135025 714 "AL" 0 1 0 1 0
    0 1 0 0 0 0 4.597138  26.89387  4.625463 0  11.36908 0 0 7346079 714 "AL" 2 1 0 1 0
    0 0 1 0 1 0 4.597138  26.89387  4.625463 0  11.36908 0 0 1927784 714 "AL" 0 1 0 1 0
    0 0 0 0 1 0 4.597138  26.89387  4.625463 0  11.36908 0 0 5707029 714 "AL" 0 1 0 1 0
    0 1 0 0 1 0 4.597138  26.89387  4.625463 0  11.36908 0 0 7474901 714 "AL" 0 1 0 1 0
    0 0 0 0 0 0 4.597138  26.89387  4.625463 0  11.36908 0 0 7564318 714 "AL" 0 1 0 1 0
    0 0 1 0 0 0 4.597138 26.844194  4.842059 0 11.405563 0 0 1921660 715 "AL" 0 1 0 2 1
    0 1 1 0 0 0 4.597138 26.844194  4.842059 0 11.405563 0 0 1135025 715 "AL" 0 1 0 2 1
    0 1 0 0 1 0 4.597138 26.844194  4.842059 0 11.405563 0 0 1170181 715 "AL" 0 1 0 2 1
    0 1 1 0 0 0 4.597138 26.844194  4.842059 0 11.405563 0 0 5707464 715 "AL" 0 1 0 2 1
    0 1 1 1 0 0 4.597138 26.844194  4.842059 0 11.405563 0 0 7312555 715 "AL" 2 1 0 2 1
    0 1 0 0 1 0 4.597138 26.844194  4.842059 0 11.405563 0 0 4968653 715 "AL" 0 1 0 2 1
    0 1 0 0 1 0 4.597138 26.844194  4.842059 0 11.405563 0 0 7009023 715 "AL" 0 1 0 2 1
    0 1 1 0 1 0 4.597138 26.844194  4.842059 0 11.405563 0 0  706786 715 "AL" 0 1 0 2 1
    0 1 0 0 1 0 4.597138 26.844194  4.842059 0 11.405563 0 0 4296355 715 "AL" 0 1 0 2 1
    0 1 1 0 0 0 4.597138 26.844194  4.842059 0 11.405563 0 0 6502335 715 "AL" 0 1 0 2 1
    0 1 1 0 1 0 4.597138 26.844194  4.842059 0 11.405563 0 0 6340785 715 "AL" 0 1 0 2 1
    0 0 0 0 0 0 4.597138 26.844194  4.842059 0 11.405563 0 0 6317893 715 "AL" 2 1 0 2 1
    0 0 0 0 1 0 4.597138 26.844194  4.842059 0 11.405563 0 0  861670 715 "AL" 2 1 0 2 1
    0 1 0 0 0 0 4.597138 26.844194  4.842059 0 11.405563 0 0 2971145 715 "AL" 0 1 0 2 1
    0 0 0 0 1 0 4.597138 26.844194  4.842059 0 11.405563 0 0 5707029 715 "AL" 0 1 0 2 1
    0 0 0 0 0 0 4.597138 26.844194  4.842059 0 11.405563 0 0 7564318 715 "AL" 0 1 0 2 1
    0 1 0 0 1 0 4.597138 26.844194  4.842059 0 11.405563 0 0 7042124 715 "AL" 2 1 0 2 1
    0 1 0 0 0 0 4.597138 26.844194  4.842059 0 11.405563 0 0 7346079 715 "AL" 2 1 0 2 1
    0 0 0 0 1 0 4.597138 26.844194  4.842059 0 11.405563 0 0 7212486 715 "AL" 0 1 0 2 1
    0 1 1 0 0 0 4.597138 26.844194  4.842059 0 11.405563 0 0 6168903 715 "AL" 2 1 0 2 1
    0 0 0 0 0 0 4.597138 26.844194  4.842059 0 11.405563 0 0 7389284 715 "AL" 0 1 0 2 1
    0 0 1 0 1 0 4.597138 26.844194  4.842059 0 11.405563 0 0 1927784 715 "AL" 0 1 0 2 1
    0 1 0 0 1 0 4.597138 26.844194  4.842059 0 11.405563 0 0 7474901 715 "AL" 0 1 0 2 1
    0 1 1 1 0 0 4.597138 26.732334 1.9600948 0 11.406064 0 0 7312555 716 "AL" 2 1 0 3 2
    0 0 0 0 0 0 4.597138 26.732334 1.9600948 0 11.406064 0 0 7564318 716 "AL" 0 1 0 3 2
    0 0 1 0 1 0 4.597138 26.732334 1.9600948 0 11.406064 0 0 1927784 716 "AL" 0 1 0 3 2
    0 1 1 0 0 0 4.597138 26.732334 1.9600948 0 11.406064 0 0 6502335 716 "AL" 0 1 0 3 2
    0 0 0 0 1 0 4.597138 26.732334 1.9600948 0 11.406064 0 0  861670 716 "AL" 2 1 0 3 2
    0 0 0 0 0 0 4.597138 26.732334 1.9600948 0 11.406064 0 0 7389284 716 "AL" 0 1 0 3 2
    0 0 0 0 1 0 4.597138 26.732334 1.9600948 0 11.406064 0 0 7212486 716 "AL" 0 1 0 3 2
    0 1 0 0 1 0 4.597138 26.732334 1.9600948 0 11.406064 0 0 7009023 716 "AL" 0 1 0 3 2
    0 1 0 0 1 0 4.597138 26.732334 1.9600948 0 11.406064 0 0 7042124 716 "AL" 2 1 0 3 2
    0 1 1 0 1 0 4.597138 26.732334 1.9600948 0 11.406064 0 0 6340785 716 "AL" 0 1 0 3 2
    0 0 0 0 1 0 4.597138 26.732334 1.9600948 0 11.406064 0 0 5707029 716 "AL" 0 1 0 3 2
    0 1 1 0 0 0 4.597138 26.732334 1.9600948 0 11.406064 0 0 5707464 716 "AL" 0 1 0 3 2
    0 1 0 0 1 0 4.597138 26.732334 1.9600948 0 11.406064 0 0 7474901 716 "AL" 0 1 0 3 2
    0 1 0 0 1 0 4.597138 26.732334 1.9600948 0 11.406064 0 0 1170181 716 "AL" 0 1 0 3 2
    0 0 1 0 0 0 4.597138 26.732334 1.9600948 0 11.406064 0 0 1921660 716 "AL" 0 1 0 3 2
    0 1 0 0 1 0 4.597138 26.732334 1.9600948 0 11.406064 0 0 4296355 716 "AL" 0 1 0 3 2
    0 0 0 0 0 0 4.597138 26.732334 1.9600948 0 11.406064 0 0 6317893 716 "AL" 2 1 0 3 2
    0 1 1 0 0 0 4.597138 26.732334 1.9600948 0 11.406064 0 0 6168903 716 "AL" 2 1 0 3 2
    0 1 0 0 0 0 4.597138 26.732334 1.9600948 0 11.406064 0 0 2971145 716 "AL" 0 1 0 3 2
    0 1 0 0 0 0 4.597138 26.732334 1.9600948 0 11.406064 0 0 7346079 716 "AL" 2 1 0 3 2
    0 1 1 0 0 0 4.597138 26.732334 1.9600948 0 11.406064 0 0 1135025 716 "AL" 0 1 0 3 2
    0 1 0 0 1 0 4.597138 26.732334 1.9600948 0 11.406064 0 0 4968653 716 "AL" 0 1 0 3 2
    0 1 1 0 1 0 4.597138 26.732334 1.9600948 0 11.406064 0 0  706786 716 "AL" 0 1 0 3 2
    0 1 0 0 1 0 4.597138 19.743225  5.197447 0 11.375776 0 0 1170181 717 "AL" 0 1 0 4 3
    0 1 1 0 0 0 4.597138 19.743225  5.197447 0 11.375776 0 0 6502335 717 "AL" 0 1 0 4 3
    0 1 0 0 1 0 4.597138 19.743225  5.197447 0 11.375776 0 0 7042124 717 "AL" 2 1 0 4 3
    0 1 0 0 1 0 4.597138 19.743225  5.197447 0 11.375776 0 0 7474901 717 "AL" 0 1 0 4 3
    0 0 1 0 0 0 4.597138 19.743225  5.197447 0 11.375776 0 0 1921660 717 "AL" 0 1 0 4 3
    0 1 0 0 1 0 4.597138 19.743225  5.197447 0 11.375776 0 0 4296355 717 "AL" 0 1 0 4 3
    0 1 1 0 0 0 4.597138 19.743225  5.197447 0 11.375776 0 0 1135025 717 "AL" 0 1 0 4 3
    0 1 1 0 0 0 4.597138 19.743225  5.197447 0 11.375776 0 0 6168903 717 "AL" 2 1 0 4 3
    0 1 0 0 1 0 4.597138 19.743225  5.197447 0 11.375776 0 0 4968653 717 "AL" 0 1 0 4 3
    0 0 0 0 1 0 4.597138 19.743225  5.197447 0 11.375776 0 0 5707029 717 "AL" 0 1 0 4 3
    0 0 0 0 0 0 4.597138 19.743225  5.197447 0 11.375776 0 0 7564318 717 "AL" 0 1 0 4 3
    0 0 0 0 0 0 4.597138 19.743225  5.197447 0 11.375776 0 0 6317893 717 "AL" 2 1 0 4 3
    0 1 0 0 0 0 4.597138 19.743225  5.197447 0 11.375776 0 0 2971145 717 "AL" 0 1 0 4 3
    0 1 1 0 1 0 4.597138 19.743225  5.197447 0 11.375776 0 0  706786 717 "AL" 0 1 0 4 3
    0 1 0 0 1 0 4.597138 19.743225  5.197447 0 11.375776 0 0 7009023 717 "AL" 0 1 0 4 3
    0 1 1 0 1 0 4.597138 19.743225  5.197447 0 11.375776 0 0 6340785 717 "AL" 0 1 0 4 3
    0 0 0 0 1 0 4.597138 19.743225  5.197447 0 11.375776 0 0  861670 717 "AL" 2 1 0 4 3
    0 1 1 1 0 0 4.597138 19.743225  5.197447 0 11.375776 0 0 7312555 717 "AL" 2 1 0 4 3
    0 1 0 0 0 0 4.597138 19.743225  5.197447 0 11.375776 0 0 7346079 717 "AL" 2 1 0 4 3
    0 0 1 0 1 0 4.597138 19.743225  5.197447 0 11.375776 0 0 1927784 717 "AL" 0 1 0 4 3
    0 1 1 0 0 0 4.597138 19.743225  5.197447 0 11.375776 0 0 5707464 717 "AL" 0 1 0 4 3
    0 0 0 0 0 0 4.597138 19.743225  5.197447 0 11.375776 0 0 7389284 717 "AL" 0 1 0 4 3
    0 0 0 0 1 0 4.597138 19.743225  5.197447 0 11.375776 0 0 7212486 717 "AL" 0 1 0 4 3
    0 0 0 0 0 0 4.597138    10.332 4.4127984 0 11.393387 0 0 7389284 718 "AL" 0 1 0 5 4
    0 1 0 0 1 0 4.597138    10.332 4.4127984 0 11.393387 0 0 4968653 718 "AL" 0 1 0 5 4
    0 1 0 0 0 0 4.597138    10.332 4.4127984 0 11.393387 0 0 2971145 718 "AL" 0 1 0 5 4
    0 1 0 0 1 0 4.597138    10.332 4.4127984 0 11.393387 0 0 7474901 718 "AL" 0 1 0 5 4
    0 0 0 0 1 0 4.597138    10.332 4.4127984 0 11.393387 0 0 7212486 718 "AL" 0 1 0 5 4
    0 1 0 0 1 0 4.597138    10.332 4.4127984 0 11.393387 0 0 4296355 718 "AL" 0 1 0 5 4
    0 0 1 0 1 0 4.597138    10.332 4.4127984 0 11.393387 0 0 1927784 718 "AL" 0 1 0 5 4
    0 1 1 0 1 0 4.597138    10.332 4.4127984 0 11.393387 0 0  706786 718 "AL" 0 1 0 5 4
    end
    format %tm monthlydate
    label values COVID COVID
    label def COVID 0 "No confirmed COVID-19", modify

  • #2
    I think this is perhaps the third attempt you have made to get help with this.
    In this example data, it is not true that program myboot runs without the bootstrap. It does not, and when I unpack it, it fails right at the -reghdfe- part. That, in turn, is happening because in this example data all of the regression variables are constant within the absorbed variables grpatid monthlydate or state, so all of them are omitted and there is no data to support a regression.

    Now, I can't be sure that the same is true in your full data set. Your output suggests that the bootstrap is actually going through all the iterations, although each iteration fails. With the example data, we never even get to iteration 1. I think it is failing on its preliminary run of -myboot- on the whole data sample that it does before it does the bootstrap samples.

    So, you need to come up with a -dataex- example that actually reproduces the behavior you are getting. The current one is actually unusable for the commands in question. It may take you some trial and error to find a sample that will actually run through -myboot- without the -bootstrap-. When you find one like that, check and see if it reproduces the problem with -bootstrap- you are having, and, if so, try reposting here with that. I can't say for sure, but as I don't see anything obviously wrong with the code, I suspect that the problem is with your data. But at present I can't say anything more specific about it.

    Comment


    • #3
      A strategy for investigating failures like this is to strip back the problem to a single RHS variable and remove any options. If that works, then add back variables and options one at a time till it fails. That can pinpoint the source of the problem, which, as Schechter says,is likely with the data, not the code. You don't need a lot of reps at this stage.

      Comment


      • #4
        Prof. Schechter,
        It is indeed my third attempt to get help as I am lost with this one.

        So here is the output using 5% random sample of the data without the bootstrap:

        Code:
        . * first stage
        . reghdfe COVID Female age75plus Asian Black Hispanic lnPopDensity tavg lnprcp CumMonthsSAH lnnursing_visits deaths_rate  cum_
        > num_vacpct, absorb(grpatid monthlydate state, save) cluster(grpatid) residuals(resid) 
        (dropped 14 singleton observations)
        note: Female is probably collinear with the fixed effects (all partialled-out values are close to zero; tol = 1.0e-09)
        note: Asian is probably collinear with the fixed effects (all partialled-out values are close to zero; tol = 1.0e-09)
        note: Black is probably collinear with the fixed effects (all partialled-out values are close to zero; tol = 1.0e-09)
        note: Hispanic is probably collinear with the fixed effects (all partialled-out values are close to zero; tol = 1.0e-09)
        note: lnPopDensity is probably collinear with the fixed effects (all partialled-out values are close to zero; tol = 1.0e-09)
        (MWFE estimator converged in 5 iterations)
        note: Female omitted because of collinearity
        note: Asian omitted because of collinearity
        note: Black omitted because of collinearity
        note: Hispanic omitted because of collinearity
        note: lnPopDensity omitted because of collinearity
        
        HDFE Linear regression                            Number of obs   =     48,828
        Absorbing 3 HDFE groups                           F(   7,   1760) =       1.76
        Statistics robust to heteroskedasticity           Prob > F        =     0.0905
                                                          R-squared       =     0.4476
                                                          Adj R-squared   =     0.4259
                                                          Within R-sq.    =     0.0019
        Number of clusters (grpatid) =      1,761         Root MSE        =     0.1131
        
                                        (Std. err. adjusted for 1,761 clusters in grpatid)
        ----------------------------------------------------------------------------------
                         |               Robust
                   COVID | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
        -----------------+----------------------------------------------------------------
                  Female |          0  (omitted)
               age75plus |  -.0097208   .0113265    -0.86   0.391    -.0319355    .0124939
                   Asian |          0  (omitted)
                   Black |          0  (omitted)
                Hispanic |          0  (omitted)
            lnPopDensity |          0  (omitted)
                    tavg |   .0004537   .0002229     2.04   0.042     .0000166    .0008909
                  lnprcp |   .0001389   .0004997     0.28   0.781    -.0008411    .0011188
            CumMonthsSAH |  -.0102566   .0077387    -1.33   0.185    -.0254347    .0049214
        lnnursing_visits |  -.0237824   .0277872    -0.86   0.392    -.0782818    .0307169
             deaths_rate |   .0001522   .0000772     1.97   0.049     7.40e-07    .0003038
          cum_num_vacpct |   2.18e-06    .000272     0.01   0.994    -.0005313    .0005356
                   _cons |   .2842873   .3198149     0.89   0.374    -.3429698    .9115444
        ----------------------------------------------------------------------------------
        
        Absorbed degrees of freedom:
        -----------------------------------------------------+
         Absorbed FE | Categories  - Redundant  = Num. Coefs |
        -------------+---------------------------------------|
             grpatid |      1761        1761           0    *|
         monthlydate |        30           0          30     |
               state |        47           1          46     |
        -----------------------------------------------------+
        * = FE nested within cluster; treated as redundant for DoF computation
        
        . predict double COVID_fe, r
        (1,652 missing values generated)
        
        . 
        . * second stage  
        . eststo: stcrreg Female age75plus Asian Black Hispanic COVID COVID_fe, compete(d2=2)
        
                 Failure _d: d2==1
           Analysis time _t: stop
          Enter on or after: time start
                ID variable: grpatid
        
        Iteration 0:  Log pseudolikelihood = -1053.6093  
        Iteration 1:  Log pseudolikelihood =  -1053.569  
        Iteration 2:  Log pseudolikelihood =  -1053.569  
        
        Competing-risks regression                        No. of obs      =     48,828
                                                          No. of subjects =      1,761
        Failure event:   d2 == 1                          No. failed      =        145
        Competing event: d2 == 2                          No. competing   =        143
                                                          No. censored    =      1,473
        
                                                          Wald chi2(7)    =      45.15
        Log pseudolikelihood =  -1053.569                 Prob > chi2     =     0.0000
        
                                    (Std. err. adjusted for 1,761 clusters in grpatid)
        ------------------------------------------------------------------------------
                     |               Robust
                  _t |        SHR   std. err.      z    P>|z|     [95% conf. interval]
        -------------+----------------------------------------------------------------
              Female |   1.608563   .2878161     2.66   0.008     1.132752    2.284238
           age75plus |    2.92114   .5404785     5.79   0.000     2.032639    4.198018
               Asian |   .9183988   .4732182    -0.17   0.869     .3345319    2.521303
               Black |   1.160182   .2990622     0.58   0.564     .7000201    1.922834
            Hispanic |   .7267613   .2160009    -1.07   0.283     .4058877    1.301301
               COVID |   1.689308   .7308934     1.21   0.226     .7234848    3.944468
            COVID_fe |    .829826   .4066926    -0.38   0.703     .3175546    2.168481
        ------------------------------------------------------------------------------
        (est72 stored)
        
        . estimates store twoSLS1
        So, definitely some variables (Female Asian Black Hispanic) are constant within the absorbed variables (individual FE grpatid) in the first stage reghdfe, without myboot program it seems to run through still. Perhaps I can run myboot program without the bootstrap too to check, but I am not sure how to modify the myboot program to run it without the bootstrap.

        Grateful for your help.
        Sincerely,
        Sumedha

        Comment


        • #5
          Prof. Schechter,
          I actually figured out how to run myboot w/o the bootstrap and here are the results (identical as above):

          Code:
          . capture program drop myboot
          
          . program define myboot, rclass
            1. 
          . * first stage
          . reghdfe COVID Female age75plus Asian Black Hispanic lnPopDensity tavg lnprcp CumMonthsSAH lnnursing_visits deaths_rate  cum_
          > num_vacpct, absorb(grpatid monthlydate state, save) cluster(grpatid) residuals(resid) 
            2. predict double COVID_fe, r
            3. 
          . * second stage  
          . eststo: stcrreg Female age75plus Asian Black Hispanic COVID COVID_fe, compete(d2=2)
            4. estimates store twoSLS1
            5. 
          . end
          
          . 
          . myboot
          (dropped 14 singleton observations)
          note: Female is probably collinear with the fixed effects (all partialled-out values are close to zero; tol = 1.0e-09)
          note: Asian is probably collinear with the fixed effects (all partialled-out values are close to zero; tol = 1.0e-09)
          note: Black is probably collinear with the fixed effects (all partialled-out values are close to zero; tol = 1.0e-09)
          note: Hispanic is probably collinear with the fixed effects (all partialled-out values are close to zero; tol = 1.0e-09)
          note: lnPopDensity is probably collinear with the fixed effects (all partialled-out values are close to zero; tol = 1.0e-09)
          (MWFE estimator converged in 5 iterations)
          note: Female omitted because of collinearity
          note: Asian omitted because of collinearity
          note: Black omitted because of collinearity
          note: Hispanic omitted because of collinearity
          note: lnPopDensity omitted because of collinearity
          
          HDFE Linear regression                            Number of obs   =     48,828
          Absorbing 3 HDFE groups                           F(   7,   1760) =       1.76
          Statistics robust to heteroskedasticity           Prob > F        =     0.0905
                                                            R-squared       =     0.4476
                                                            Adj R-squared   =     0.4259
                                                            Within R-sq.    =     0.0019
          Number of clusters (grpatid) =      1,761         Root MSE        =     0.1131
          
                                          (Std. err. adjusted for 1,761 clusters in grpatid)
          ----------------------------------------------------------------------------------
                           |               Robust
                     COVID | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
          -----------------+----------------------------------------------------------------
                    Female |          0  (omitted)
                 age75plus |  -.0097208   .0113265    -0.86   0.391    -.0319355    .0124939
                     Asian |          0  (omitted)
                     Black |          0  (omitted)
                  Hispanic |          0  (omitted)
              lnPopDensity |          0  (omitted)
                      tavg |   .0004537   .0002229     2.04   0.042     .0000166    .0008909
                    lnprcp |   .0001389   .0004997     0.28   0.781    -.0008411    .0011188
              CumMonthsSAH |  -.0102566   .0077387    -1.33   0.185    -.0254347    .0049214
          lnnursing_visits |  -.0237824   .0277872    -0.86   0.392    -.0782818    .0307169
               deaths_rate |   .0001522   .0000772     1.97   0.049     7.40e-07    .0003038
            cum_num_vacpct |   2.18e-06    .000272     0.01   0.994    -.0005313    .0005356
                     _cons |   .2842873   .3198149     0.89   0.374    -.3429698    .9115444
          ----------------------------------------------------------------------------------
          
          Absorbed degrees of freedom:
          -----------------------------------------------------+
           Absorbed FE | Categories  - Redundant  = Num. Coefs |
          -------------+---------------------------------------|
               grpatid |      1761        1761           0    *|
           monthlydate |        30           0          30     |
                 state |        47           1          46     |
          -----------------------------------------------------+
          * = FE nested within cluster; treated as redundant for DoF computation
          (1,652 missing values generated)
          
                   Failure _d: d2==1
             Analysis time _t: stop
            Enter on or after: time start
                  ID variable: grpatid
          
          Iteration 0:  Log pseudolikelihood = -1053.6093  
          Iteration 1:  Log pseudolikelihood =  -1053.569  
          Iteration 2:  Log pseudolikelihood =  -1053.569  
          
          Competing-risks regression                        No. of obs      =     48,828
                                                            No. of subjects =      1,761
          Failure event:   d2 == 1                          No. failed      =        145
          Competing event: d2 == 2                          No. competing   =        143
                                                            No. censored    =      1,473
          
                                                            Wald chi2(7)    =      45.15
          Log pseudolikelihood =  -1053.569                 Prob > chi2     =     0.0000
          
                                      (Std. err. adjusted for 1,761 clusters in grpatid)
          ------------------------------------------------------------------------------
                       |               Robust
                    _t |        SHR   std. err.      z    P>|z|     [95% conf. interval]
          -------------+----------------------------------------------------------------
                Female |   1.608563   .2878161     2.66   0.008     1.132752    2.284238
             age75plus |    2.92114   .5404785     5.79   0.000     2.032639    4.198018
                 Asian |   .9183988   .4732182    -0.17   0.869     .3345319    2.521303
                 Black |   1.160182   .2990622     0.58   0.564     .7000201    1.922834
              Hispanic |   .7267613   .2160009    -1.07   0.283     .4058877    1.301301
                 COVID |   1.689308   .7308934     1.21   0.226     .7234848    3.944468
              COVID_fe |    .829826   .4066926    -0.38   0.703     .3175546    2.168481
          ------------------------------------------------------------------------------
          (est73 stored)
          Of course, this does not solve the problem that my dataex did not have enough variation for diagnostic purposes...

          Many thanks for your guidance to help solve this problem.
          Gratefully,
          Sumedha

          Comment


          • #6
            So, this validates that with an appropriate corpus of data, program -myboot- can run without error messages and produces seemingly appropriate results. The question is why this fails when you run it under -bootstrap-.

            As pointed out by Daniel Feenberg, while you are trying to debug things, you should specify a small number of reps. Given that the output in #1 shows that all of the reps attempted failed, you only need a handful of them to get a sense of what is going wrong. Also while debugging, you should add the -noisily- option to your -bootstrap- command so that you get the output of -myboot- as you go along. (Remove -noisily- once things are working well and you go into production runs.)

            One other thing I have noticed about your -bootstrap- command is that you did not specify the -strata()- option. Given that the analysis within -bootstrap- is based on cluster defined by grpatid, you should probably do the -bootstrap- with -strata(grpatid)-. That will assure that in the bootstrap sampling, instead of randomly selecting at the observation level, sampling will be done at the grpatid level, so that if a grpatid is selected for the sample, all of the observations for that grpatid will be used: that is important for supporting panel-data analysis.

            So with those things in place, the output you get from -bootstrap- may make it clear why it is failing, and enable you to fix it. The other part of Daniel Feenberg's advice will also prove helpful if the first attempt doesn't clear things up: simplify the regressions down to a single explanatory variable and remove options. Then add things back one at a time to see at what point you encounter problems.

            Comment


            • #7
              Thank you Prof. Schechter and Prof. Feenberg. Following both of your advice, I stripped down the number of included covariates, reduced the reps to 10, added cluster(grpatid) to ensure sampling at individual level, and added noisily. I get an error suggesting multiple failures within the person, which is not the case....

              Code:
              . stset stop, id(grpatid) enter(start) failure(d2=1) time0(start)
              
              Survival-time data settings
              
                         ID variable: grpatid
                       Failure event: d2==1
              Observed time interval: (start, stop]
                   Enter on or after: time start
                   Exit on or before: failure
              
              --------------------------------------------------------------------------
                   50,480  total observations
                        0  exclusions
              --------------------------------------------------------------------------
                   50,480  observations remaining, representing
                    1,781  subjects
                      158  failures in single-failure-per-subject data
                   50,480  total analysis time at risk and under observation
                                                              At risk from t =         0
                                                   Earliest observed entry t =         0
                                                        Last observed exit t =        31
              
              . encode state, gen(state_d)
              
              . 
              . gen lnPopDensity=ln(PopDensity)
              (160 missing values generated)
              
              . gen lnnursing_visits=ln(nursing_visits)
              (1,482 missing values generated)
              
              . gen lnprcp=ln(prcp)
              (160 missing values generated)
              
              . 
              . capture program drop myboot
              
              . program define myboot, rclass
                1. 
              . * first stage
              . reghdfe COVID tavg , absorb(grpatid monthlydate state, save) cluster(grpatid) residuals(resid) 
                2. predict double COVID_fe, r
                3. 
              . * second stage  
              . eststo: stcrreg Female age75plus Asian Black Hispanic COVID COVID_fe, compete(d2=2)
                4. estimates store twoSLS1
                5. 
              . drop resid COVID_fe
                6. end
              
              . 
              . //myboot
              . 
              . xtset, clear
              
              . bootstrap _b, reps(10) noisily seed(123) cluster(grpatid) idcluster(newid): myboot
              bootstrap: First call to myboot with data as is:
              
              . myboot
              (dropped 14 singleton observations)
              (MWFE estimator converged in 5 iterations)
              
              HDFE Linear regression                            Number of obs   =     50,306
              Absorbing 3 HDFE groups                           F(   1,   1760) =       0.00
              Statistics robust to heteroskedasticity           Prob > F        =     0.9533
                                                                R-squared       =     0.4517
                                                                Adj R-squared   =     0.4309
                                                                Within R-sq.    =     0.0000
              Number of clusters (grpatid) =      1,761         Root MSE        =     0.1164
              
                                          (Std. err. adjusted for 1,761 clusters in grpatid)
              ------------------------------------------------------------------------------
                           |               Robust
                     COVID | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
              -------------+----------------------------------------------------------------
                      tavg |   .0000124   .0002119     0.06   0.953    -.0004032    .0004281
                     _cons |   .0242106   .0030769     7.87   0.000     .0181759    .0302453
              ------------------------------------------------------------------------------
              
              Absorbed degrees of freedom:
              -----------------------------------------------------+
               Absorbed FE | Categories  - Redundant  = Num. Coefs |
              -------------+---------------------------------------|
                   grpatid |      1761        1761           0    *|
               monthlydate |        31           0          31     |
                     state |        47           1          46     |
              -----------------------------------------------------+
              * = FE nested within cluster; treated as redundant for DoF computation
              (174 missing values generated)
              
                       Failure _d: d2==1
                 Analysis time _t: stop
                Enter on or after: time start
                      ID variable: grpatid
              
              Iteration 0:  Log pseudolikelihood = -1075.1635  
              Iteration 1:  Log pseudolikelihood = -1075.1207  
              Iteration 2:  Log pseudolikelihood = -1075.1207  
              
              Competing-risks regression                        No. of obs      =     50,306
                                                                No. of subjects =      1,761
              Failure event:   d2 == 1                          No. failed      =        148
              Competing event: d2 == 2                          No. competing   =        143
                                                                No. censored    =      1,470
              
                                                                Wald chi2(7)    =      45.80
              Log pseudolikelihood = -1075.1207                 Prob > chi2     =     0.0000
              
                                          (Std. err. adjusted for 1,761 clusters in grpatid)
              ------------------------------------------------------------------------------
                           |               Robust
                        _t |        SHR   std. err.      z    P>|z|     [95% conf. interval]
              -------------+----------------------------------------------------------------
                    Female |   1.560147   .2744972     2.53   0.011     1.105102    2.202565
                 age75plus |   2.985454   .5491266     5.95   0.000     2.081831    4.281296
                     Asian |   .8958582   .4613537    -0.21   0.831     .3264999    2.458077
                     Black |   1.134688   .2921316     0.49   0.624     .6850623    1.879416
                  Hispanic |   .7084065   .2102203    -1.16   0.245     .3959931    1.267294
                     COVID |   1.575292   .6663082     1.07   0.283     .6875818    3.609088
                  COVID_fe |   .8322585   .3906756    -0.39   0.696      .331658    2.088459
              ------------------------------------------------------------------------------
              (est78 stored)
              
              Bootstrap replications (10)
              . myboot
              (MWFE estimator converged in 5 iterations)
              
              HDFE Linear regression                            Number of obs   =     50,403
              Absorbing 3 HDFE groups                           F(   1,   1100) =       0.03
              Statistics robust to heteroskedasticity           Prob > F        =     0.8700
                                                                R-squared       =     0.4646
                                                                Adj R-squared   =     0.4518
                                                                Within R-sq.    =     0.0000
              Number of clusters (grpatid) =      1,101         Root MSE        =     0.1177
              
                                          (Std. err. adjusted for 1,101 clusters in grpatid)
              ------------------------------------------------------------------------------
                           |               Robust
                     COVID | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
              -------------+----------------------------------------------------------------
                      tavg |    .000041   .0002503     0.16   0.870    -.0004501    .0005321
                     _cons |   .0253284   .0036804     6.88   0.000     .0181069    .0325498
              ------------------------------------------------------------------------------
              
              Absorbed degrees of freedom:
              -----------------------------------------------------+
               Absorbed FE | Categories  - Redundant  = Num. Coefs |
              -------------+---------------------------------------|
                   grpatid |      1101        1101           0    *|
               monthlydate |        31           0          31     |
                     state |        45           1          44     |
              -----------------------------------------------------+
              * = FE nested within cluster; treated as redundant for DoF computation
              data with multiple failures per subject not supported by stcrreg
              an error occurred when bootstrap executed myboot, posting missing values
              . myboot
              (MWFE estimator converged in 5 iterations)
              
              HDFE Linear regression                            Number of obs   =     50,467
              Absorbing 3 HDFE groups                           F(   1,   1132) =       0.57
              Statistics robust to heteroskedasticity           Prob > F        =     0.4513
                                                                R-squared       =     0.4395
                                                                Adj R-squared   =     0.4258
                                                                Within R-sq.    =     0.0000
              Number of clusters (grpatid) =      1,133         Root MSE        =     0.1157
              
                                          (Std. err. adjusted for 1,133 clusters in grpatid)
              ------------------------------------------------------------------------------
                           |               Robust
                     COVID | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
              -------------+----------------------------------------------------------------
                      tavg |   .0002244   .0002978     0.75   0.451    -.0003599    .0008086
                     _cons |   .0206067   .0043405     4.75   0.000     .0120903    .0291231
              ------------------------------------------------------------------------------
              
              Absorbed degrees of freedom:
              -----------------------------------------------------+
               Absorbed FE | Categories  - Redundant  = Num. Coefs |
              -------------+---------------------------------------|
                   grpatid |      1133        1133           0    *|
               monthlydate |        31           0          31     |
                     state |        47           1          46     |
              -----------------------------------------------------+
              * = FE nested within cluster; treated as redundant for DoF computation
              data with multiple failures per subject not supported by stcrreg
              an error occurred when bootstrap executed myboot, posting missing values
              . myboot
              (MWFE estimator converged in 5 iterations)
              
              HDFE Linear regression                            Number of obs   =     50,275
              Absorbing 3 HDFE groups                           F(   1,   1097) =       2.26
              Statistics robust to heteroskedasticity           Prob > F        =     0.1328
                                                                R-squared       =     0.4768
                                                                Adj R-squared   =     0.4643
                                                                Within R-sq.    =     0.0001
              Number of clusters (grpatid) =      1,098         Root MSE        =     0.1121
              
                                          (Std. err. adjusted for 1,098 clusters in grpatid)
              ------------------------------------------------------------------------------
                           |               Robust
                     COVID | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
              -------------+----------------------------------------------------------------
                      tavg |  -.0005847   .0003887    -1.50   0.133    -.0013474     .000178
                     _cons |   .0324401   .0055926     5.80   0.000     .0214667    .0434134
              ------------------------------------------------------------------------------
              
              Absorbed degrees of freedom:
              -----------------------------------------------------+
               Absorbed FE | Categories  - Redundant  = Num. Coefs |
              -------------+---------------------------------------|
                   grpatid |      1098        1098           0    *|
               monthlydate |        31           0          31     |
                     state |        44           1          43     |
              -----------------------------------------------------+
              * = FE nested within cluster; treated as redundant for DoF computation
              data with multiple failures per subject not supported by stcrreg
              an error occurred when bootstrap executed myboot, posting missing values
              . myboot
              (MWFE estimator converged in 5 iterations)
              
              HDFE Linear regression                            Number of obs   =     50,582
              Absorbing 3 HDFE groups                           F(   1,   1120) =       0.63
              Statistics robust to heteroskedasticity           Prob > F        =     0.4260
                                                                R-squared       =     0.4427
                                                                Adj R-squared   =     0.4292
                                                                Within R-sq.    =     0.0000
              Number of clusters (grpatid) =      1,121         Root MSE        =     0.1146
              
                                          (Std. err. adjusted for 1,121 clusters in grpatid)
              ------------------------------------------------------------------------------
                           |               Robust
                     COVID | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
              -------------+----------------------------------------------------------------
                      tavg |  -.0002022    .000254    -0.80   0.426    -.0007006    .0002961
                     _cons |   .0264981   .0036827     7.20   0.000     .0192723    .0337239
              ------------------------------------------------------------------------------
              
              Absorbed degrees of freedom:
              -----------------------------------------------------+
               Absorbed FE | Categories  - Redundant  = Num. Coefs |
              -------------+---------------------------------------|
                   grpatid |      1121        1121           0    *|
               monthlydate |        31           0          31     |
                     state |        47           1          46     |
              -----------------------------------------------------+
              * = FE nested within cluster; treated as redundant for DoF computation
              data with multiple failures per subject not supported by stcrreg
              an error occurred when bootstrap executed myboot, posting missing values
              . myboot
              (MWFE estimator converged in 5 iterations)
              
              HDFE Linear regression                            Number of obs   =     50,458
              Absorbing 3 HDFE groups                           F(   1,   1132) =       1.38
              Statistics robust to heteroskedasticity           Prob > F        =     0.2407
                                                                R-squared       =     0.4656
                                                                Adj R-squared   =     0.4525
                                                                Within R-sq.    =     0.0000
              Number of clusters (grpatid) =      1,133         Root MSE        =     0.1192
              
                                          (Std. err. adjusted for 1,133 clusters in grpatid)
              ------------------------------------------------------------------------------
                           |               Robust
                     COVID | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
              -------------+----------------------------------------------------------------
                      tavg |  -.0003164   .0002695    -1.17   0.241    -.0008452    .0002124
                     _cons |   .0312652   .0039265     7.96   0.000     .0235611    .0389694
              ------------------------------------------------------------------------------
              
              Absorbed degrees of freedom:
              -----------------------------------------------------+
               Absorbed FE | Categories  - Redundant  = Num. Coefs |
              -------------+---------------------------------------|
                   grpatid |      1133        1133           0    *|
               monthlydate |        31           0          31     |
                     state |        46           1          45     |
              -----------------------------------------------------+
              * = FE nested within cluster; treated as redundant for DoF computation
              data with multiple failures per subject not supported by stcrreg
              an error occurred when bootstrap executed myboot, posting missing values
              . myboot
              (MWFE estimator converged in 5 iterations)
              
              HDFE Linear regression                            Number of obs   =     50,163
              Absorbing 3 HDFE groups                           F(   1,   1133) =       0.63
              Statistics robust to heteroskedasticity           Prob > F        =     0.4266
                                                                R-squared       =     0.4477
                                                                Adj R-squared   =     0.4340
                                                                Within R-sq.    =     0.0000
              Number of clusters (grpatid) =      1,134         Root MSE        =     0.1133
              
                                          (Std. err. adjusted for 1,134 clusters in grpatid)
              ------------------------------------------------------------------------------
                           |               Robust
                     COVID | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
              -------------+----------------------------------------------------------------
                      tavg |  -.0001935   .0002432    -0.80   0.427    -.0006707    .0002838
                     _cons |   .0260118     .00353     7.37   0.000     .0190857    .0329378
              ------------------------------------------------------------------------------
              
              Absorbed degrees of freedom:
              -----------------------------------------------------+
               Absorbed FE | Categories  - Redundant  = Num. Coefs |
              -------------+---------------------------------------|
                   grpatid |      1134        1134           0    *|
               monthlydate |        31           0          31     |
                     state |        46           1          45     |
              -----------------------------------------------------+
              * = FE nested within cluster; treated as redundant for DoF computation
              data with multiple failures per subject not supported by stcrreg
              an error occurred when bootstrap executed myboot, posting missing values
              . myboot
              (MWFE estimator converged in 5 iterations)
              
              HDFE Linear regression                            Number of obs   =     50,072
              Absorbing 3 HDFE groups                           F(   1,   1102) =       0.27
              Statistics robust to heteroskedasticity           Prob > F        =     0.6066
                                                                R-squared       =     0.4296
                                                                Adj R-squared   =     0.4158
                                                                Within R-sq.    =     0.0000
              Number of clusters (grpatid) =      1,103         Root MSE        =     0.1191
              
                                          (Std. err. adjusted for 1,103 clusters in grpatid)
              ------------------------------------------------------------------------------
                           |               Robust
                     COVID | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
              -------------+----------------------------------------------------------------
                      tavg |  -.0002078   .0004034    -0.52   0.607    -.0009993    .0005837
                     _cons |   .0278769   .0058097     4.80   0.000     .0164777    .0392762
              ------------------------------------------------------------------------------
              
              Absorbed degrees of freedom:
              -----------------------------------------------------+
               Absorbed FE | Categories  - Redundant  = Num. Coefs |
              -------------+---------------------------------------|
                   grpatid |      1103        1103           0    *|
               monthlydate |        31           0          31     |
                     state |        46           1          45     |
              -----------------------------------------------------+
              * = FE nested within cluster; treated as redundant for DoF computation
              data with multiple failures per subject not supported by stcrreg
              an error occurred when bootstrap executed myboot, posting missing values
              . myboot
              (MWFE estimator converged in 6 iterations)
              
              HDFE Linear regression                            Number of obs   =     49,725
              Absorbing 3 HDFE groups                           F(   1,   1114) =       0.32
              Statistics robust to heteroskedasticity           Prob > F        =     0.5726
                                                                R-squared       =     0.4765
                                                                Adj R-squared   =     0.4637
                                                                Within R-sq.    =     0.0000
              Number of clusters (grpatid) =      1,115         Root MSE        =     0.1153
              
                                          (Std. err. adjusted for 1,115 clusters in grpatid)
              ------------------------------------------------------------------------------
                           |               Robust
                     COVID | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
              -------------+----------------------------------------------------------------
                      tavg |  -.0001424   .0002523    -0.56   0.573    -.0006375    .0003526
                     _cons |   .0274934   .0036381     7.56   0.000     .0203551    .0346318
              ------------------------------------------------------------------------------
              
              Absorbed degrees of freedom:
              -----------------------------------------------------+
               Absorbed FE | Categories  - Redundant  = Num. Coefs |
              -------------+---------------------------------------|
                   grpatid |      1115        1115           0    *|
               monthlydate |        31           0          31     |
                     state |        46           1          45     |
              -----------------------------------------------------+
              * = FE nested within cluster; treated as redundant for DoF computation
              data with multiple failures per subject not supported by stcrreg
              an error occurred when bootstrap executed myboot, posting missing values
              . myboot
              (MWFE estimator converged in 5 iterations)
              
              HDFE Linear regression                            Number of obs   =     50,300
              Absorbing 3 HDFE groups                           F(   1,   1133) =       0.09
              Statistics robust to heteroskedasticity           Prob > F        =     0.7582
                                                                R-squared       =     0.4410
                                                                Adj R-squared   =     0.4272
                                                                Within R-sq.    =     0.0000
              Number of clusters (grpatid) =      1,134         Root MSE        =     0.1178
              
                                          (Std. err. adjusted for 1,134 clusters in grpatid)
              ------------------------------------------------------------------------------
                           |               Robust
                     COVID | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
              -------------+----------------------------------------------------------------
                      tavg |  -.0001098   .0003568    -0.31   0.758    -.0008098    .0005901
                     _cons |   .0264254   .0051788     5.10   0.000     .0162642    .0365866
              ------------------------------------------------------------------------------
              
              Absorbed degrees of freedom:
              -----------------------------------------------------+
               Absorbed FE | Categories  - Redundant  = Num. Coefs |
              -------------+---------------------------------------|
                   grpatid |      1134        1134           0    *|
               monthlydate |        31           0          31     |
                     state |        46           1          45     |
              -----------------------------------------------------+
              * = FE nested within cluster; treated as redundant for DoF computation
              data with multiple failures per subject not supported by stcrreg
              an error occurred when bootstrap executed myboot, posting missing values
              . myboot
              (MWFE estimator converged in 5 iterations)
              
              HDFE Linear regression                            Number of obs   =     50,560
              Absorbing 3 HDFE groups                           F(   1,   1118) =       2.27
              Statistics robust to heteroskedasticity           Prob > F        =     0.1320
                                                                R-squared       =     0.4337
                                                                Adj R-squared   =     0.4200
                                                                Within R-sq.    =     0.0001
              Number of clusters (grpatid) =      1,119         Root MSE        =     0.1210
              
                                          (Std. err. adjusted for 1,119 clusters in grpatid)
              ------------------------------------------------------------------------------
                           |               Robust
                     COVID | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
              -------------+----------------------------------------------------------------
                      tavg |  -.0004248   .0002818    -1.51   0.132    -.0009778    .0001282
                     _cons |   .0321098   .0041001     7.83   0.000     .0240651    .0401544
              ------------------------------------------------------------------------------
              
              Absorbed degrees of freedom:
              -----------------------------------------------------+
               Absorbed FE | Categories  - Redundant  = Num. Coefs |
              -------------+---------------------------------------|
                   grpatid |      1119        1119           0    *|
               monthlydate |        31           0          31     |
                     state |        44           1          43     |
              -----------------------------------------------------+
              * = FE nested within cluster; treated as redundant for DoF computation
              data with multiple failures per subject not supported by stcrreg
              an error occurred when bootstrap executed myboot, posting missing values
              insufficient observations to compute bootstrap standard errors
              no results will be saved
              r(2000);
              
              end of do-file
              
              r(2000);
              What am I still doing wrong?

              Grateful for your help.
              Sumedha

              Comment


              • #8
                Well, Stata is telling you the problem from its perspective: "data with multiple failures per subject not supported by stcrreg." Which is odd, because your -stset- command does not set multiple failures per subject. But somehow in the bootstrap replications Stata is getting confused and thinks that you do have that. I suspect that the bootstrap sampling is producing data sets where the information in the variables created by -stset- is no longer compatible with the actual data. I'm really just speculating here, because I have never attempted to do a -bootstrap- of a survival analysis, so I don't really quite know the ins and outs of that. I would try moving the -stset- command into program myboot so that the survival variables get re-created with each sample, and presumably that results in consistent information.

                Comment


                • #9
                  Hi,
                  Thank you for your input. Putting the stset into myboot did something but did not fix the problem fully.

                  Code:
                  . gen d2=d
                  
                  . replace d2=2 if dead==1
                  (2,374 real changes made)
                  
                  . 
                  . encode state, gen(state_d)
                  
                  . 
                  . gen lnPopDensity=ln(PopDensity)
                  (160 missing values generated)
                  
                  . gen lnnursing_visits=ln(nursing_visits)
                  (1,482 missing values generated)
                  
                  . gen lnprcp=ln(prcp)
                  (160 missing values generated)
                  
                  . 
                  . capture program drop myboot
                  
                  . program define myboot, rclass
                    1. 
                  . * first stage
                  . reghdfe COVID tavg , absorb(grpatid monthlydate state, save) cluster(grpatid) residuals(resid) 
                    2. predict double COVID_fe, r
                    3. 
                  . * second stage  
                  . stset stop, id(grpatid) enter(start) failure(d2=1) time0(start)
                    4. eststo: stcrreg Female age75plus Asian Black Hispanic COVID COVID_fe, compete(d2=2)
                    5. estimates store twoSLS1
                    6. 
                  . drop resid COVID_fe
                    7. end
                  
                  . 
                  . tsset, clear
                  
                  . bootstrap _b, reps(10) noisily seed(123) cluster(grpatid) idcluster(newid): myboot
                  bootstrap: First call to myboot with data as is:
                  
                  . myboot
                  (dropped 14 singleton observations)
                  (MWFE estimator converged in 5 iterations)
                  
                  HDFE Linear regression                            Number of obs   =     50,306
                  Absorbing 3 HDFE groups                           F(   1,   1760) =       0.00
                  Statistics robust to heteroskedasticity           Prob > F        =     0.9533
                                                                    R-squared       =     0.4517
                                                                    Adj R-squared   =     0.4309
                                                                    Within R-sq.    =     0.0000
                  Number of clusters (grpatid) =      1,761         Root MSE        =     0.1164
                  
                                              (Std. err. adjusted for 1,761 clusters in grpatid)
                  ------------------------------------------------------------------------------
                               |               Robust
                         COVID | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
                  -------------+----------------------------------------------------------------
                          tavg |   .0000124   .0002119     0.06   0.953    -.0004032    .0004281
                         _cons |   .0242106   .0030769     7.87   0.000     .0181759    .0302453
                  ------------------------------------------------------------------------------
                  
                  Absorbed degrees of freedom:
                  -----------------------------------------------------+
                   Absorbed FE | Categories  - Redundant  = Num. Coefs |
                  -------------+---------------------------------------|
                       grpatid |      1761        1761           0    *|
                   monthlydate |        31           0          31     |
                         state |        47           1          46     |
                  -----------------------------------------------------+
                  * = FE nested within cluster; treated as redundant for DoF computation
                  (174 missing values generated)
                  
                  Survival-time data settings
                  
                             ID variable: grpatid
                           Failure event: d2==1
                  Observed time interval: (start, stop]
                       Enter on or after: time start
                       Exit on or before: failure
                  
                  --------------------------------------------------------------------------
                       50,480  total observations
                            0  exclusions
                  --------------------------------------------------------------------------
                       50,480  observations remaining, representing
                        1,781  subjects
                          158  failures in single-failure-per-subject data
                       50,480  total analysis time at risk and under observation
                                                                  At risk from t =         0
                                                       Earliest observed entry t =         0
                                                            Last observed exit t =        31
                  
                           Failure _d: d2==1
                     Analysis time _t: stop
                    Enter on or after: time start
                          ID variable: grpatid
                  
                  Iteration 0:  Log pseudolikelihood = -1075.1635  
                  Iteration 1:  Log pseudolikelihood = -1075.1207  
                  Iteration 2:  Log pseudolikelihood = -1075.1207  
                  
                  Competing-risks regression                        No. of obs      =     50,306
                                                                    No. of subjects =      1,761
                  Failure event:   d2 == 1                          No. failed      =        148
                  Competing event: d2 == 2                          No. competing   =        143
                                                                    No. censored    =      1,470
                  
                                                                    Wald chi2(7)    =      45.80
                  Log pseudolikelihood = -1075.1207                 Prob > chi2     =     0.0000
                  
                                              (Std. err. adjusted for 1,761 clusters in grpatid)
                  ------------------------------------------------------------------------------
                               |               Robust
                            _t |        SHR   std. err.      z    P>|z|     [95% conf. interval]
                  -------------+----------------------------------------------------------------
                        Female |   1.560147   .2744972     2.53   0.011     1.105102    2.202565
                     age75plus |   2.985454   .5491266     5.95   0.000     2.081831    4.281296
                         Asian |   .8958582   .4613537    -0.21   0.831     .3264999    2.458077
                         Black |   1.134688   .2921316     0.49   0.624     .6850623    1.879416
                      Hispanic |   .7084065   .2102203    -1.16   0.245     .3959931    1.267294
                         COVID |   1.575292   .6663082     1.07   0.283     .6875818    3.609088
                      COVID_fe |   .8322585   .3906756    -0.39   0.696      .331658    2.088459
                  ------------------------------------------------------------------------------
                  (est92 stored)
                  
                  Bootstrap replications (10)
                  . myboot
                  (MWFE estimator converged in 5 iterations)
                  
                  HDFE Linear regression                            Number of obs   =     50,403
                  Absorbing 3 HDFE groups                           F(   1,   1100) =       0.03
                  Statistics robust to heteroskedasticity           Prob > F        =     0.8700
                                                                    R-squared       =     0.4646
                                                                    Adj R-squared   =     0.4518
                                                                    Within R-sq.    =     0.0000
                  Number of clusters (grpatid) =      1,101         Root MSE        =     0.1177
                  
                                              (Std. err. adjusted for 1,101 clusters in grpatid)
                  ------------------------------------------------------------------------------
                               |               Robust
                         COVID | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
                  -------------+----------------------------------------------------------------
                          tavg |    .000041   .0002503     0.16   0.870    -.0004501    .0005321
                         _cons |   .0253284   .0036804     6.88   0.000     .0181069    .0325498
                  ------------------------------------------------------------------------------
                  
                  Absorbed degrees of freedom:
                  -----------------------------------------------------+
                   Absorbed FE | Categories  - Redundant  = Num. Coefs |
                  -------------+---------------------------------------|
                       grpatid |      1101        1101           0    *|
                   monthlydate |        31           0          31     |
                         state |        45           1          44     |
                  -----------------------------------------------------+
                  * = FE nested within cluster; treated as redundant for DoF computation
                  
                  Survival-time data settings
                  
                             ID variable: grpatid
                           Failure event: d2==1
                  Observed time interval: (start, stop]
                       Enter on or after: time start
                       Exit on or before: failure
                  
                  --------------------------------------------------------------------------
                       50,403  total observations
                       18,902  overlapping records (stop[_n-1]>start)         PROBABLE ERROR
                  --------------------------------------------------------------------------
                       31,501  observations remaining, representing
                        1,101  subjects
                           87  failures in single-failure-per-subject data
                       31,501  total analysis time at risk and under observation
                                                                  At risk from t =         0
                                                       Earliest observed entry t =         0
                                                            Last observed exit t =        31
                  option compete(): competing risks events must be stset as censored
                  an error occurred when bootstrap executed myboot, posting missing values
                  . myboot
                  (MWFE estimator converged in 5 iterations)
                  
                  HDFE Linear regression                            Number of obs   =     50,467
                  Absorbing 3 HDFE groups                           F(   1,   1132) =       0.57
                  Statistics robust to heteroskedasticity           Prob > F        =     0.4513
                                                                    R-squared       =     0.4395
                                                                    Adj R-squared   =     0.4258
                                                                    Within R-sq.    =     0.0000
                  Number of clusters (grpatid) =      1,133         Root MSE        =     0.1157
                  
                                              (Std. err. adjusted for 1,133 clusters in grpatid)
                  ------------------------------------------------------------------------------
                               |               Robust
                         COVID | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
                  -------------+----------------------------------------------------------------
                          tavg |   .0002244   .0002978     0.75   0.451    -.0003599    .0008086
                         _cons |   .0206067   .0043405     4.75   0.000     .0120903    .0291231
                  ------------------------------------------------------------------------------
                  
                  Absorbed degrees of freedom:
                  -----------------------------------------------------+
                   Absorbed FE | Categories  - Redundant  = Num. Coefs |
                  -------------+---------------------------------------|
                       grpatid |      1133        1133           0    *|
                   monthlydate |        31           0          31     |
                         state |        47           1          46     |
                  -----------------------------------------------------+
                  * = FE nested within cluster; treated as redundant for DoF computation
                  
                  
                  
                  Survival-time data settings
                  
                             ID variable: grpatid
                           Failure event: d2==1
                  Observed time interval: (start, stop]
                       Enter on or after: time start
                       Exit on or before: failure
                  
                  --------------------------------------------------------------------------
                       50,582  total observations
                       18,465  overlapping records (stop[_n-1]>start)         PROBABLE ERROR
                  --------------------------------------------------------------------------
                       32,117  observations remaining, representing
                        1,121  subjects
                           95  failures in single-failure-per-subject data
                       32,117  total analysis time at risk and under observation
                                                                  At risk from t =         0
                                                       Earliest observed entry t =         0
                                                            Last observed exit t =        31
                  option compete(): competing risks events must be stset as censored
                  an error occurred when bootstrap executed myboot, posting missing values
                  . myboot
                  (MWFE estimator converged in 5 iterations)
                  
                  HDFE Linear regression                            Number of obs   =     50,458
                  Absorbing 3 HDFE groups                           F(   1,   1132) =       1.38
                  Statistics robust to heteroskedasticity           Prob > F        =     0.2407
                                                                    R-squared       =     0.4656
                                                                    Adj R-squared   =     0.4525
                                                                    Within R-sq.    =     0.0000
                  Number of clusters (grpatid) =      1,133         Root MSE        =     0.1192
                  
                                              (Std. err. adjusted for 1,133 clusters in grpatid)
                  ------------------------------------------------------------------------------
                               |               Robust
                         COVID | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
                  -------------+----------------------------------------------------------------
                          tavg |  -.0003164   .0002695    -1.17   0.241    -.0008452    .0002124
                         _cons |   .0312652   .0039265     7.96   0.000     .0235611    .0389694
                  ------------------------------------------------------------------------------
                  
                  Absorbed degrees of freedom:
                  -----------------------------------------------------+
                   Absorbed FE | Categories  - Redundant  = Num. Coefs |
                  -------------+---------------------------------------|
                       grpatid |      1133        1133           0    *|
                   monthlydate |        31           0          31     |
                         state |        46           1          45     |
                  -----------------------------------------------------+
                  * = FE nested within cluster; treated as redundant for DoF computation
                  
                  
                  Survival-time data settings
                  
                             ID variable: grpatid
                           Failure event: d2==1
                  Observed time interval: (start, stop]
                       Enter on or after: time start
                       Exit on or before: failure
                  
                  --------------------------------------------------------------------------
                       50,163  total observations
                       17,801  overlapping records (stop[_n-1]>start)         PROBABLE ERROR
                  --------------------------------------------------------------------------
                       32,362  observations remaining, representing
                        1,134  subjects
                          100  failures in single-failure-per-subject data
                       32,362  total analysis time at risk and under observation
                                                                  At risk from t =         0
                                                       Earliest observed entry t =         0
                                                            Last observed exit t =        31
                  option compete(): competing risks events must be stset as censored
                  an error occurred when bootstrap executed myboot, posting missing values
                  . myboot
                  (MWFE estimator converged in 5 iterations)
                  
                  HDFE Linear regression                            Number of obs   =     50,072
                  Absorbing 3 HDFE groups                           F(   1,   1102) =       0.27
                  Statistics robust to heteroskedasticity           Prob > F        =     0.6066
                                                                    R-squared       =     0.4296
                                                                    Adj R-squared   =     0.4158
                                                                    Within R-sq.    =     0.0000
                  Number of clusters (grpatid) =      1,103         Root MSE        =     0.1191
                  
                                              (Std. err. adjusted for 1,103 clusters in grpatid)
                  ------------------------------------------------------------------------------
                               |               Robust
                         COVID | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
                  -------------+----------------------------------------------------------------
                          tavg |  -.0002078   .0004034    -0.52   0.607    -.0009993    .0005837
                         _cons |   .0278769   .0058097     4.80   0.000     .0164777    .0392762
                  ------------------------------------------------------------------------------
                  
                  Absorbed degrees of freedom:
                  -----------------------------------------------------+
                   Absorbed FE | Categories  - Redundant  = Num. Coefs |
                  -------------+---------------------------------------|
                       grpatid |      1103        1103           0    *|
                   monthlydate |        31           0          31     |
                         state |        46           1          45     |
                  -----------------------------------------------------+
                  * = FE nested within cluster; treated as redundant for DoF computation
                  
                  Survival-time data settings
                  
                             ID variable: grpatid
                           Failure event: d2==1
                  Observed time interval: (start, stop]
                       Enter on or after: time start
                       Exit on or before: failure
                  
                  --------------------------------------------------------------------------
                       50,072  total observations
                       18,699  overlapping records (stop[_n-1]>start)         PROBABLE ERROR
                  --------------------------------------------------------------------------
                       31,373  observations remaining, representing
                        1,103  subjects
                           96  failures in single-failure-per-subject data
                       31,373  total analysis time at risk and under observation
                                                                  At risk from t =         0
                                                       Earliest observed entry t =         0
                                                            Last observed exit t =        31
                  option compete(): competing risks events must be stset as censored
                  an error occurred when bootstrap executed myboot, posting missing values
                  . myboot
                  (MWFE estimator converged in 6 iterations)
                  
                  HDFE Linear regression                            Number of obs   =     49,725
                  Absorbing 3 HDFE groups                           F(   1,   1114) =       0.32
                  Statistics robust to heteroskedasticity           Prob > F        =     0.5726
                                                                    R-squared       =     0.4765
                                                                    Adj R-squared   =     0.4637
                                                                    Within R-sq.    =     0.0000
                  Number of clusters (grpatid) =      1,115         Root MSE        =     0.1153
                  
                                              (Std. err. adjusted for 1,115 clusters in grpatid)
                  ------------------------------------------------------------------------------
                               |               Robust
                         COVID | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
                  -------------+----------------------------------------------------------------
                          tavg |  -.0001424   .0002523    -0.56   0.573    -.0006375    .0003526
                         _cons |   .0274934   .0036381     7.56   0.000     .0203551    .0346318
                  ------------------------------------------------------------------------------
                  
                  Absorbed degrees of freedom:
                  -----------------------------------------------------+
                   Absorbed FE | Categories  - Redundant  = Num. Coefs |
                  -------------+---------------------------------------|
                       grpatid |      1115        1115           0    *|
                   monthlydate |        31           0          31     |
                         state |        46           1          45     |
                  -----------------------------------------------------+
                  * = FE nested within cluster; treated as redundant for DoF computation
                  
                  Survival-time data settings
                  
                             ID variable: grpatid
                           Failure event: d2==1
                  Observed time interval: (start, stop]
                       Enter on or after: time start
                       Exit on or before: failure
                  
                  --------------------------------------------------------------------------
                       49,725  total observations
                       18,055  overlapping records (stop[_n-1]>start)         PROBABLE ERROR
                  --------------------------------------------------------------------------
                       31,670  observations remaining, representing
                        1,115  subjects
                          100  failures in single-failure-per-subject data
                       31,670  total analysis time at risk and under observation
                                                                  At risk from t =         0
                                                       Earliest observed entry t =         0
                                                            Last observed exit t =        31
                  option compete(): competing risks events must be stset as censored
                  an error occurred when bootstrap executed myboot, posting missing values
                  . myboot
                  (MWFE estimator converged in 5 iterations)
                  
                  HDFE Linear regression                            Number of obs   =     50,300
                  Absorbing 3 HDFE groups                           F(   1,   1133) =       0.09
                  Statistics robust to heteroskedasticity           Prob > F        =     0.7582
                                                                    R-squared       =     0.4410
                                                                    Adj R-squared   =     0.4272
                                                                    Within R-sq.    =     0.0000
                  Number of clusters (grpatid) =      1,134         Root MSE        =     0.1178
                  
                                              (Std. err. adjusted for 1,134 clusters in grpatid)
                  ------------------------------------------------------------------------------
                               |               Robust
                         COVID | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
                  -------------+----------------------------------------------------------------
                          tavg |  -.0001098   .0003568    -0.31   0.758    -.0008098    .0005901
                         _cons |   .0264254   .0051788     5.10   0.000     .0162642    .0365866
                  ------------------------------------------------------------------------------
                  
                  Absorbed degrees of freedom:
                  -----------------------------------------------------+
                   Absorbed FE | Categories  - Redundant  = Num. Coefs |
                  -------------+---------------------------------------|
                       grpatid |      1134        1134           0    *|
                   monthlydate |        31           0          31     |
                         state |        46           1          45     |
                  -----------------------------------------------------+
                  * = FE nested within cluster; treated as redundant for DoF computation
                  
                  Survival-time data settings
                  
                             ID variable: grpatid
                           Failure event: d2==1
                  Observed time interval: (start, stop]
                       Enter on or after: time start
                       Exit on or before: failure
                  
                  --------------------------------------------------------------------------
                       50,300  total observations
                       17,963  overlapping records (stop[_n-1]>start)         PROBABLE ERROR
                  --------------------------------------------------------------------------
                       32,337  observations remaining, representing
                        1,134  subjects
                          101  failures in single-failure-per-subject data
                       32,337  total analysis time at risk and under observation
                                                                  At risk from t =         0
                                                       Earliest observed entry t =         0
                                                            Last observed exit t =        31
                  option compete(): competing risks events must be stset as censored
                  an error occurred when bootstrap executed myboot, posting missing values
                  . myboot
                  (MWFE estimator converged in 5 iterations)
                  
                  HDFE Linear regression                            Number of obs   =     50,560
                  Absorbing 3 HDFE groups                           F(   1,   1118) =       2.27
                  Statistics robust to heteroskedasticity           Prob > F        =     0.1320
                                                                    R-squared       =     0.4337
                                                                    Adj R-squared   =     0.4200
                                                                    Within R-sq.    =     0.0001
                  Number of clusters (grpatid) =      1,119         Root MSE        =     0.1210
                  
                                              (Std. err. adjusted for 1,119 clusters in grpatid)
                  ------------------------------------------------------------------------------
                               |               Robust
                         COVID | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
                  -------------+----------------------------------------------------------------
                          tavg |  -.0004248   .0002818    -1.51   0.132    -.0009778    .0001282
                         _cons |   .0321098   .0041001     7.83   0.000     .0240651    .0401544
                  ------------------------------------------------------------------------------
                  
                  Absorbed degrees of freedom:
                  -----------------------------------------------------+
                   Absorbed FE | Categories  - Redundant  = Num. Coefs |
                  -------------+---------------------------------------|
                       grpatid |      1119        1119           0    *|
                   monthlydate |        31           0          31     |
                         state |        44           1          43     |
                  -----------------------------------------------------+
                  * = FE nested within cluster; treated as redundant for DoF computation
                  
                  Survival-time data settings
                  
                             ID variable: grpatid
                           Failure event: d2==1
                  Observed time interval: (start, stop]
                       Enter on or after: time start
                       Exit on or before: failure
                  
                  --------------------------------------------------------------------------
                       50,560  total observations
                       18,500  overlapping records (stop[_n-1]>start)         PROBABLE ERROR
                  --------------------------------------------------------------------------
                       32,060  observations remaining, representing
                        1,119  subjects
                           88  failures in single-failure-per-subject data
                       32,060  total analysis time at risk and under observation
                                                                  At risk from t =         0
                                                       Earliest observed entry t =         0
                                                            Last observed exit t =        31
                  option compete(): competing risks events must be stset as censored
                  an error occurred when bootstrap executed myboot, posting missing values
                  insufficient observations to compute bootstrap standard errors
                  no results will be saved
                  r(2000);
                  
                  end of do-file
                  
                  r(2000);
                  
                  .
                  So, a new error...what more can I try?
                  Gratefully,
                  Sumedha

                  Comment


                  • #10
                    Oh, I think I see it. I think I was wrong to tell you to include -strata(grpatid)- in your -bootstrap- command. I was confusing -strata()- with -cluster()-. I think it should be -cluster(grpatid) idcluster(new_id)-, where new_id is a name for a new variable, one that does not yet exist in your data set.

                    Then we also need to replace the -stset- command in a somewhat complicated way:
                    Code:
                    capture confirm var new_id
                    if c(rc) {   
                        stset stop, id(new_id) enter(start) failure(d2=1) time0(start)
                    }
                    else {   
                        stset stop, id(grpatid) enter(start) failure(d2=1) time0(start)
                    }

                    Comment


                    • #11
                      Thank you for your continued guidance Prof. Schechter. So I tried your suggestion, but perhaps the placement of the above code is not correct yet (I placed it inside myboot based on our earlier discussion)? I also used cluster and created newid. Now, back to the earlier error message ...

                      Code:
                      . stset stop, id(grpatid) enter(start) failure(d2=1) time0(start)
                      
                      Survival-time data settings
                      
                                 ID variable: grpatid
                               Failure event: d2==1
                      Observed time interval: (start, stop]
                           Enter on or after: time start
                           Exit on or before: failure
                      
                      --------------------------------------------------------------------------
                           50,480  total observations
                                0  exclusions
                      --------------------------------------------------------------------------
                           50,480  observations remaining, representing
                            1,781  subjects
                              158  failures in single-failure-per-subject data
                           50,480  total analysis time at risk and under observation
                                                                      At risk from t =         0
                                                           Earliest observed entry t =         0
                                                                Last observed exit t =        31
                      
                      . 
                      . 
                      . xtset grpatid monthlydate
                      
                      Panel variable: grpatid (unbalanced)
                       Time variable: monthlydate, 2019m7 to 2022m1
                               Delta: 1 month
                      
                      . capture program drop myboot
                      
                      . program define myboot, rclass
                        1. 
                      . * first stage
                      . reghdfe COVID tavg , absorb(grpatid monthlydate state, save) cluster(grpatid) residuals(resid) 
                        2. predict double COVID_fe, r
                        3. 
                      . * second stage  
                      . eststo: stcrreg Female age75plus Asian Black Hispanic COVID COVID_fe, compete(d2=2)
                        4. estimates store twoSLS1
                        5. 
                      . drop resid COVID_fe
                        6. capture confirm var newid
                        7. if c(rc) {   
                        8.     stset stop, id(newid) enter(start) failure(d2=1) time0(start)
                        9. }
                       10. else {   
                       11.     stset stop, id(grpatid) enter(start) failure(d2=1) time0(start)
                       12. }
                       13. 
                      . end
                      
                      . tsset, clear
                      
                      . xtset, clear
                      
                      . bootstrap _b, reps(10) noisily seed(123) cluster(grpatid) idcluster(newid): myboot
                      bootstrap: First call to myboot with data as is:
                      
                      . myboot
                      (dropped 14 singleton observations)
                      (MWFE estimator converged in 5 iterations)
                      
                      HDFE Linear regression                            Number of obs   =     50,306
                      Absorbing 3 HDFE groups                           F(   1,   1760) =       0.00
                      Statistics robust to heteroskedasticity           Prob > F        =     0.9533
                                                                        R-squared       =     0.4517
                                                                        Adj R-squared   =     0.4309
                                                                        Within R-sq.    =     0.0000
                      Number of clusters (grpatid) =      1,761         Root MSE        =     0.1164
                      
                                                  (Std. err. adjusted for 1,761 clusters in grpatid)
                      ------------------------------------------------------------------------------
                                   |               Robust
                             COVID | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
                      -------------+----------------------------------------------------------------
                              tavg |   .0000124   .0002119     0.06   0.953    -.0004032    .0004281
                             _cons |   .0242106   .0030769     7.87   0.000     .0181759    .0302453
                      ------------------------------------------------------------------------------
                      
                      Absorbed degrees of freedom:
                      -----------------------------------------------------+
                       Absorbed FE | Categories  - Redundant  = Num. Coefs |
                      -------------+---------------------------------------|
                           grpatid |      1761        1761           0    *|
                       monthlydate |        31           0          31     |
                             state |        47           1          46     |
                      -----------------------------------------------------+
                      * = FE nested within cluster; treated as redundant for DoF computation
                      (174 missing values generated)
                      
                               Failure _d: d2==1
                         Analysis time _t: stop
                        Enter on or after: time start
                              ID variable: grpatid
                      
                      Iteration 0:  Log pseudolikelihood = -1075.1635  
                      Iteration 1:  Log pseudolikelihood = -1075.1207  
                      Iteration 2:  Log pseudolikelihood = -1075.1207  
                      
                      Competing-risks regression                        No. of obs      =     50,306
                                                                        No. of subjects =      1,761
                      Failure event:   d2 == 1                          No. failed      =        148
                      Competing event: d2 == 2                          No. competing   =        143
                                                                        No. censored    =      1,470
                      
                                                                        Wald chi2(7)    =      45.80
                      Log pseudolikelihood = -1075.1207                 Prob > chi2     =     0.0000
                      
                                                  (Std. err. adjusted for 1,761 clusters in grpatid)
                      ------------------------------------------------------------------------------
                                   |               Robust
                                _t |        SHR   std. err.      z    P>|z|     [95% conf. interval]
                      -------------+----------------------------------------------------------------
                            Female |   1.560147   .2744972     2.53   0.011     1.105102    2.202565
                         age75plus |   2.985454   .5491266     5.95   0.000     2.081831    4.281296
                             Asian |   .8958582   .4613537    -0.21   0.831     .3264999    2.458077
                             Black |   1.134688   .2921316     0.49   0.624     .6850623    1.879416
                          Hispanic |   .7084065   .2102203    -1.16   0.245     .3959931    1.267294
                             COVID |   1.575292   .6663082     1.07   0.283     .6875818    3.609088
                          COVID_fe |   .8322585   .3906756    -0.39   0.696      .331658    2.088459
                      ------------------------------------------------------------------------------
                      (est99 stored)
                      
                      Survival-time data settings
                      
                                 ID variable: grpatid
                               Failure event: d2==1
                      Observed time interval: (start, stop]
                           Enter on or after: time start
                           Exit on or before: failure
                      
                      --------------------------------------------------------------------------
                           50,480  total observations
                                0  exclusions
                      --------------------------------------------------------------------------
                           50,480  observations remaining, representing
                            1,781  subjects
                              158  failures in single-failure-per-subject data
                           50,480  total analysis time at risk and under observation
                                                                      At risk from t =         0
                                                           Earliest observed entry t =         0
                                                                Last observed exit t =        31
                      
                      Bootstrap replications (10)
                      . myboot
                      (MWFE estimator converged in 5 iterations)
                      
                      HDFE Linear regression                            Number of obs   =     50,403
                      Absorbing 3 HDFE groups                           F(   1,   1100) =       0.03
                      Statistics robust to heteroskedasticity           Prob > F        =     0.8700
                                                                        R-squared       =     0.4646
                                                                        Adj R-squared   =     0.4518
                                                                        Within R-sq.    =     0.0000
                      Number of clusters (grpatid) =      1,101         Root MSE        =     0.1177
                      
                                                  (Std. err. adjusted for 1,101 clusters in grpatid)
                      ------------------------------------------------------------------------------
                                   |               Robust
                             COVID | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
                      -------------+----------------------------------------------------------------
                              tavg |    .000041   .0002503     0.16   0.870    -.0004501    .0005321
                             _cons |   .0253284   .0036804     6.88   0.000     .0181069    .0325498
                      ------------------------------------------------------------------------------
                      
                      Absorbed degrees of freedom:
                      -----------------------------------------------------+
                       Absorbed FE | Categories  - Redundant  = Num. Coefs |
                      -------------+---------------------------------------|
                           grpatid |      1101        1101           0    *|
                       monthlydate |        31           0          31     |
                             state |        45           1          44     |
                      -----------------------------------------------------+
                      * = FE nested within cluster; treated as redundant for DoF computation
                      data with multiple failures per subject not supported by stcrreg
                      an error occurred when bootstrap executed myboot, posting missing values
                      . myboot
                      (MWFE estimator converged in 5 iterations)
                      
                      HDFE Linear regression                            Number of obs   =     50,467
                      Absorbing 3 HDFE groups                           F(   1,   1132) =       0.57
                      Statistics robust to heteroskedasticity           Prob > F        =     0.4513
                                                                        R-squared       =     0.4395
                                                                        Adj R-squared   =     0.4258
                                                                        Within R-sq.    =     0.0000
                      Number of clusters (grpatid) =      1,133         Root MSE        =     0.1157
                      
                                                  (Std. err. adjusted for 1,133 clusters in grpatid)
                      ------------------------------------------------------------------------------
                                   |               Robust
                             COVID | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
                      -------------+----------------------------------------------------------------
                              tavg |   .0002244   .0002978     0.75   0.451    -.0003599    .0008086
                             _cons |   .0206067   .0043405     4.75   0.000     .0120903    .0291231
                      ------------------------------------------------------------------------------
                      
                      Absorbed degrees of freedom:
                      -----------------------------------------------------+
                       Absorbed FE | Categories  - Redundant  = Num. Coefs |
                      -------------+---------------------------------------|
                           grpatid |      1133        1133           0    *|
                       monthlydate |        31           0          31     |
                             state |        47           1          46     |
                      -----------------------------------------------------+
                      * = FE nested within cluster; treated as redundant for DoF computation
                      data with multiple failures per subject not supported by stcrreg
                      an error occurred when bootstrap executed myboot, posting missing values
                      . myboot
                      (MWFE estimator converged in 5 iterations)
                      
                      HDFE Linear regression                            Number of obs   =     50,275
                      Absorbing 3 HDFE groups                           F(   1,   1097) =       2.26
                      Statistics robust to heteroskedasticity           Prob > F        =     0.1328
                                                                        R-squared       =     0.4768
                                                                        Adj R-squared   =     0.4643
                                                                        Within R-sq.    =     0.0001
                      Number of clusters (grpatid) =      1,098         Root MSE        =     0.1121
                      
                                                  (Std. err. adjusted for 1,098 clusters in grpatid)
                      ------------------------------------------------------------------------------
                                   |               Robust
                             COVID | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
                      -------------+----------------------------------------------------------------
                              tavg |  -.0005847   .0003887    -1.50   0.133    -.0013474     .000178
                             _cons |   .0324401   .0055926     5.80   0.000     .0214667    .0434134
                      ------------------------------------------------------------------------------
                      
                      Absorbed degrees of freedom:
                      -----------------------------------------------------+
                       Absorbed FE | Categories  - Redundant  = Num. Coefs |
                      -------------+---------------------------------------|
                           grpatid |      1098        1098           0    *|
                       monthlydate |        31           0          31     |
                             state |        44           1          43     |
                      -----------------------------------------------------+
                      * = FE nested within cluster; treated as redundant for DoF computation
                      data with multiple failures per subject not supported by stcrreg
                      an error occurred when bootstrap executed myboot, posting missing values
                      . myboot
                      (MWFE estimator converged in 5 iterations)
                      
                      HDFE Linear regression                            Number of obs   =     50,582
                      Absorbing 3 HDFE groups                           F(   1,   1120) =       0.63
                      Statistics robust to heteroskedasticity           Prob > F        =     0.4260
                                                                        R-squared       =     0.4427
                                                                        Adj R-squared   =     0.4292
                                                                        Within R-sq.    =     0.0000
                      Number of clusters (grpatid) =      1,121         Root MSE        =     0.1146
                      
                                                  (Std. err. adjusted for 1,121 clusters in grpatid)
                      ------------------------------------------------------------------------------
                                   |               Robust
                             COVID | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
                      -------------+----------------------------------------------------------------
                              tavg |  -.0002022    .000254    -0.80   0.426    -.0007006    .0002961
                             _cons |   .0264981   .0036827     7.20   0.000     .0192723    .0337239
                      ------------------------------------------------------------------------------
                      
                      Absorbed degrees of freedom:
                      -----------------------------------------------------+
                       Absorbed FE | Categories  - Redundant  = Num. Coefs |
                      -------------+---------------------------------------|
                           grpatid |      1121        1121           0    *|
                       monthlydate |        31           0          31     |
                             state |        47           1          46     |
                      -----------------------------------------------------+
                      * = FE nested within cluster; treated as redundant for DoF computation
                      data with multiple failures per subject not supported by stcrreg
                      an error occurred when bootstrap executed myboot, posting missing values
                      . myboot
                      (MWFE estimator converged in 5 iterations)
                      
                      HDFE Linear regression                            Number of obs   =     50,458
                      Absorbing 3 HDFE groups                           F(   1,   1132) =       1.38
                      Statistics robust to heteroskedasticity           Prob > F        =     0.2407
                                                                        R-squared       =     0.4656
                                                                        Adj R-squared   =     0.4525
                                                                        Within R-sq.    =     0.0000
                      Number of clusters (grpatid) =      1,133         Root MSE        =     0.1192
                      
                                                  (Std. err. adjusted for 1,133 clusters in grpatid)
                      ------------------------------------------------------------------------------
                                   |               Robust
                             COVID | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
                      -------------+----------------------------------------------------------------
                              tavg |  -.0003164   .0002695    -1.17   0.241    -.0008452    .0002124
                             _cons |   .0312652   .0039265     7.96   0.000     .0235611    .0389694
                      ------------------------------------------------------------------------------
                      
                      Absorbed degrees of freedom:
                      -----------------------------------------------------+
                       Absorbed FE | Categories  - Redundant  = Num. Coefs |
                      -------------+---------------------------------------|
                           grpatid |      1133        1133           0    *|
                       monthlydate |        31           0          31     |
                             state |        46           1          45     |
                      -----------------------------------------------------+
                      * = FE nested within cluster; treated as redundant for DoF computation
                      data with multiple failures per subject not supported by stcrreg
                      an error occurred when bootstrap executed myboot, posting missing values
                      . myboot
                      (MWFE estimator converged in 5 iterations)
                      
                      HDFE Linear regression                            Number of obs   =     50,163
                      Absorbing 3 HDFE groups                           F(   1,   1133) =       0.63
                      Statistics robust to heteroskedasticity           Prob > F        =     0.4266
                                                                        R-squared       =     0.4477
                                                                        Adj R-squared   =     0.4340
                                                                        Within R-sq.    =     0.0000
                      Number of clusters (grpatid) =      1,134         Root MSE        =     0.1133
                      
                                                  (Std. err. adjusted for 1,134 clusters in grpatid)
                      ------------------------------------------------------------------------------
                                   |               Robust
                             COVID | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
                      -------------+----------------------------------------------------------------
                              tavg |  -.0001935   .0002432    -0.80   0.427    -.0006707    .0002838
                             _cons |   .0260118     .00353     7.37   0.000     .0190857    .0329378
                      ------------------------------------------------------------------------------
                      
                      Absorbed degrees of freedom:
                      -----------------------------------------------------+
                       Absorbed FE | Categories  - Redundant  = Num. Coefs |
                      -------------+---------------------------------------|
                           grpatid |      1134        1134           0    *|
                       monthlydate |        31           0          31     |
                             state |        46           1          45     |
                      -----------------------------------------------------+
                      * = FE nested within cluster; treated as redundant for DoF computation
                      data with multiple failures per subject not supported by stcrreg
                      an error occurred when bootstrap executed myboot, posting missing values
                      . myboot
                      (MWFE estimator converged in 5 iterations)
                      
                      HDFE Linear regression                            Number of obs   =     50,072
                      Absorbing 3 HDFE groups                           F(   1,   1102) =       0.27
                      Statistics robust to heteroskedasticity           Prob > F        =     0.6066
                                                                        R-squared       =     0.4296
                                                                        Adj R-squared   =     0.4158
                                                                        Within R-sq.    =     0.0000
                      Number of clusters (grpatid) =      1,103         Root MSE        =     0.1191
                      
                                                  (Std. err. adjusted for 1,103 clusters in grpatid)
                      ------------------------------------------------------------------------------
                                   |               Robust
                             COVID | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
                      -------------+----------------------------------------------------------------
                              tavg |  -.0002078   .0004034    -0.52   0.607    -.0009993    .0005837
                             _cons |   .0278769   .0058097     4.80   0.000     .0164777    .0392762
                      ------------------------------------------------------------------------------
                      
                      Absorbed degrees of freedom:
                      -----------------------------------------------------+
                       Absorbed FE | Categories  - Redundant  = Num. Coefs |
                      -------------+---------------------------------------|
                           grpatid |      1103        1103           0    *|
                       monthlydate |        31           0          31     |
                             state |        46           1          45     |
                      -----------------------------------------------------+
                      * = FE nested within cluster; treated as redundant for DoF computation
                      data with multiple failures per subject not supported by stcrreg
                      an error occurred when bootstrap executed myboot, posting missing values
                      . myboot
                      (MWFE estimator converged in 6 iterations)
                      
                      HDFE Linear regression                            Number of obs   =     49,725
                      Absorbing 3 HDFE groups                           F(   1,   1114) =       0.32
                      Statistics robust to heteroskedasticity           Prob > F        =     0.5726
                                                                        R-squared       =     0.4765
                                                                        Adj R-squared   =     0.4637
                                                                        Within R-sq.    =     0.0000
                      Number of clusters (grpatid) =      1,115         Root MSE        =     0.1153
                      
                                                  (Std. err. adjusted for 1,115 clusters in grpatid)
                      ------------------------------------------------------------------------------
                                   |               Robust
                             COVID | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
                      -------------+----------------------------------------------------------------
                              tavg |  -.0001424   .0002523    -0.56   0.573    -.0006375    .0003526
                             _cons |   .0274934   .0036381     7.56   0.000     .0203551    .0346318
                      ------------------------------------------------------------------------------
                      
                      Absorbed degrees of freedom:
                      -----------------------------------------------------+
                       Absorbed FE | Categories  - Redundant  = Num. Coefs |
                      -------------+---------------------------------------|
                           grpatid |      1115        1115           0    *|
                       monthlydate |        31           0          31     |
                             state |        46           1          45     |
                      -----------------------------------------------------+
                      * = FE nested within cluster; treated as redundant for DoF computation
                      data with multiple failures per subject not supported by stcrreg
                      an error occurred when bootstrap executed myboot, posting missing values
                      . myboot
                      (MWFE estimator converged in 5 iterations)
                      
                      HDFE Linear regression                            Number of obs   =     50,300
                      Absorbing 3 HDFE groups                           F(   1,   1133) =       0.09
                      Statistics robust to heteroskedasticity           Prob > F        =     0.7582
                                                                        R-squared       =     0.4410
                                                                        Adj R-squared   =     0.4272
                                                                        Within R-sq.    =     0.0000
                      Number of clusters (grpatid) =      1,134         Root MSE        =     0.1178
                      
                                                  (Std. err. adjusted for 1,134 clusters in grpatid)
                      ------------------------------------------------------------------------------
                                   |               Robust
                             COVID | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
                      -------------+----------------------------------------------------------------
                              tavg |  -.0001098   .0003568    -0.31   0.758    -.0008098    .0005901
                             _cons |   .0264254   .0051788     5.10   0.000     .0162642    .0365866
                      ------------------------------------------------------------------------------
                      
                      Absorbed degrees of freedom:
                      -----------------------------------------------------+
                       Absorbed FE | Categories  - Redundant  = Num. Coefs |
                      -------------+---------------------------------------|
                           grpatid |      1134        1134           0    *|
                       monthlydate |        31           0          31     |
                             state |        46           1          45     |
                      -----------------------------------------------------+
                      * = FE nested within cluster; treated as redundant for DoF computation
                      data with multiple failures per subject not supported by stcrreg
                      an error occurred when bootstrap executed myboot, posting missing values
                      . myboot
                      (MWFE estimator converged in 5 iterations)
                      
                      HDFE Linear regression                            Number of obs   =     50,560
                      Absorbing 3 HDFE groups                           F(   1,   1118) =       2.27
                      Statistics robust to heteroskedasticity           Prob > F        =     0.1320
                                                                        R-squared       =     0.4337
                                                                        Adj R-squared   =     0.4200
                                                                        Within R-sq.    =     0.0001
                      Number of clusters (grpatid) =      1,119         Root MSE        =     0.1210
                      
                                                  (Std. err. adjusted for 1,119 clusters in grpatid)
                      ------------------------------------------------------------------------------
                                   |               Robust
                             COVID | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
                      -------------+----------------------------------------------------------------
                              tavg |  -.0004248   .0002818    -1.51   0.132    -.0009778    .0001282
                             _cons |   .0321098   .0041001     7.83   0.000     .0240651    .0401544
                      ------------------------------------------------------------------------------
                      
                      Absorbed degrees of freedom:
                      -----------------------------------------------------+
                       Absorbed FE | Categories  - Redundant  = Num. Coefs |
                      -------------+---------------------------------------|
                           grpatid |      1119        1119           0    *|
                       monthlydate |        31           0          31     |
                             state |        44           1          43     |
                      -----------------------------------------------------+
                      * = FE nested within cluster; treated as redundant for DoF computation
                      data with multiple failures per subject not supported by stcrreg
                      an error occurred when bootstrap executed myboot, posting missing values
                      insufficient observations to compute bootstrap standard errors
                      no results will be saved
                      r(2000);
                      
                      end of do-file
                      
                      r(2000);

                      Comment


                      • #12
                        I'm sorry, but I'm out of ideas on this. I really don't know why you are getting that error at this point.

                        Comment


                        • #13
                          I wish it had worked but I really appreciate you trying to help. Thank you so much. 🙏

                          Comment

                          Working...
                          X