Announcement

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

  • Error with tab2xl

    Hi,

    I am using tab2xl command in Stata 15 and would want to save the excel file using today's date. Below is the code am using

    Code:
    gl date = c(current_date)
    sysuse auto, clear 
    tab2xl foreign using "Output_$date", row(1) col(1)
    Please let me know a possible work around on this.]

    Thanks in advance!

    Stephen.

  • #2
    You don't tell us what your problem is. It is
    Code:
    . tab2xl foreign using "Output_$date" , row(1) col(1)
    invalid 'Mar' 
    r(198);
    which suggests that the tab2xl command (user written, from the Stata blog) does not correctly handle quoted filenames with embedded spaces, since c(current_date) returns (as I write this)
    Code:
    . display c(current_date)
    27 Mar 2019
    The following example shows working code. I changed your global macro $date to a local macro `fdate' because local macros are better practice when a global macro is not specifically needed.
    Code:
    . local fdate = strofreal( daily(c(current_date),"DMY") , "%td" )
    
    . sysuse auto, clear 
    (1978 Automobile Data)
    
    . tab2xl foreign using Output_`fdate', row(1) col(1)
    Note: file will be modified when putexcel close command is issued
    file Output_27mar2019.xlsx saved
    
    .

    Comment


    • #3
      Thanks William Lisowski for the help. This is much appreciated. I am sincerely sorry for not elaborating my problem.

      Comment

      Working...
      X