Announcement

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

  • Problem with graph combine

    Hello, I am trying to combine some graphs. I generate the graphs and save them into a folder.
    When I try to combine them Stata returns error and says the path of the graph is not found. However, this graph file exists.

    This is the code I use to generate the graphs (it works):
    Code:
     *GRAPHS*
     foreach a in e ef {
     foreach b in t1m t3m t6m t1y t2y t3y t5y t7y t10y {
     foreach c in mp1 mp2 mp3 mp4 ff1 ff2 ff3 ff4 ed1 ed2 ed3 ed4 {
      twoway  (line ffr_shock date) (line mp_shock date ) (line  `a'_`b'_`c' date) (line ffr_shadow date, yaxis(2)), title("SHOCK:`a'_`b'_`c'", color(black) size(medium))
      graph save  "\\Cntdat08\grp5$\ses\Generi\GENERAL\INVESTIGACION\2018_MP_flows\data\shock\_`a'_`b'_`c'.gph", replace
     }
     }
     }
    This is the code I am using to combine graphs (returns error, file not found (but i check it exists))
    Code:
     foreach a in e ef {
     foreach b in t1m t3m t6m t1y t2y t3y t5y t7y t10y {
     foreach c in ed mp ff  {
     graph combine "\\Cntdat08\grp5$\ses\Generi\GENERAL\INVESTIGACION\2018_MP_flows\data\shock\_`a'_`b'_`c'1.gph" "\\Cntdat08\grp5$\ses\Generi\GENERAL\INVESTIGACION\2018_MP_flows\data\shock\_`a'_`b'_`c'2.gph" "\\Cntdat08\grp5$\ses\Generi\GENERAL\INVESTIGACION\2018_MP_flows\data\shock\_`a'_`b'_`c'3.gph" "\\Cntdat08\grp5$\ses\Generi\GENERAL\INVESTIGACION\2018_MP_flows\data\shock\_`a'_`b'_`c'4.gph"
     }
     }
     }

  • #2
    Best to use
    Code:
    set trace on
    to see how Stata interprets your code, and check again if the filenames as Stata is trying to find them exist. Otherwise post the output of trace just before the error pops up.

    Comment


    • #3
      You're asking many questions of this form. It is easy to sympathise but hard to provide detailed support for the mundane but crucial reason that we can't tell you anything about your files that you don't know.

      Beyond that,

      1. I see dollar signs in your path names. Stata is predisposed to interpret dollar signs as indicating global macro names to follow. That may not be biting you here, but watch out.

      2. If I were creating files in the folder
      \\Cntdat08\grp5$\ses\Generi\GENERAL\INVESTIGACION\ 2018_MP_flows\data\shock I would cd to that folder first.

      Comment


      • #4
        Originally posted by Jorrit Gosens View Post
        Best to use
        Code:
        set trace on
        to see how Stata interprets your code, and check again if the filenames as Stata is trying to find them exist. Otherwise post the output of trace just before the error pops up.
        Hello, Thank you for your help.

        I tried what you told me and the path is well written. I tried to combine two graphs outside the loop and returns same error.

        Comment


        • #5
          If you can combine two graphs by writing out their complete filepaths manually, but your loop doesn't work, than it suggests that your file naming in your loop isn't being interpreted by Stata in the way you want it.
          If you cannot combine two graphs by writing out their complete filepaths manually, than it suggests you are not writing your filepaths correctly.

          Other than that, Nick's warnings are good tips.

          Comment


          • #6
            I hope no one minds me resurrecting this thread.

            I ran into this same issue recently and I believe it is a bug in Stata. In short, graph combine does not seem to handle UNC paths properly, but graph save does.

            The following code demonstrates the issue:

            Code:
            sysuse nlsw88, clear
            
            * This script runs without any errors if this path is used
            *global graph_directory "C:\temp"
            
            * The final "graph combine" command will fail if this UNC path is used
            global graph_directory "\\server_name\insert\path\here"
            
            global graph_one_filename "$graph_directory\graph_one.gph"
            global graph_two_filename "$graph_directory\graph_two.gph"
            
            graph hbar wage, over(occupation)
            graph save "$graph_one_filename", replace
            
            graph hbar wage, over(married)
            graph save "$graph_two_filename", replace
            
            graph combine ///
                "$graph_one_filename" ///
                "$graph_two_filename", cols(2) rows(1)
            
            * The command above will fail if the UNC path was used, with this error:
            * file \server_name\insert\path\here\graph_one.gph not found
            
            * Note the single "\" before "server_name" in the error message

            I have reported this to Stata Technical Support today.

            Comment

            Working...
            X