Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Setting today's date in a do-file


From   "Michael S. Hanson" <mshanson@mac.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Setting today's date in a do-file
Date   Tue, 21 Nov 2006 09:26:22 -0500

On Nov 21, 2006, at 7:36 AM, Patrick Woodburn wrote:

Dear statalist,

So far, when I've wanted a do-file to treat data in a way conditional to
the date the do-file is run, I've put something like the following
towards the beginning of my do-file:

**************macro for today's date: UPDATE when repeat
do-file***************
global today "d(21nov2006)"
*********************************************************************** *
*******

(The stars are a way of emphasising the importance of this line)

I am worried that this is prone to error, if someone forgot to change
the date or made an incorrect guesse at the date. Is there any way to
automatically obtain today's date in Stata, and, perhaps, to incorporate
this into a global macro called today, so that I can make the simplest
modification possible?
I have a series of .do files that write text (ASCII) output to a .log file. Each contains a "report header" based in part on the following code:


local dupwidth = 96 // Character width for separators
local timwidth = `dupwidth' - 11 // Location of timestamp

noi disp _newline(0)
noi disp as text "`=c(current_date)'" as text %`timwidth's "`=c(current_time)'"
noi disp _newline(0)
noi disp as text %~`dupwidth's "Forecast Summary Statistics"
noi disp as text _dup(`dupwidth') "="
noi disp _newline(0)


These commands are all -noisily- as the code is wrapped in a -quietly{ }- block so as to not place intermediate results into the .log file. See -help creturn- for more information on the c-class values such as -c(current_time)-, and -help display- for more information on the text formatting options used above.



I use Stata through a Windows environment, if that makes any difference.
One of the very attractive things about Stata is that it is completely cross-platform, so one is free to use as painful and uncooperative an OS as one chooses.

Hope this helps.

-- Mike

*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/




© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index