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 on April 23, and its replacement, statalist.org is already up and running.


[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 <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
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 <kit.baum@bc.edu> 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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index