Announcement

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

  • Mac version: -graph export- vs -graph save-, and inclusion of periods in file names

    This is a follow-up to my earlier question about the behaviour of graph export in the Mac version of Stata.

    In an assignment for my intro biostats class, students are expected to export some graphs to png files. I was expecting them to use graph export, like this:

    Code:
    graph export "$myfolder/Figures/A.Birthday_Problem.png", as(png) replace
    But some of them are using graph save instead, like this:

    Code:
    graph save Graph "$myfolder/Figures/A.Birthday_Problem.png", replace
    As noted in the previous thread, I use the Windows version of Stata, but many of my students use the Mac version. In a meeting with one of the Mac users today, I observed that when we used graph export with a file name that included two periods (A.Birthday_Problem.png), Stata treated everything after the first period as a file extension, and execution stopped. When I became aware of that, I advised Mac users to change the first period in the file name to an underscore (A_Birthday_Problem.png), and that seemed to fix things. I concluded that the Mac OS does not allow periods in file names apart from the final period before a file extension.

    But then today, with graph save (and the same file name), everything was fine. So now I suspect some inconsistency between graph export and graph save.

    Can any Mac users duplicate what I have described? Here's a silly little example you can try.

    Code:
    clear *
    sysuse auto
    histogram rep78, discrete
    graph export "auto.rep78.v1.png", replace as(png)
    graph save Graph "auto.rep78.v2.png", replace
    
    erase "auto.rep78.v1.png"
    erase "auto.rep78.v2.png"
    Thanks,
    Bruce

    --
    Bruce Weaver
    Email: [email protected]
    Version: Stata/MP 18.5 (Windows)

  • #2
    First, the inconsistency between graph export and graph save is that they are separate commands with separate purposes. The intent of graph save is is to create a Stata .gph file for later reuse; this is best explained by
    Code:
    help saving_option
    which documents the saving() option to save the graph at the time of creation. If the objective is to produce a png, the students using graph save are not accomplishing that objective.

    Under macOS 10.13.3 with Stata 15.1, your toy example using graph export produces a readable png image, but using graph save produces a much smaller file that is not recognized as a png by Preview.

    Changing the names to auto1.png and auto2.png produces the same results, so this is not a Stata problem with additional periods in the file name.

    Dumping the file created with graph save shows that despite the .png suffix, it is in Stata .gph format. Changing the suffix to .gph and opening it in Stata causes Stata to display the original graph.

    If you specify an inappropriate suffix for a file, Stata will happily create the file replacing the appropriate suffix with the inappropriate suffix.
    Code:
    . sysuse auto, clear
    (1978 Automobile Data)
    
    . save "~/Downloads/foo.bar"
    file ~/Downloads/foo.bar saved
    
    . dir "~/Downloads/foo*"
    
    -rw-r--r--  1 lisowskiw  staff  12207 Mar 19 21:07 /Users/lisowskiw/Downloads/foo.bar

    I concluded that the Mac OS does not allow periods in file names apart from the final period before a file extension.
    That is not the case, as your subsequent experience demonstrated.
    Last edited by William Lisowski; 19 Mar 2018, 19:21.

    Comment


    • #3
      Thank you, William. I should have spotted that graph save is saving a gph file.

      Just to be crystal clear, were you able to execute the graph export command in my toy example successfully?

      Code:
      graph export "auto.rep78.v1.png", replace as(png)
      As I noted, the multiple periods in the file name seemed to be causing problems for my students who have the Mac version. (If I had access to Stata on a Mac, I would test this myself. Sorry for being a nuisance!)

      Cheers,
      Bruce
      --
      Bruce Weaver
      Email: [email protected]
      Version: Stata/MP 18.5 (Windows)

      Comment


      • #4
        The paragraphs in post #2 starting at "Under macOS 10.13.3 with Stata 15.1" document my experience with your toy example. So yes, graph export with the extra periods worked successfully.

        Do note that your toy example includes the as(png) option; removing that produces the following result:
        Code:
        . graph export "~/Downloads/auto.rep78.v1.png", replace
        output-file suffix "rep78.v1.png" not recognized
            specify correct suffix or specify as() option
        r(198);
        This was an error message generated by Stata, not by macOS: in this context, at least, Stata searched for the first period rather than the final period as would be appropriate for an operating system that, unlike what I recall of Windows, allows periods within file names (no operating system allows periods within extensions).

        As a Mac user, tomorrow I will call the attention of Stata Technical Services to this issue.
        Last edited by William Lisowski; 19 Mar 2018, 20:25.

        Comment


        • #5
          Thanks William. I'll advise my Mac-using students that they must include as(png) as an option.

          Cheers,
          Bruce
          --
          Bruce Weaver
          Email: [email protected]
          Version: Stata/MP 18.5 (Windows)

          Comment

          Working...
          X