Hello everyone,
I am currently struggling with some of my data analysis. I am not experiencing any problems with my results, but I am not sure whether I am using the right code. I get mixed messages on this from the internet and textbooks, so I would appreciate if someone could help me figure this out.
I use stata 13, and the stcox command.
My aim is to establish the hazard of failure for a particular regime, and some of my predictor variables are categorical indicator variables. The proportional hazard tests indicate that the effects of the instability variable vary over time, so I tried to include it as a variable with time-varying effect in the model.
Some sources seem to imply that categorical variables cannot be used like continuous predictors in the model, but instead I should stratify on the categorical variable (I don't want to do that because instability is theoretically too important, and I need to know the hazard ratio). Other sources say 'use stsplit' and then treat categorical indicator like continuous one in the code. But my data is already in a one record per one unit of time format.
This is what the data looks like:
The code I use to include instability as a variable with time-varying effect is:
Where instabt is the interaction between the indicator variable and time.
Unfortunately, the command:
does not work (which worries me!) but the stpm2 command:
works perfectly fine and returns results almost identical to the cox command.
Am I doing the right thing here? Is this methodologically correct?
I would very much appreciate your advice on this.
Thank you very much,
Basia
I am currently struggling with some of my data analysis. I am not experiencing any problems with my results, but I am not sure whether I am using the right code. I get mixed messages on this from the internet and textbooks, so I would appreciate if someone could help me figure this out.
I use stata 13, and the stcox command.
My aim is to establish the hazard of failure for a particular regime, and some of my predictor variables are categorical indicator variables. The proportional hazard tests indicate that the effects of the instability variable vary over time, so I tried to include it as a variable with time-varying effect in the model.
Some sources seem to imply that categorical variables cannot be used like continuous predictors in the model, but instead I should stratify on the categorical variable (I don't want to do that because instability is theoretically too important, and I need to know the hazard ratio). Other sources say 'use stsplit' and then treat categorical indicator like continuous one in the code. But my data is already in a one record per one unit of time format.
This is what the data looks like:
Code:
regimeID year failure instability regimeA 1991 0 0 regimeA 1992 0 1 regimeA 1993 0 1 regimeA 1994 0 1 regimeA 1995 0 0 regimeA 1996 0 0 regimeA 1997 0 0 regimeA 1998 0 0 regimeA 1999 0 1 regimeA 2000 1 1 regimeB 1991 0 0 regimeB 1992 0 0 regimeB 1993 0 1 regimeB 1994 0 1 regimeB 1995 0 0 regimeB 1996 0 0 regimeB 1997 0 0 regimeB 1998 0 1 regimeB 1999 0 0 regimeB 2000 0 0 regimeB 2001 0 1 regimeB 2002 0 0 regimeB 2003 1 0
The code I use to include instability as a variable with time-varying effect is:
Code:
stcox instability instabt
Unfortunately, the command:
Code:
stcox instability, tvc(instability)
Code:
stpm2 instability, df(4) scale(hazard) tvc(instability) dftvc(3)
Am I doing the right thing here? Is this methodologically correct?
I would very much appreciate your advice on this.
Thank you very much,
Basia