Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down at the end of May, and its replacement, **statalist.org** is already up and running.

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

From |
Nick Cox <njcoxstata@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: data management question |

Date |
Thu, 1 Mar 2012 00:27:00 +0000 |

You could -tsset- or -xtset- these data and then use -tsspell- (SSC) to identify spells in which there was uninterrupted use. tsset id day tsspell, pcond(number) Then the median length of spells is given by su _seq if _end, detail Principles for analysing spells are discussed in SJ-7-2 dm0029 . . . . . . . . . . . . . . Speaking Stata: Identifying spells . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox Q2/07 SJ 7(2):249--265 (no commands) shows how to handle spells with complete control over spell specification This paper is independent of -tsspell-. -tsspell- I suspect provides all the basic tools you need. Nick On Wed, Feb 29, 2012 at 11:14 PM, Maria Cecilia Vieira da Silva <mcvieira@mapigroup.com> wrote: > Hello, > My data set looks like below. Each patient (here patient 1 and 2) takes or not pills each day (from day 1 to day 12). I would like to estimate the median number of days that the patients take the pill uninterruptedly. For example, the median is 3 in the case below - Patient 1 (3, 4, 1) and Patient 2 (3, 2). > Any suggestions about how to implement it in a large data set? > I though about creating a dummy (number of pills>0) and performing sums for the series bordered by zeros, but I am not sure about a command that would allow me to create subseries defined as series of numbers bordered by zeros. Actually, if I could create such subseries, it would suffice to perform a count. > Thanks, > Maria Cecilia > > > id day number of pills > 1 1 1 > 1 2 2 > 1 3 1 > 1 4 0 > 1 5 0 > 1 6 2 > 1 7 1 > 1 8 2 > 1 9 3 > 1 10 0 > 1 11 0 > 1 12 1 > 2 1 0 > 2 2 0 > 2 3 0 > 2 4 1 > 2 5 1 > 2 6 1 > 2 7 0 > 2 8 0 > 2 9 0 > 2 10 2 > 2 11 2 > 2 12 0 * * 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/

**References**:**st: data management question***From:*Maria Cecilia Vieira da Silva <mcvieira@mapigroup.com>

- Prev by Date:
**Re: st: data management question** - Next by Date:
**Re: st: RE: intreg with fixed effects and clustered standard errors** - Previous by thread:
**Re: st: data management question** - Index(es):