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: RE: STATA date question


From   Kieran McCaul <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: RE: STATA date question
Date   Thu, 30 Jan 2014 03:43:08 +0800

...

See below.

thursday1 is the nearest Thursday to enddate
thursday2 is the first Thursday after enddate





clear *

set obs 14

gen enddate =  date(c(current_date), "DMY") + _n
gen dow_enddate = dow(enddate)

* Date of nearest Thursday
gen thursday1 = enddate + (4 - dow_enddate)
gen dow_thursday1 = dow(enddate + (4 - dow_enddate))

* Date of next Thursday
gen thursday2 = (enddate + mod(4 - dow_enddate,7))
gen dow_thursday2 = dow((enddate + mod(4 - dow_enddate,7)))
format enddate thursday1 thursday2 %td

run "C:\ado\personal\Weekdaysfmt.do"
label values dow_* Weekdaysfmt

gen days_to_thursday = 4 - dow_enddate

list , abb(20) sepby(thursday1)


     +----------------------------------------------------------------------------------------------------+
     |   enddate   dow_enddate   thursday1   dow_thursday1   thursday2   dow_thursday2   days_to_thursday |
     |----------------------------------------------------------------------------------------------------|
  1. | 31jan2014        Friday   30jan2014        Thursday   06feb2014        Thursday                 -1 |
  2. | 01feb2014      Saturday   30jan2014        Thursday   06feb2014        Thursday                 -2 |
     |----------------------------------------------------------------------------------------------------|
  3. | 02feb2014        Sunday   06feb2014        Thursday   06feb2014        Thursday                  4 |
  4. | 03feb2014        Monday   06feb2014        Thursday   06feb2014        Thursday                  3 |
  5. | 04feb2014       Tuesday   06feb2014        Thursday   06feb2014        Thursday                  2 |
  6. | 05feb2014     Wednesday   06feb2014        Thursday   06feb2014        Thursday                  1 |
  7. | 06feb2014      Thursday   06feb2014        Thursday   06feb2014        Thursday                  0 |
  8. | 07feb2014        Friday   06feb2014        Thursday   13feb2014        Thursday                 -1 |
  9. | 08feb2014      Saturday   06feb2014        Thursday   13feb2014        Thursday                 -2 |
     |----------------------------------------------------------------------------------------------------|
 10. | 09feb2014        Sunday   13feb2014        Thursday   13feb2014        Thursday                  4 |
 11. | 10feb2014        Monday   13feb2014        Thursday   13feb2014        Thursday                  3 |
 12. | 11feb2014       Tuesday   13feb2014        Thursday   13feb2014        Thursday                  2 |
 13. | 12feb2014     Wednesday   13feb2014        Thursday   13feb2014        Thursday                  1 |
 14. | 13feb2014      Thursday   13feb2014        Thursday   13feb2014        Thursday                  0 |
     +----------------------------------------------------------------------------------------------------+


-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Ed Levitas
Sent: Wednesday, 29 January 2014 10:13 PM
To: [email protected]
Subject: st: STATA date question

Hi Statalisters,

I'm trying to output dates  that occur on the Thursday after 18 months have passed since a beginning date. For example, assume my beginning date is January 1, 2014.  The Thursday after 18 months have passed from this date is July 2, 2015.  In this case, I am not concerned with how many days are in each month (e.g., I don't care that January 2014 has 31 days and February 2014 has only 28).  I treat month duration as equivalent regardless of days within each month.    I have examined datetime  but am still unsure as to how to accomplish this in STATA.  Can you please suggest a way in STATA to produce this output?

Thanks in advance for your time and consideration, Ed

****************************************
Edward Levitas, PhD
Associate Professor
Sheldon B. Lubar School of Business
University of Wisconsin-Milwaukee
3202 N. Maryland Ave.
Milwaukee, WI  53211
ph: (414) 229-6825
fx: (414) 229-6957
http://www4.uwm.edu/business/faculty/busfaculty/levitas.cfm




*
*   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/

*
*   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