Announcement

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

  • Producing multiple graphs at once

    Hello, everyone. I want to receive the 25 charts in the once. ( 5 row and 5 columns ) . Because it represents the combination at a 5-time horizon, But at the end, it gives me 25 PDFs separately.

    Code:
    clear
    foreach   v in "totalfertility"         {
    forvalues x = 1/5                       {
    forvalues y = 1/5                       {                
    foreach vart in "0" "1" "2" "3" "4" "5" { 
    cd "C:\Users\KHATEREH\Desktop\MyProject/`v'"
    use "C:\Users\KHATEREH\Desktop\charts A\xtscc-correct-dataset.dta"   
    xi: statsby _b _se e(r2_a), clear: xtscc d`vart'`v' l(0/`y')dum_recession l(1/`x')d0`v' i.year,fe
    foreach var in dum_recession {
        gen t_`var' = _b_`var'/_se_`var'
        gen time = "obs`vart'" 
    save `y'`x'`v'`vart'.dta, replace
        }
        }
        }    
        }
        }
    and then :
    Code:
    clear
    foreach v in  "totalfertility"  {
    forvalues x = 1/5               {
    forvalues y = 1/5               {        
    use "C:\Users\KHATEREH\Desktop\MyProject/`v'/`y'`x'`v'0.dta"
    foreach var in  "1" "2" "3" "4" "5" {
    append using  "C:\Users\KHATEREH\Desktop\MyProject/`v'/`y'`x'`v'`var'.dta"
    *drop _merge
    }
    gen date_string = substr(time, 4, 2)
    destring date_string, gen(year)
    
    keep  year  _b_dum_recession _se_dum_recession t_dum_recession 
    order  year  _b_dum_recession _se_dum_recession t_dum_recession 
    gen label="all"
    bysort label (year) : gen first = _n == _N-5
    **expand only the first obs
    expand 2 if first==1
    **** generate the new time variable
    bysort label (year) :gen time2 = _n-2
    ***recode the variables
    replace _b_dum_recession=0 if time2==-1
    replace _se_dum_recession=0 if time2==-1  
    replace t_dum_recession=0 if time2==-1  
    bysort label (year) : gen low = _b_dum_recession-(_se_dum_recession*1.645)
    bysort label (year) : gen high = _b_dum_recession+(_se_dum_recession*1.645)
    gen a=0 
    *a=0 is for charts  
    save "C:\Users\KHATEREH\Desktop\MyProject/`y'`x'`v'all.dta", replace
    }
    }
    }
    and :
    Code:
    cd "C:\Users\KHATEREH\Desktop\MyProject/"
    forvalues x = 1/5               {
    forvalues y = 1/5               {            
    clear
    use "C:\Users\KHATEREH\Desktop\MyProject/`y'`x'totalfertilityall.dta"
    
    twoway rarea high low time2, astyle(ci) || ///
           line _b_dum_recession time2, mstyle(p1)  || ///            
           line a time2, mstyle(p1) lpattern(dash) lwidth(vthin) lcolor(gs0)  ///
           xtitle("Periods after Pandemic Recession") ytitle("level changes totalfertilitry") ylabel(,alternate) xlabel(-1(1)5) title(lag `x'_`var'_lag`y'shock) legend(off)  saving("`var'", replace)
    
    graph export `y'`x'totalfertilitry.pdf, replace 
    }    
    }
    Thank you so much.

    Regards,

  • #2
    See the output of
    Code:
    help graph combine
    for information on displaying multiple graphs in one chart.
    Code:
    cls
    sysuse auto
    scatter price weight, nodraw name(g1)
    scatter price length, nodraw name(g2)
    scatter mpg weight, nodraw name(g3)
    scatter mpg length, nodraw name(g4)
    graph combine g1 g2 g3 g4, rows(2)
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	141.7 KB
ID:	1646280

    Comment


    • #3
      @William Lisowski thank you so much for your reply. My problem is that I try to add it in my loop command but I in any case I did not receive 25 combinations in one PDF file.

      Thank you so much in advance for your valuable time and advice.
      regards,

      Comment


      • #4
        Do you see that in post #4 I created 4 graphs and then ran graph combine one time? If you put graph combine in your loop, I fear you didn't try to understand my example.

        I think these changes to your loop may do what you want. But do spend the time with the documentation to understand how the codes work.
        Code:
        cd "C:\Users\KHATEREH\Desktop\MyProject/"
        graph drop _all
        forvalues x = 1/5               {
        forvalues y = 1/5               {            
        clear
        use "C:\Users\KHATEREH\Desktop\MyProject/`y'`x'totalfertilityall.dta"
        
        twoway rarea high low time2, astyle(ci) || ///
               line _b_dum_recession time2, mstyle(p1)  || ///            
               line a time2, mstyle(p1) lpattern(dash) lwidth(vthin) lcolor(gs0)  ///
               xtitle("Periods after Pandemic Recession") ytitle("level changes totalfertilitry") ylabel(,alternate) xlabel(-1(1)5) title(lag `x'_`var'_lag`y'shock) legend(off)  name(g`x'`y')
        
        * graph export `y'`x'totalfertilitry.pdf, replace 
        }    
        }
        graph combine g11 g12 g13 g14 g15 g21 g22 g23 g24 g25 g31` g32 g33 g34 g35 g41 g42 g43 g44 g45 g51 g52 g53 g54 g55, rows(5) name(5by5)
        graph export totalfertility5by5.pdf, replace name(5by5)

        Comment


        • #5
          William Lisowski thank you so much for your reply.

          Regards,

          Comment

          Working...
          X