Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Extracting a string from c(current_time)


From   John-Paul Ferguson <[email protected]>
To   [email protected]
Subject   st: Extracting a string from c(current_time)
Date   Thu, 24 Mar 2005 23:59:15 -0500

Hello,

I am trying to write a program (here called -autolog-), for use in a do-file,
that creates a unique, time-stamped log whenever the program is run. For
example, running the do-file that contains autolog at 11:45.22 on the 24th of
March would produce 24Mar2005_114522.log, or something similar. My first
attempt is below:

program autolog
     local time c(current_time)
     local logtime: subinstr local time ":" "", all
     local date c(current_date)
     local logdate: subinstr local date " " "", all
     local timestamp `logdate'_`logtime'
     log using `timestamp'.log, replace
end

The idea is straightforward. Since I work part-time in Windows, which will not
accept colons in file names, I wanted to strip the colons out of the current
time (and, less critically, the spaces out of the current date).

However, Stata seems to parse the current_time value as a single token no matter
what, and thus doesn't "see" the colons within it. (A smart idea, under other
circumstances!) It similarly ignores the spaces in current_date.

My question therefore is this: how can I retrieve the current date or time and
hold it as a genuine string, such that I can manipulate it? The answer is
probably basic, but I haven't been able to find anything obvious in the user's
guide or online (I don't have _Programming Stata_, alas).

Thanks for your help,

John-Paul Ferguson
PhD Student
Institute for Work and Employment Research
Sloan School of Management
Massachusetts Institute of Technology
*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index