Announcement

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

  • graph combine does not function...

    Hello dear Stata users, that's my first question here in this forum, so i hope that is the right way to ask such questions: I am trying to combine graphs, but the code doesn't function throughly; i.e., Stata stops after showing the first graph. I have used the same code for other countries and it was successful but not for this country's group! Can anyone tell me, what i'm doing wrong? Here is my code:

    foreach i in "Afghanistan" "Iran, Islamic Rep." "Iraq" "Jordan" "Kuwait" "Lebanon" "Syrian Arab Republic" "Oman"{
    twoway line GDP_log Year if Country =="`i'", xlab(1960(20)2020, labsize(small)) ///
    ylab(,labsize(small)) ///
    title("`i'") ///
    name("`i'", replace) ///
    ytitle("exponential GDP", size(small)) ///
    xtitle("Year", size(small))
    }
    graph combine Afghanistan Iran, Islamic Rep. Iraq Jordan Kuwait Lebanon Syrian Arab Republic Oman, title("Graphic 1: GDP from 1960 to 2020" size(small)) ///
    graph export "./Schema1.tif", width(4000) replace



    thank you in advance.
    Aida

  • #2
    I think you need " " around names containing spaces in graph combine, just as in your loop.

    Comment


    • #3
      It is unclear whether O.P. is referring to the -graph combine- command or to the second iteration of the -foreach- loop here. I believe it is the latter. And it might well explain why OP has previously encountered no problem when using the same code for other countries. The difficulty is that "Iran, Islamic Rep.", the second value of the i iterator, is not a legal graph name. So when it appears in the -name()- option of the -twoway line- command it breaks.

      It is not a legal graph name because it contains embedded punctuation and spaces. I would suggest modifying the code along these lines:

      Code:
      foreach i in "Afghanistan" "Iran, Islamic Rep." "Iraq" "Jordan" "Kuwait" "Lebanon" "Syrian Arab Republic" "Oman"{
          local graph_name = strtoname(`"`i'"')
          twoway line GDP_log Year if Country =="`i'", xlab(1960(20)2020, labsize(small)) ///
          ylab(,labsize(small)) ///
          title("`i'") ///
          name("`graph_name'", replace) ///
          ytitle("exponential GDP", size(small)) ///
          xtitle("Year", size(small))
      }
      This will enable the loop to run to completion and create the named graphs. Nick's point in #2 about how to fix up the -graph combine- command is then also necessary to reach the desired end.

      Comment


      • #4
        Clyde Schechter is I think quite right. His diagnosis explains why only the first graph is shown,

        Comment

        Working...
        X