Announcement

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

  • Get all estimates to appear in automated output for Cox models

    I am attempting to create an automated table using collect of the univariable and adjusted results of some Cox models. In the adjusted analysis, I am adjusting for age, sex and HIV viral load status at drug start. However with the code I am using the estimates for the variables I am adjusting for are being overwritten/cancelled out. Please can you suggest a way to avoid this?

    This is the code I am using:


    collect _r_b _r_ci _r_p, ///
    tag(model[(2)] colname[1.age]) ///
    : stcox age i.vl_group sex

    collect _r_b _r_ci, ///
    tag(model[(2)]) ///
    : stcox i.age_gp i.vl_group sex
    collect get _r_p=(r(p)), tag(model[(2)] colname[1.age_gp]): testparm i.age_gp

    collect _r_b _r_ci _r_p, ///
    tag(model[(2)] colname[1.sex]) ///
    : stcox sex i.vl_group age

    collect _r_b _r_ci, ///
    tag(model[(2)]) ///
    : stcox i.vl_group age sex
    collect get _r_p=(r(p)), tag(model[(2)] colname[1.vl_group]): testparm i.vl_group

    collect _r_b _r_ci _r_p, ///
    tag(model[(2)]) ///
    : stcox prevfail i.vl_group age sex

    and this is the output:
    Adjusted for age, sex & VL status at drug start
    Hazard ratio 95% CI p-value
    Age (years)
    0 to <6 1.00 0.497
    6 to <12 1.93 (0.25,14.92)
    12 to <18 2.51 (0.34,18.29)
    Sex
    Naive <0.001
    ART experienced, VL≥200c/mL
    ART experienced, VL<200c/mL
    ART experienced, VL unknown
    Previous treatment failure 2.64 (1.47, 4.72) 0.001
    Apologies that I haven't provided a dataset to test with.

    Thanks!

  • #2
    Hi Karen, it easily takes me a day just to make a collect table. Powerful command but very unintuitive. I actually found your post because I am having difficulties collecting all my predictors and laying them out in a table.

    Anyway, to my naive eye, it appears that you are overwriting each subsequent model's collected results because they are all assigned to model 2. Each separate stcox model should be stored in its own level within the model dimension:

    Code:
    collect _r_b _r_ci _r_p, ///
    tag(model[(1)] colname[1.age]) ///
    : stcox age i.vl_group sex
    
    collect _r_b _r_ci, ///
    tag(model[(2)]) ///
    : stcox i.age_gp i.vl_group sex
    collect get _r_p=(r(p)), tag(model[(2)] colname[1.age_gp]): testparm i.age_gp
    
    collect _r_b _r_ci _r_p, ///
    tag(model[(3)] colname[1.sex]) ///
    : stcox sex i.vl_group age
    
    collect _r_b _r_ci, ///
    tag(model[(4)]) ///
    : stcox i.vl_group age sex
    collect get _r_p=(r(p)), tag(model[(4)] colname[1.vl_group]): testparm i.vl_group
    
    collect _r_b _r_ci _r_p, ///
    tag(model[(5)]) ///
    : stcox prevfail i.vl_group age sex
    Or something similar. One could use a macro counter between each model to minimise transcription errors. Not sure if it will work but worth a try.

    Good luck!

    Comment

    Working...
    X