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: re: re:st: Creating variable based on time reference


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: re: re:st: Creating variable based on time reference
Date   Thu, 20 Oct 2011 08:59:38 +0100

Another way to do it is

gen responsetime = cond(delta < 2, 1, cond(delta < 6, 2, 3))

with perhaps different inequalities <= and/or constants depending on
exactly "between" and "within" mean.

My personal bias against -irecode()- is that not only do I have to
look up the syntax every time, I also have to rediscover exactly what
happens with boundary cases and then document that as a part of any
respectable .do file. With -cond(,,)- my inequalities are always
explicit in the code. Conversely, the case against -cond(,,,)- is that
some find it too messy for multiple branches.

The code above is not smart about missings.

Nick

On Thu, Oct 20, 2011 at 3:42 AM, Christopher Baum <[email protected]> wrote:
> <.>
> To get the 'response time' categorical variable requested, the irecode() fu=
> nction is handy:
>
> bys group (datesubmitted): g delta =3D datesubmitted - datesubmitted[1]
> g responsetime = 1 + irecode(delta, 1, 5)
>
> . l
>
>    +-------------------------------------------------+
>    |   datesub   group   datesu~d   delta   respon~e |
>    |-------------------------------------------------|
>  1. | 10/1/2011       1      18901       0          1 |
>  2. | 10/9/2011       1      18909       8          3 |
>  3. |  8/1/2011       2      18840       0          1 |
>  4. |  8/2/2011       2      18841       1          1 |
>  5. |  8/5/2011       2      18844       4          2 |
>    +-------------------------------------------------+
>

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


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