Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | "Sarah Tougher" <Sarah.Tougher@lshtm.ac.uk> |
To | "Nick Cox" <njcoxstata@gmail.com>, <statalist@hsphsun2.harvard.edu> |
Subject | Re: re: re:st: Creating variable based on time reference (Out of office) |
Date | Thu, 20 Oct 2011 09:01:04 +0100 |
I am out of the office until November 7th. I have intermittent access to email, but will try to return your message as soon as possible. >>> Nick Cox <njcoxstata@gmail.com> 10/20/11 08:59 >>> 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/ * * 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/