Announcement

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

  • Graph combine with a loop

    Hello,

    I'm trying to combine the graphs that I created with rdplot command in a loop. Namely, this is my command:

    foreach var in province district subdistrict_village abroad sregion12 provinceb districtb subdistrict_villageb abroadb s130d {

    rdplot `var' rv, p(1) ci(95) shade
    graph export cc_`var', replace


    }

    How can I combine all these graphs in one graph?
    Thanks in advance.

  • #2
    Have a look at -graph combine- command.

    Comment


    • #3

      Code:
      local names 
      
      foreach var in province district subdistrict_village abroad sregion12 provinceb districtb subdistrict_villageb abroadb s130d {
      
          rdplot `var' rv, p(1) ci(95) shade, name(`var', replace) 
      
          local names `names' `var' 
          
         graph export cc_`var', replace
      
      
      }
      
      graph combine `names'

      Comment


      • #4
        Hi Nick, thanks for the answer. I tried this command but I get this error message:

        province is not a memory graph
        r(198);

        Why do you think that's the case?

        Comment


        • #5
          Some silly mistakes there on my part. Sorry about that. Try this:

          Code:
          local names  
          
          foreach var in province district subdistrict_village abroad sregion12 provinceb districtb subdistrict_villageb abroadb s130d {      
          
               rdplot `var' rv, p(1) ci(95) shade saving(`var', replace)      
               local names `names' `var'          
               graph export cc_`var', replace  
          }  
          
          graph combine `names'
          Last edited by Nick Cox; 04 Mar 2022, 12:43.

          Comment


          • #6
            Thanks it worked!


            Originally posted by Nick Cox View Post
            Some silly mistakes there on my part. Sorry about that. Try this:

            Code:
            local names
            
            foreach var in province district subdistrict_village abroad sregion12 provinceb districtb subdistrict_villageb abroadb s130d {
            
            rdplot `var' rv, p(1) ci(95) shade saving(`var', replace)
            local names `names' `var'
            graph export cc_`var', replace
            }
            
            graph combine `names'

            Comment

            Working...
            X