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 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]

Re: st: generating a variable that requires comparing two dates


From   "Ariel Linden, DrPH" <ariel.linden@gmail.com>
To   <statalist@hsphsun2.harvard.edu>
Subject   Re: st: generating a variable that requires comparing two dates
Date   Fri, 12 Apr 2013 12:41:33 -0400

Hi Nick,

I just read the article and don't see how that code would help me here. The
data is already in long format, and I am not clear on how expanding the data
would help? I need to find the date in one variable that corresponds with
the date in the second variable, but those dates are not always on the same
line or on the next line (so using the "gen cond(n==1, arrival, leave)"
doesn't seem relevant)?

Thanks!

Ariel  


Date: Fri, 12 Apr 2013 01:33:52 +0100
From: Nick Cox <njcoxstata@gmail.com>
Subject: Re: st: generating a variable that requires comparing two dates

One technique that can be useful with paired dates is to -expand 2-.

See http://www.stata-journal.com/article.html?article=dm0068


Nick
njcoxstata@gmail.com


On 11 April 2013 20:16, Ariel Linden, DrPH <ariel.linden@gmail.com> wrote:
> Hi fellow listers,
>
> This may be an easy task, but I am not getting it right...
>
> I would like to generate a new variable ( by ID) that will equal 1 if
there
> was an alert (triggered on the surveydate, when that surveydate was the
same
> as the admitdate. The obvious problem is that the dates are not always
> aligned so a straight "bys ID: gen test if surveydate==admitdate &
alert==1"
> will not always work.
>
> In the data below, the code would need to "see" that the admitdate of
> 4/6/2011 has a corresponding surveydate a few lines down where the
alert==1.
> Similarly, the next admitdate is 4/20/2011, so it would need to lookup the
> corresponding surveydate and verify that alert==1.
>
> I would then like to run this code again (generating a new variable) where
> we'd look to see if there was an alert on the surveydate the day before
the
> admitdate (ie., surveydate = admitdate - 1)
>
> Thanks in advance!
>
> Ariel
>
> **** example data****
>
> ID      surveydate      alert   admitdate
> 1       4/2/2011        1       4/6/2011
> 1       4/3/2011        1       4/20/2011
> 1       4/4/2011        0       4/20/2011
> 1       4/5/2011        0       4/20/2011
> 1       4/6/2011        1       4/20/2011
> 1       4/7/2011        0       4/20/2011
> 1       4/8/2011        0       4/20/2011
> 1       4/9/2011        0       4/20/2011
> 1       4/10/2011       0       4/20/2011
> 1       4/11/2011       0       4/20/2011
> 1       4/12/2011       0       4/20/2011
> 1       4/13/2011       0       4/20/2011
> 1       4/14/2011       0       4/20/2011
> 1       4/15/2011       0       4/20/2011
> 1       4/16/2011       0       4/20/2011
> 1       4/17/2011       0       4/20/2011
> 1       4/18/2011       0       4/20/2011
> 1       4/19/2011       0       4/20/2011
> 1       4/20/2011       1       4/20/2011
> 1       4/21/2011       0       4/20/2011
> *************************************
>


*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index