Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

st: Looping over observations


From   Albert Navarro <albertnavarro2002@yahoo.es>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   st: Looping over observations
Date   Thu, 17 Nov 2011 11:32:14 +0000 (GMT)

Dear all,

We have simulated an arbitrary number of observations of survival data, where each individual can have several episodes and each episode has its own generating process, from the first one until the fourth. From the fourth episode and until the time when a new episode occurs is before the follow-up time (which is a fixed parameter in our simulation) we want to generate new episodes for each individual. We have tried to do this with a ‘while’ loop, but it only takes into account the value for the first individual, and this is no option for us as we want this loop running for each individual. Any ideas on how to do this?

Our current code (part of the loop): 
 
while (suma < max_time) {
                                  replace ui = uniform() if (suma < 120 & it4 == 1)
                                  gen t`i'c = ((log(1/ui)/0.009961534))^(1/ 1.42213732720679) if (suma < 120 & it4 == 1)
                                  replace uj = uniform() if (suma < 120 & it4 == 1)
           gen t`i'b = ((log(1/uj)/0.1717102))^(1/0. 85817155198598) if (suma < 120 & it4 == 1)
                                  replace suma = `suma' + t`i'b
                                  gen it`i' = 1 if (suma < 120 & it4 == 1)
                                  replace it`i' = 0 if (t`i'c < t`i'b | suma > `time')
                                  local i = `i' + 1
                                 
                                }

Thanks in advance!

Albert

*
*   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   |   Site index