Announcement

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

  • Collect estimates of bootstraped confidence intervals

    Hello,

    I am trying to collect the results of Kaplan-Meier curves with bootstrapped confidence intervals using the command collect.

    I tried the following code to extract the estimates of the coefficient, the bias and the bootstrapped CIs (line: collect layout (colname) (result[b_bs bias ci_bc]))
    Then, I aim to export them with putexcel.

    Code:
    preserve
    stset age2 if $missing [pw=what_last_nonmissing] , failure(mover) id(pidp)  enter(age) exit(time .)
    keep if _st==1
    collect clear 
    collect: bootstrap S1 = r(S1) S2 = r(S2) S3 = r(S3) S4 = r(S4) S5 = r(S5) S6 = r(S6) S7 = r(S7) S8 = r(S8) S9 = r(S9) S10 = r(S10), reps(10): get_survival
    collect style cell, nformat(%5.2f) cidelimiter(",") 
    collect layout (colname) (result[b_bs  bias ci_bc])
    collect style header colname, level(value)
    collect preview
    restore

    What I obtain is a table with the coefficient and the bias, but not the confidence intervals.
    You can see it below.



    Bootstrap Estimated
    estimates biases

    S1 1.00 | 0.00
    S2 0.97 | 0.00
    S3 0.87 | -0.00
    S4 0.78 | -0.00
    S5 0.70 | -0.00
    S6 0.65 | 0.01
    S7 0.60 | 0.01
    S8 0.54 | 0.01
    S9 0.46 | 0.01
    S10 0.44 | 0.01


    I would appreciate if you could help me obtain the confidence intervals. Thank you very much. Lydia





  • #2
    You did not provide us with any data to help us help you and show that our suggestions work.

    bootstrap posts the bias-corrected confidence intervals in the rows of the matrix e(ci_bc). So your layout needs to also include the rowname dimension.

    Here is an example, with data, that uses bootstrap with a linear model.
    Code:
    sysuse auto
    collect: bootstrap: regress mpg turn trunk
    collect layout (colname) (result[b_bs bias] result[ci_bc]#rowname)
    Here is the resulting table.
    Code:
    --------------------------------------------------------------------------------------------------
                          | Bootstrap estimates Estimated biases bias-corrected CIs bias-corrected CIs
                          |                                                      ll                 ul
    ----------------------+---------------------------------------------------------------------------
    Turn circle (ft.)     |           -.7854365        -.0244253          -1.117182          -.5003818
    Trunk space (cu. ft.) |           -.3341846        -.0180021          -.4671342          -.0248406
    Intercept             |            57.17028         1.350265           46.46913           64.42422
    --------------------------------------------------------------------------------------------------
    If you are looking to leverage something like the _r_ci composite result, implied by your use of collect style cell option cidelimiter(), then I suggest you collect the results differently, and define your own composite result.
    Code:
    sysuse auto
    * estimation, but do not use -collect:- prefix
    bootstrap: regress mpg turn trunk
    * collect row vectors and declare the CI limits separately
    collect get ///
        estimate=(e(b_bs)) ///
        bias=(e(bias)) ///
        ll=(e(ci_bc)["ll",1...]) ///
        ul=(e(ci_bc)["ul",1...])
    * define your own composite result for the CI
    collect composite define ci = ll ul, delimiter(", ")
    * format the numeric results
    collect style cell, nformat(%5.2f)
    * supply a custom label to your composite result
    collect label levels result ci "95% CI"
    * your other style choices
    collect style header colname, level(value)
    * arrange your collected results into a table
    collect layout (colname) (result[estimate bias ci])
    Here is the resulting table.
    Code:
    -----------------------------------
          | estimate  bias       95% CI
    ------+----------------------------
    turn  |    -0.74  0.02 -1.08, -0.53
    trunk |    -0.32 -0.01 -0.43, -0.01
    _cons |    54.91 -0.91 48.06, 65.99
    -----------------------------------

    Comment

    Working...
    X