I have not used -margins- much. I do not know if it is a bug or a design feature, but I have always been wary of using -margins- with ratio outcomes. I think the results are only correct with linear predictors.
For your Cox model, you can use margins on the linear predictor by
. margins , over(posttran surgery) exp(predict(xb))
You can then manually exponentiate the results to get the same results presented by -stcox-
NOTE: The -exp- above is an abbreviation of -expression- (an option to -margins-), not the exponential function.
Also, the command
. margins , over(posttran surgery) exp(exp(predict(xb)))
(where the second -exp- is the exponential function) does not produce the correct results. Instead it produces the same output as the default option.
In short, you have to use -margins-, then exponentiate. You cannot exponentiate then use -margins-.
In Stata forums, you are asked to explain where user-written programs come from; that seems a good convention for CV too. As Pier Luigi should already know, switchr
can be installed by typing in Stata
ssc install switchr
You are looking at the syntax statement from the help, but later in the help there is much more detail and examples of main and regime equations. Scroll down to the end to see. (A general tip with unfamiliar commands is to look at the examples first.)
Correct spelling is Markov.
Best Answer
In package survival, it's
coxph
. John Fox has a nice introduction to using coxph in R: