Announcement

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

  • Why baseline hazard contributions different with code 0 1 or 1 2

    clear
    input time event str1 group
    1 2 B
    2 2 A
    3 0 A
    4 1 B
    5 1 A
    6 0 A
    7 2 B
    8 0 A
    9 1 B
    10 0 A
    11 2 A
    12 1 A
    13 1 A
    14 2 A
    15 2 B
    16 1 A
    17 1 B
    18 1 A
    19 0 A
    20 0 B
    end

    gen group1=0 if group=="A"
    replace group1=1 if group=="B"

    gen group2=1 if group=="A"
    replace group2=2 if group=="B"

    stset time, failure(event==1)
    stcox group1
    predict h1, basehc

    stcox group2
    predict h2, basehc

  • #2
    By definition, the baseline hazard is the hazard conditional on all predictor variables in the model being zero. For your group1 model, that is group A. For the group2 model, it is neither group and, in fact, that baseline hazard is completely meaningless. Nevertheless, the hazard ratio calculated for the group2 variable is still the hazard ratio associated with a unit change in group2, which, in this case means 2 vs 1, which corresponds to the coding you used there.

    What I want to also point out is that you should have coded the proportional hazards model as -stcox i.group2-. As things stand, you still get correct results for the hazard ratio. But without the i., Stata treats group2 as a continuous variable. If you had more than 2 levels, or if there were two levels but the codes differed by something other than 1, then the hazard ratios would be incorrect. Also, without the i., the -margins- command will treat it as a continuous variable and produce incorrect estimates for marginal effects.

    Comment

    Working...
    X