Thursday, September 01, 2016

Stata: display system date

Stata: display system date
  • .di "system date:" c(current_date)
  • .di "system date:" "$S_DATE"
  • .di %td_CY-N-D  date("`c(current_date)'","DMY") // "` '" are not necessary
  • .di %td_CY-N-D  date("$S_DATE","DMY")
  • .di "system year: " year(date(c(current_date),"DMY") // w/o `' around c(current_date)
  • .di "system month: " month(date(c(current_date),"DMY"))
  • .di "system day:" day(date(c(current_date),"DMY"))
  • .di "system year: " year(date("$S_DATE","DMY"))
  • .di "system month: " month(date("$S_DATE","DMY"))
  • .di "system day:" day(date("$S_DATE","DMY"))
  •  more examples:
    • Works ('local' with '=')
      • local dd=day(date(c(current_date),"DMY"))
      • local mm=month(date(c(current_date),"DMY"))
      • local yy=year(date(c(current_date),"DMY"))
      • log using "output_`yy'_`mm'_`dd'.log", replace
      • log close
    • Doesn't work ('local' without '=')
      • local dd day(date(c(current_date),"DMY"))
      • local mm=month(date(c(current_date),"DMY"))
      • local yy=year(date(c(current_date),"DMY"))
      • log using "output_`yy'_`mm'_`dd'.log", replace
      • log close // invalid 'DMY' r(198)
    • Works ('global' with '=')
      • global dd=day(date(c(current_date),"DMY"))
      • global mm=month(date(c(current_date),"DMY"))
      • global yy=year(date(c(current_date),"DMY"))
      • log using "output $yy-$mm-$dd.log", replace
      • log close