Categorical variable with hierarchical structure - Cox regression What is the best way to build a cox model with a categorical variable that has a hierarchical structure (20 levels).
 A: The main choice here seems to be how deeply you want to go into the hierarchical structure of the categorical variable. The usual rule of thumb for a Cox model is 10-20 events per "independent variable." For a single categorical variable, the number of "independent variables" is 1 fewer than its number of possible values. If these are mutually exclusive categories at all hierarchical levels, then it would seem to make the most sense to go down to the number of levels of the categorical variable so that you have the number of possible values of the categorical variable compatible with your number of events.
Added in response to new information:
With over 500 events you should have enough data to analyze all 20 values of your categorical variable if you wish. If you really need to do all pairwise comparisons among the values of this variable with respect to outcome, the glht function in the R multcomp can do this, if you specify linfct=mcp(treat = "Tukey") in the call to the function (replacing "treat" with the name of your categorical variable).
With 190 pairwise comparisons, however, the correction for multiple comparisons will make it difficult to find any differences significant. If you are doing this on a Cox model then you will have to document that the proportional hazards assumption is met for all values of the variable. And I suspect that the results of the multiple comparisons will depend heavily on the particular data sample you have, as you could evaluate by bootstrapping.
You might consider taking the hierarchical structure of the values of this variable into account, if you think that the hierarchical structure is related to outcome. For example, you could proceed through the hierarchy evaluating the first 2 values at the highest level, then go down a level to evaluate the 4 values at the next level, and so forth. I haven't thought through how to correct this for multiple comparisons as you go through the hierarchy, but it might lead to selection of a number/level of variable values that is less affected by vagaries of sampling, as tested by bootstrapping, and with less loss for multiple-comparison correction at the ultimate level of analysis.
