Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Nick Cox <njcoxstata@gmail.com> |
To | statalist@hsphsun2.harvard.edu |
Subject | Re: st: Need help programming for dates in Stata |
Date | Tue, 5 Mar 2013 19:41:01 +0000 |
I can't see what code you tried. I'm assuming your date variables are Stata daily date variables. If not, let that be so. If I understand you correctly, you need to clone to fill in missings. clonevar startdate2 = startdate replace startdate2 = mdy(12, 31, 2008) if missing(startdate) clonevar stopdate2 = stopdate replace stopdate2 = mdy(12, 31, 2012) if missing(stopdate) Then on a quick and perhaps hasty analysis gen used_2009 = startdate2 <= mdy(12,31,2009) gen used_2010 = (startdate2 <= mdy(12,31,2010)) & (stopdate >= mdy(1,1,2010)) and the definitions for 2011 and 2012 resemble those for 2010. My first instinct was "It's a loop" but with just four years making it general seems unimportant. Code not tested. NB: one criterion; two criteria. Nick On Tue, Mar 5, 2013 at 6:43 PM, Michael Stewart <michaelstewartresearch@gmail.com> wrote: > I have a list of start and stop dates for medications > I am trying to find if there is way to classify them to specifically > say if they are used in particular years > > Med Start date Stopdate > xxx 11/12/2009 11/12/2012 > yyy . 1/2/2010 > zzz 1/1/2009 . > > > I want to create four variables Used_2009 used_2010 used_2011 > used_2012 > > The criteria is > 1)If medication is used even for a day in a year, it is considered to > be used for that year > 2)If the start date is blank, then it is deemed to be used from a much > prior day > 3)If ending date is blank/missing then that medication is currently active * * 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/