I am doing a study of credit risk in europe for the period of 2006 - 2016 by using the Cox Proportional Hazard Model (time costant edition) in R (coxph). I have succesfully implemented the model for the whole period with 8 independent variables.

Now I want to make 2 subgroups (2006 - 2010 and 2011 - 2016) in order to compare the coefficients between the two subgroups. I have created a dataset of the sub groups by with a dummy variable (Subgroup) so that 2006 - 2010 = 0 and 2011 - 2016 = 1.

What is the next step in the analysis in order to compare the coefficients in the two sub groups?

Dataset: https://www.dropbox.com/s/bslulf4dud6zaxq/0610og1116.csv?dl=0

I dont know if i have done it correctly in the code below?

so far?


1 Answer 1


R takes care of creating dummy variables. You just need to include qualitative predictor in formula inside coxph.

E.g. if X and Y are quantitative and Z is qualitative,

coxph(Surv(time, status) ~ X + Y + Z)

should work.

You may also add interactions to check if Z affects coefficients of X and y:

coxph(Surv(time, status) ~ X + Y + Z + X:Z + Y:Z)
  • $\begingroup$ Thank you @Łukasz - could you please be a bit more specific? The following is from my model covering the whole period (2006 - 2016): cox.FINAL<-coxph(Surv(N, Konkurs) ~ ROA+GDP+LIBOR+PCL.TA+VIX+DEPTA,data=CoxData) $\endgroup$ Commented Jun 23, 2017 at 12:52
  • $\begingroup$ I assume that in CoxDatayou have a variable called YEAR or somthing similar. First, you have to cut it to get subgroups (2006 - 2010 and 2011 - 2016) : CoxData$YEARCUT<-cut(CoxData$YEAR, c(2006,2010,2016), include.lowest=T and then use it in coxph: coxph(Surv(N, Konkurs) ~ ROA+GDP+LIBOR+PCL.TA+VIX+DEPTA+YEARCUT,data=CoxData) $\endgroup$ Commented Jun 23, 2017 at 12:57
  • $\begingroup$ This solution doesn't work for me. The variable N in my cox model is the time to event / censoring. I have constructed my dataset in excel and imported to R afterwards. So i dont have the "years" variable. I have created the sub datasets manually - how do i compare coefficients now? Thank you in advance ! $\endgroup$ Commented Jun 23, 2017 at 13:47
  • $\begingroup$ Add YEAR variable to your Excel $\endgroup$ Commented Jun 23, 2017 at 14:20
  • $\begingroup$ I am sorry, but is not possible to make a clear cut like that. Constructing a dataset for this purpose must be constructed in a speciale manner. The time to event variable must be present. But i have found another solution on how to implement the dummy variable. Could you please help me with the comparison of coefficients? $\endgroup$ Commented Jun 23, 2017 at 14:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.