Announcement

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

  • a local macro with double quotes at begin at end of a string

    When a use a local and I need a start and end double quote should be included the options i use aren't functioning.

    1. char(34)
    2. compound quotes

    I want to use a local to generate automatic filenames. Date time and a name including a pathname.

    the local should give this: "C:/map/map/stata/graph/filename.extension", file name is datatime in a string

    goal is that automatic file naming is done with:

    graph export "C:/map/map/stata/graph/datetime_graph.tif", as(tif) replace

    i have made a datetimelocal and a path local but the command requires the start and end with a double quote.

  • #2
    If your filepath doesn't include spaces, you don't need " " in the macro. How are you expressing date times?

    Comment


    • #3
      local c_time_date = ""$S_DATE"+"_" + "$S_TIME"";
      local c_time_date= subinstr("`c_time_date'", ":", "_", .);
      local c_time_date = subinstr("`time_string'", " ", "_", .);
      local file_1 "C:\map\map\stata\graph";
      local file_2 "`file_1'""`time_string'"".tif";
      graph export `file_2', as(tif) replace;

      Comment


      • #4
        I can't see a definition here for local macro time_string

        It's simpler than you fear, but never use backslashes:


        Code:
         
        local td = "$S_DATE"+ "_" + "$S_TIME"
        local td = subinstr("`td'", ":", "_", .)
        local td = subinstr("`td'", " ", "_", .)
        local file C:/map/map/stata/graph/`td'.tif
        di "`file'"
        One I did just now was

        C:/map/map/stata/graph/29_Jan_2015_16_30_18.tif

        See
        http://www.stata-journal.com/sjpdf.html?articlenum=pr0042 on why not backslashes.

        Comment


        • #5
          thanks,

          the idea was that I wanted to extract the do.file name to a local, use that name for name convention as name for the graph by concatenate that name with the datetime_string so that it is easy to see in the folder which do file created the graph.

          Comment

          Working...
          X