Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Solved: stcox and tvc. Translation of SAS program


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Solved: stcox and tvc. Translation of SAS program
Date   Tue, 14 Jun 2005 18:02:09 +0100

gen i1=0
replace i1=1 if (time==0&case==0)

could be condensed to 

gen i1 = time == 0 & case == 0 

The three -generate-s could be 
done at once, modulo a change 
of names: 

forval j = 1/3 { 
	gen i`j' = time == `j' & case == 0 
} 

So, 

gen id=_n
stset year, failure(hd==1) id(id)
stsplit time, at(1,2)
forval j = 1/3 { 
	gen i`j' = time == `j' & case == 0 
} 
stcox i0 i1 i2 age1 age2 gender c1 c2

Nick
n.j.cox@durham.ac.uk 

Claus Dethlefsen

Thanks to Benoît Laplante, I was pointed towards the manual on "stsplit" and I am now able to reproduce the output from SAS in my Stata program. In case others are interested, here is my solution

/* Attempt 4 */

gen id=_n
stset year, failure(hd==1) id(id)
stsplit time, at(1,2)
gen i1=0
replace i1=1 if (time==0&case==0)
gen i2=0
replace i2=1 if (time==1&case==0)
gen i3=0
replace i3=1 if (time==2&case==0)

stcox i1 i2 i3 age1 age2 gender c1 c2

I am quite sure, that this could be done more elegantly, but I'm still learning.


*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index