Skip to content

Instantly share code, notes, and snippets.

Last active July 10, 2021 15:07
What would you like to do?
Stata Log File with Date
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