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   Roberto Ferrer <[email protected]>
To   Stata Help <[email protected]>
Subject   Re: st: Mark observation if date variable is between some range
Date   Tue, 13 Aug 2013 22:33:42 +0100

Nick and Sergiy,

Thank you for your replies.

Indeed, a typo in my first post.

Is there a way in which I can specify the probe as only day-month (no
year)? In case of an episode that spans two+ years, one appearance
would be enough to set the mark.

Could one strategy be create a series of probes for each observation
(based on the number of years spanning the episode) and to test them?
In a loop maybe.

A similar problem I think arises with -tin()- and -twithin()-. Is it
not possible to represent day-month as a date in Stata? I haven't been
able to find an example.





On Tue, Aug 13, 2013 at 9:29 PM, Sergiy Radyakin <[email protected]> wrote:
> Roberto, if your variable is numeric variable formatted as date, you
> should not be seeing "31feb1999" as you show in the output. February
> 31 is an impossible date in any year.
>
> Given that that is just a typo, all you need is
> inrange(candidate,beg,end). Most of the following program generates
> the data (that you already have) before applying inrange().
>
> do http://radyakin.org/statalist/2013081301/dateinrange.do
>
>      +----------------------------------------+
>      |   begorig     endorig   probe   marker |
>      |----------------------------------------|
>   1. | 01jan1998   31dec1998   14067        1 |
>   2. | 01oct1998   05jul1999   14246        1 |
>   3. | 01jan1999   21feb1999   15041        0 |
>      +----------------------------------------+
>
> The variable probe may of course vary by observation, or may be a constant:
> generate sprobe="30jun1999"
> (instead of the second input statement).
>
> Best, Sergiy
>
>
>
>
> On Tue, Aug 13, 2013 at 4:00 PM, Nick Cox <[email protected]> wrote:
>> 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/
> *
> *   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