Dear Statalisters,

When we are checking for interactions in cox regression, what is the difference between using # and ##.
I created a categorical variable at by combining the two categorical variables I was checking interactions for and the output for the combination of the two variables (category 1) matches the output from the interaction term using only #.

I also get different outputs for continuous variables using # and ##.

however I have seen ## being used to check for interaction terms.

I would really appreciate any help with this.

Thank you



. gen at=1 if font==1 & tn==1

. replace at=2 if font==1 & tn==0

. replace at=3 if font==0 & tn==1

. recode at .=0
.
. stcox i.at

failure _d: death == 0
analysis time _t: time

Iteration 0: log likelihood = -13412.176
Iteration 1: log likelihood = -13401.235
Iteration 2: log likelihood = -13401.04
Iteration 3: log likelihood = -13401.04
Refining estimates:
Iteration 0: log likelihood = -13401.04

Cox regression -- Breslow method for ties

No. of subjects = 4500 Number of obs = 4500
No. of failures = 546
Time at risk = 67726
LR chi2(3) = 22.27
Log likelihood = -13401.04 Prob > chi2 = 0.0001

------------------------------------------------------------------------------
_t | Haz. Ratio Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
at |
1 | 1.385293 .2101892 2.15 0.032 1.028939 1.865064
2 | 1.215577 .1883428 1.26 0.208 .8972146 1.646905
3 | .830212 .0436796 -3.54 0.000 .7488676 .9203922
------------------------------------------------------------------------------

.
. stcox i.font#i.tn

failure _d: death == 0
analysis time _t: time

Iteration 0: log likelihood = -13412.176
Iteration 1: log likelihood = -13401.235
Iteration 2: log likelihood = -13401.04
Iteration 3: log likelihood = -13401.04
Refining estimates:
Iteration 0: log likelihood = -13401.04

Cox regression -- Breslow method for ties

No. of subjects = 4500 Number of obs = 4500
No. of failures = 546
Time at risk = 67726
LR chi2(3) = 22.27
Log likelihood = -13401.04 Prob > chi2 = 0.0001

---------------------------------------------------------------------------------
_t | Haz. Ratio Std. Err. z P>|z| [95% Conf. Interval]
----------------+----------------------------------------------------------------
font#tn |
0 1 | .830212 .0436796 -3.54 0.000 .7488676 .9203922
1 0 | 1.215577 .1883428 1.26 0.208 .8972146 1.646905
1 1 | 1.385293 .2101892 2.15 0.032 1.028939 1.865064
---------------------------------------------------------------------------------

.
. stcox i.font##i.tn

failure _d: death == 0
analysis time _t: time

Iteration 0: log likelihood = -13412.176
Iteration 1: log likelihood = -13401.235
Iteration 2: log likelihood = -13401.04
Iteration 3: log likelihood = -13401.04
Refining estimates:
Iteration 0: log likelihood = -13401.04

Cox regression -- Breslow method for ties

No. of subjects = 4500 Number of obs = 4500
No. of failures = 546
Time at risk = 67726
LR chi2(3) = 22.27
Log likelihood = -13401.04 Prob > chi2 = 0.0001

---------------------------------------------------------------------------------
_t | Haz. Ratio Std. Err. z P>|z| [95% Conf. Interval]
----------------+----------------------------------------------------------------
1.font | 1.215577 .1883428 1.26 0.208 .8972146 1.646905
1.tn | .830212 .0436796 -3.54 0.000 .7488676 .9203922
|
font#tn |
1 1 | 1.372683 .2983352 1.46 0.145 .8965458 2.101687
---------------------------------------------------------------------------------