Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Extract date from Excel as input in global macro

    Hi,

    I would like to extract a date from Excel in MM/DD/YYYY format which is located in cell B2, convert it in a Stata monthly date "YYYYmMM" and put in as input in a global macro variable in Stata as monthly date, month and year:
    global mdate ...
    global month ...
    global year ...

    Anyone can help? Thanks a lot in advance.

    Attached Files

  • #2
    Code:
    . import excel dates using "~/Desktop/example.xlsx", cellrange(B1:B2)
    (1 var, 2 obs)
    
    . global mdate = mofd(dates[2])
    
    . global month = month(dates[2])
    
    . global year  = year(dates[2])
    
    . display "unformatted mdate " $mdate " formatted "%tm $mdate " month "$month " year " $year
    unformatted mdate 723 formatted  2020m4 month 4 year 2020

    Comment


    • #3
      Thanks a lot William

      Comment

      Working...
      X