Announcement

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

  • All saved graphs are .gph despite specifying different extension with saving()

    Hi,

    I am trying to generate and save a series of dotplots using a loop. The relevant lines are:

    local intint AgeAtHAART YearsOfVL_FU_afterSuccess400 YearsSpentUndetectable PeakVLBefARVs BaselineCD4 MaxCD4At2y PercentCD4Change AbsIncrease2y RDWatHAART WBCatHAART HgbAtHAART MCVatHAART PLTatHAART SCrAtHAART eGFRHAART SCrAtImmuneFail eGFRImmuneFail AZTd4T_PeriodsDuringObs AZTd4Ttime FolInh_PeriodsDuringObs FolateInhTime ACEI_PeriodsDuringObs ACEItime ARB_PeriodsDuringObs ARBtime RTVperiodsDuringObs RTVtime

    foreach x of var `intint' {
    dotplot `x' if RDWatHAART >0, over(CD4Above350At2y) median bar center msymbol(o) saving(`x'.jpg, replace)
    }

    All the expected graphs are generated and saved, with .jpg extensions, but when I try to use them in other applications (e.g., insert them into a PowerPoint slide), they are unreadable. If I manually change the extension to .gph, sure enough, Stata opens them without complaint. Adding the asif option also doesn't change the behavior.

    Any ideas?

  • #2
    You need to use the -graph export- command to save a graph in format other than gph.

    Comment


    • #3
      Can -graph export- be used in a loop, as in the original posting? If so, could you suggest the relevant syntax? I am trying to avoid having to save each graph individually, as I have a large number of variables I need plotted. Thank you very much for your help!

      Comment


      • #4
        Did you find something in the documentation that made you think that -graph export- can't be used in a loop? Or, did you try it and have it not work? Nothing terrible will happen if you try something and it doesn't work. That's in fact a good way to learn something.

        Reading the documentation for -graph export- would show, by the way, that jpg is not a supported output format. I often use png, so you could try something like:

        Code:
        foreach x of etc ... {
           dotplot etc....   without saving
           graph export "`x'.png"
        }

        Comment


        • #5
          I tried .PNG first. I didn't try what you suggest, only b/c it didn't occur to me that I could just nest the second command after issuing the -graph- command. As I read the -graph- ecport- documentation, it seemed as though it would only export the last graph in memory. I'm on myobile now, will try your suggestion when I get back to computer and report back. Thank you again for your help.

          Comment


          • #6
            Because there is a loop, the last graph in memory is currently changing. So, each call to -graph export- will export a different graph.

            Comment


            • #7
              Worked exactly as intended! Thank you so very much. As I said, I hadn't tried it simply because I did not recognize it as a possibility. I learned something new from this, and I do appreciate it.

              Comment

              Working...
              X