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
[email protected]
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:[email protected]]
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/