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]
st: generating a seq() going backwards and forward from a given timepoint?
From
"Ariel Linden, DrPH" <[email protected]>
To
<[email protected]>
Subject
st: generating a seq() going backwards and forward from a given timepoint?
Date
Thu, 13 Dec 2012 22:31:13 -0500
Hi Listers,
This is probably a very simple solution, but I am getting stuck. I'd like to
generate a running sequence going both backwards and forwards from a
specified timepoint. -seq()- is pretty straightforward (pun intended) for
going forward, but I can't seem to figure out the backwards part.
Below I have and data with the "period" variable that I'd like to achieve
via code (I did this manually). For this example, I specified that
01/01/2012 is the starting point and ran the following code:
. display date("01/01/2012", "MDY")
18993
. bys ID: egen period = seq() if date>=18993
(48 missing values generated)
How do I get the backward periods (-1 to -24)? There will be IDs with
varying numbers of periods available, so this must work via bysort ID,
anchored on the same starting date for everyone:
ID date period
WC9 01/01/2010 -24
WC9 02/01/2010 -23
WC9 03/01/2010 -22
WC9 04/01/2010 -21
WC9 05/01/2010 -20
WC9 06/01/2010 -19
WC9 07/01/2010 -18
WC9 08/01/2010 -17
WC9 09/01/2010 -16
WC9 10/01/2010 -15
WC9 11/01/2010 -14
WC9 12/01/2010 -13
WC9 01/01/2011 -12
WC9 02/01/2011 -11
WC9 03/01/2011 -10
WC9 04/01/2011 -9
WC9 05/01/2011 -8
WC9 06/01/2011 -7
WC9 07/01/2011 -6
WC9 08/01/2011 -5
WC9 09/01/2011 -4
WC9 10/01/2011 -3
WC9 11/01/2011 -2
WC9 12/01/2011 -1
WC9 01/01/2012 1
WC9 02/01/2012 2
WC9 03/01/2012 3
WC9 04/01/2012 4
WC9 05/01/2012 5
WC9 06/01/2012 6
WC9 07/01/2012 7
WC9 08/01/2012 8
Thanks!
Ariel
*
* 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/