Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re:st: Overlapping dates


From   n j cox <[email protected]>
To   [email protected]
Subject   Re:st: Overlapping dates
Date   Thu, 02 Feb 2006 16:04:53 +0000

Anton is correct about -disjoint-. It is not
designed for his problem.

At worst his -d0- and -d1- are string variables
that need to be converted:

clear
set obs 2
gen d0 = cond(_n == 1, "1Jan99", "2Jan99")
gen d1 = cond(_n == 1, "6Jan99", "7Jan99")
gen x = _n
gen date0 = date(d0, "dmy", 2050)
gen date1 = date(d1, "dmy", 2050)
format date* %dd_m_CY

Get how long each programme lasted and -expand-:

gen duration = date1 - date0 + 1
gen id = _n
expand duration

Map first date variable to increasing sequences

bysort id : replace date0 = date0[_n-1] + 1 if _n > 1

and cumulate identifiers:

gen  which = ""
bysort date0 (x) : replace which =
	which[_n-1] + string(x) + " " if x != x[_n-1]

Clean up:

by date0 : keep if _n == _N
bysort which (date0) : replace date1 = date0[_N]
bysort which (date0) : keep if _n == 1
drop dur id
replace which = trim(which)

This is what I get:

     +-------------------------------------------------------+
     |     d0       d1   x        date0        date1   which |
     |-------------------------------------------------------|
  1. | 1Jan99   6Jan99   1   1 Jan 1999   1 Jan 1999       1 |
  2. | 2Jan99   7Jan99   2   2 Jan 1999   6 Jan 1999     1 2 |
  3. | 2Jan99   7Jan99   2   7 Jan 1999   7 Jan 1999       2 |
     +-------------------------------------------------------+

My results differ from Anton's example.

Nick
[email protected]


Anton econ (edited):

In my data set I have a number of overlapping dates
showing start and end of various programmes. I would like to
create a dataset which consists of consecutive dates and
contains information on types of programmes.
(See example below.)

Potentially this can be solved with the -spellsplit-
command which is a part of the -spellutil- package.
However -spellsplit- allows you only to sum or average
variables included into the dataset.
The -disjoint- command does not seem to solve the problem
either.


/*** Example  ***/

           d0        d1          x
  1.   1Jan99    6Jan99          1
  2.   2Jan99    7Jan99          2

              d0          d1          x
  1.   01Jan1999   02Jan1999          1
  2.   02Jan1999   07Jan1999         1;2
*
*   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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index