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]

st: Create Timeline based on Dates


From   Lisa Wang <[email protected]>
To   [email protected]
Subject   st: Create Timeline based on Dates
Date   Fri, 26 Oct 2012 11:02:42 +1100

Hi all,

I would like to create a timeline based on some event date (ie. ...-5,
-4, -3, -2, -1, 0, +1, +2, +3...etc). I have different students names
in a variable named "as" (column 1)  and also a set of dates (column
2) as well as another variable 'edate' (column 3) which has the event
dates and . everywhere else if it didn't match with column 2. What I
would like to know is how to create the timeline with the event date
being 0 for each student.

This is the code I have run so far:

- bysort as: generate rank =_n

. bysort as: generate erank = rank if date==edate

. bysort as: egen erank_pop = min(erank)

. bysort as: generate t = rank -erank_pop -

There are three problems which have me now stuck.

1. I might have multiple observations for a particular student on the
same date as well. Therefore, when I run the first line of code, it's
already erroneous as Stata will treat it as being different dates. I
tried also -bysort as(date): generate rank =_n - instead but it
returns an error: "factor variables and time-series operators not
allowed".

2. Sometimes I have multiple event dates for a particular student - I
would like Stata to guess which event date the date is closer to and
then do the time differences from that.

3. The dates in column 2 have all weekdays but no weekends (as the
students don't need to go to school on those days), so if I do a
timeline then it will skip some dates (eg. -5 then to -2,-1 etc. as a
result of the weekend). How would I overcome this, so that it actually
is -3,-2,-1 etc?


Thank you so much. My email is a bit long but just wanted everyone to
understand what I wanted to achieve.

Kind regards,
Lisa
*
*   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