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: Mark observation if date variable is between some range


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Mark observation if date variable is between some range
Date   Tue, 13 Aug 2013 21:00:51 +0100

See -help tin()-  and -help twithin()-
Nick
[email protected]


On 13 August 2013 20:54, Roberto Ferrer <[email protected]> wrote:
> I have date variables (type:  numeric daily date (int)) that define
> the beginning and end of an episode for any observation:
>
> begorig        endorig
> 01jan1998    31dec1998
> 01oct1998    05jul1999
> 01jan1999    31feb1999
>
> I'd like to mark the observation (with some dummy variable) if say,
> the day 30jun is between -begorig- and -endorig-. Note that the years
> in any episode are not necessarily the same.
>
> Below is something I wrote which does not work. I think I found the
> mistake but have not yet corrected it. Before doing that, can someone
> suggest an alternative way?
>
> local d 30
> local m 6
>
> gen dummy = 0
>
> /*
> If -begorig- and -endorig- have different years the possibilities are:
>      ------------------------
>      -begorig- and  -endorig-
>      ------------------------
>     1. before  and   anything  --> MARK
>     2. after    and   after     --> MARK
>     3. after    and   before    --> do nothing
> */
> replace dummy = 1 if ///
>     year(begorig) < year(endorig) & ///
>     day(begorig) <= `d' & month(begorig) <= `m' ///
>     | ///
>     year(begorig) < year(endorig) & ///
>     day(begorig) >= `d' & month(begorig) >= `m' & ///
>     day(endorig) >= `d' & month(endorig) >= `m'
>
> /*
> If -begorig- and -endorig- have the same year the possibilities are:
>      -----------------------
>      -begorig- and -endorig-
>      -----------------------
>     1. before  and   before  --> do nothing
>     2. before  and   after   --> MARK
>     3. after   and   after   --> do nothing
>     4. after   and   before  --> not possible
> */
> replace dummy = 1 if year(begorig) == year(endorig) & ///
>     day(begorig) <= `d' & month(begorig) <= `m' & ///
>     day(endorig) >= `d' & month(endorig) >= `m'
>
>
> Thank you.
> *
> *   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/
*
*   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