Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: Identify Closest Subsequent Date


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Identify Closest Subsequent Date
Date   Thu, 4 Apr 2013 18:03:41 +0100

Assuming release1-release7 are the release variables, try

gen clsdate = .
gen lapse = .

forval j = 1/7 {
       replace clsdate = release`j' if release`j' > cdate &
(release`j' - cdate) < lapse
       replace lapse = release`j' - cdate if clsdate == release`j'
}

Think carefully about whether whether

release`j' == cdate

is possible, in which case > should be >=.

For a review of working rowwise, see

SJ-9-1  pr0046  . . . . . . . . . . . . . . . . . . .  Speaking Stata: Rowwise
        (help rowsort, rowranks if installed) . . . . . . . . . . .  N. J. Cox
        Q1/09   SJ 9(1):137--157
        shows how to exploit functions, egen functions, and Mata
        for working rowwise; rowsort and rowranks are introduced

.pdf at http://www.stata-journal.com/sjpdf.html?articlenum=pr0046
Nick
[email protected]


On 4 April 2013 17:50, Julia Laskorunsky <[email protected]> wrote:
> Hi everyone,
>
> I have unique ID#s which list a court date and several release dates
> (0 to 7). I would like to ask Stata to identify the closest subsequent
> release date to the court date of interest. I have asked Stata to
> convert all date variables to elapsed format.  Here is an example of
> the data (sorry if the formatting gets messed up):
>
>
> ID  cdate    release1   release2   release3
> 1   16705   16799       18502           .
> 2   15088   15000            .                 .
> 3   16805      .                  .                 .
> 4    16000    15222      15899       16452
>
> Is there a way to generate a variable that identifies a subsequent
> released date (if there is one) to the court date? In the example
> above the variable would identify:
>
> ID  clsdate
> 1     16799
> 2         .
> 3         .
> 4      16452
>
> Using Stata 12. Thanks for everyone's help.
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index