Shantanu Nundy wrote:
> I am working with panel data and am struggling to do manipulations with the data given that the time differences between ob[n] and ob[n-1] are not constant.Here is my specific problem at hand: I have a variable that is either 1 or 0. I want to define an "episode" of 1, where episode is defined the time between the first 1 and the last 1 that is followed by at least three 0s AND over at least 21 days. From my list of 1s and 0s, I would to define a "episode_start" variable that is 1 for the start of each episode and for a second variable "episode_day" to be 1 for all days of an episode. The trouble is that in some cases the three 0s may be over 5 days and other times over 25 days. If the three 0s are over 5 days, we need to checking more observations as long as the variable remains 0 until 21 days has been reached.I have found a solution but it is by no means elegant and consists of over 20 lines of the following (where codigo is my panel variable, giardia is the 1 or 0 vari
ab!
> le, giardia_i is the desire "episode_start" variable, and date is time):by codigo: replace giardia_i=1 if count_result==1 & giardia==1 & (date - date[_n-4] >= 21 | giardia[_n-4]==.) & giardia[_n-4]!=1by codigo: replace giardia_i=1 if count_result==1 & giardia==1 & (date- date[_n-5] >= 21 | date[_n-5]==.) & giardia[_n-4]!=1 & giardia[_n-5]!=1
The user-written -tsspell-, available from SSC, might be of use here.
However, I haven't used this routine, so I can't give you examples of
how to use it for your specific problem.
--
Clive Nicholas
[Please DO NOT mail me personally here, but at
<[email protected]>. Thanks!]
"Courage is going from failure to failure without losing enthusiasm."
-- Winston Churchill
*
* 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/