Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: st: RE: survival data analysis- recode survival time variable


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: RE: survival data analysis- recode survival time variable
Date   Tue, 25 Aug 2009 15:04:38 +0100

The month is in these terms 

mod(SURV, 100) 

A one-liner is thus 

gen time_in_months = 12 * int(SURV/100) + mod(SURV, 100) 

-floor()- is an alternative to -int()-. 

There is more on -mod(,)- at

SJ-7-1  pr0031  . Stata tip 43: Remainders, selections, sequences,
extractions
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N.
J. Cox
        Q1/07   SJ 7(1):143--145                                 (no
commands)
        tip for uses of the modulus


A major omission in that Tip is that it doesn't mention rotations. E.g.
if you rotate 180 degrees clockwise you end up at mod(vector + 180,
360). 

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

Villa Lora, Juan Miguel

gen year = int(SURV/100)
tostring SURV, replace
gen month = substr(SURV,-2,.)
Replace month = SURV if month == ""

gen time_in_months = year*12 + real(month) 

From: Johannes Schoder [mailto:johannes.schoder@soi.uzh.ch]

Hi Juan,
Thank you very much for your help thats a great idea!!
However, when I run the command Stata always tells "type mismatch".
what I did:

gen year=substr(SURV, 1, 2)
**I guess this command is generating the year variable by just taking
the first to digits. And I guess here lies the problem because if the
survival time is e.g 1 year my spread sheet looks like this: 100 and not
0100. But I am totally not sure if this is the problem.

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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