Stata Log File with Date
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
capture log close _all // Close any open log files | |
local cur date(c(current_date), "DMY") // Create a Date Object | |
local y = year(`cur') // Grab the year | |
local m = month(`cur') // Grab the month | |
local d = day(`cur') // Grab the day | |
if `m' < 10 { | |
local m = "0`m'" // Add a 0 to single-digit months | |
} | |
if `d' < 10 { | |
local d = "0`d'" // Add a 0 to single-digit days | |
} | |
local filedate = "`y'`m'`d'" // Combine into a single macro | |
local now = subinstr("`c(current_time)'", ":", "", .) | |
local timestamp `filedate'T`now' | |
di "`timestamp'" | |
* Create a log file with the date in the filename | |
log using 01_logs/05_explore_`timestamp'.txt, text replace name(main05) // Replace with file name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment