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 23:33:41 +0100

Sure. I wasn't paying attention to the whole question, just

 Is it not possible to represent day-month as a date in Stata?
Nick
[email protected]


On 13 August 2013 23:30, Sergiy Radyakin <[email protected]> wrote:
> Nick, the question is how to create a pool of candidates (date) for
> the condition you posted. Suppose the end of the period is 100 years
> from begin. That makes it close to a hundred candidates to probe.
> Fortunately in this case we know that any period longer than a year
> would contain any given day for certain, so we don't need to probe
> anything when endorig-begorig>=366.
>
> The interesting case is to find the candidates within the remaining
> situations. I see two candidates, 30jun in the year of begorig and
> 30jun in the year of endorig.
>
> My solution is here:
> do http://radyakin.org/statalist/2013081301/dateinrange2.do
>
> Roberto should be careful that although this solution seems to work
> fine for June 30, it would NOT work for February 29, for apparent
> reasons.
>
> This is also an example of the nested cond() for the discussion
> started last week
> http://www.stata.com/statalist/archive/2013-08/msg00351.html
>
> Best, Sergiy Radyakin
>
>
>
> On Tue, Aug 13, 2013 at 5:39 PM, Nick Cox <[email protected]> wrote:
>> Think of your birthday. Does it define a single date? No, it defines a
>> set of dates.
>>
>> Either way, Stata doesn't regard a day-month as a date, but that need
>> not stand in your way. Your condition is just something like
>>
>> ... if month(date) == 12 & day(date) == 25
>>
>> and you can add extra condition(s) in terms of -year(date)- if you wish.
>> Nick
>> [email protected]
>>
>>
>> On 13 August 2013 22:33, Roberto Ferrer <[email protected]> wrote:
>>> 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/
>> *
>> *   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