Announcement

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

  • Problem with capture confirm and graph combine








    Hello. I have problems combining two graphs in a loop . I do not have all of the combination of the loop. For example, I have asset_t3m_ed1_qe.gph and asset_t3m_ed1_nqe.gph but not asset_t6m_ed1_qe.gph and asset_t6m_ed1_nqe.gph. I always have the qe and qe version of each combination. I want to combine the graphs qe and nqe. I try to use capture confirm but it does not work. It returns error (NOT FOUND).

    Do you know how can I do that?

    Code:
    foreach pi in  t3m t6m t1y t2y t3y t5y t7y t10y { 
    foreach iv in ed1 ed2 ed3 ed4 ff1 ff2 ff3 ff4 mp1 mp2 mp3 mp4 {
    capture confirm existence "RESULTS/graphs_04/asset_`pi'_`iv'_`s'".gph
    if _rc == 0 {
    graph combine "$RESULTS/graphs_04/asset_`pi'_`iv'_qe.gph" "$RESULTS/graphs_04/asset_`pi'_`iv'_nqe.gph"
    graph save "$RESULTS/graphs_04/combined/asset_`pi'_`iv'.gph", replace
    }
    }
    }

  • #2
    Make sure that you place the " after .gph, not before.

    Comment


    • #3
      Originally posted by Nick Cox View Post
      Make sure that you place the " after .gph, not before.
      Yes, I realized of that but I tried having changed it and it also returns error. I also tried writting capture confirm file instead of capture confirm existence, and it does not work.

      Comment


      • #4
        I think you need confirm file

        Comment


        • #5
          Originally posted by Nick Cox View Post
          I think you need confirm file
          Yes, I also thought that and I tried it but still does not work.

          Code:
          foreach pi in  t3m t6m t1y t2y t3y t5y t7y t10y {
          foreach iv in ed1 ed2 ed3 ed4 ff1 ff2 ff3 ff4 mp1 mp2 mp3 mp4 {
          capture confirm file "$RESULTS/graphs_04/asset_`pi'_`iv'_`s'.gph"
          if _rc == 0 {
          graph combine "$RESULTS/graphs_04/asset_`pi'_`iv'_qe.gph" "$RESULTS/graphs_04/asset_`pi'_`iv'_nqe.gph"
          graph save "$RESULTS/graphs_04/combined/asset_`pi'_`iv'.gph", replace
          }
          }
          }

          Comment


          • #6
            Shouldnt this be:
            Code:
            foreach pi in  t3m t6m t1y t2y t3y t5y t7y t10y {
            foreach iv in ed1 ed2 ed3 ed4 ff1 ff2 ff3 ff4 mp1 mp2 mp3 mp4 {
            capture confirm file "$RESULTS/graphs_04/asset_`pi'_`iv'_qe.gph" "$RESULTS/graphs_04/asset_`pi'_`iv'_nqe.gph"
            if _rc == 0 {
            graph combine "$RESULTS/graphs_04/asset_`pi'_`iv'_qe.gph" "$RESULTS/graphs_04/asset_`pi'_`iv'_nqe.gph"
            graph save "$RESULTS/graphs_04/combined/asset_`pi'_`iv'.gph", replace
            }
            }
            }
            That is, check existence of graphs to combine before combining them?
            Right now you are checking the existence of some files, then attempting to graph some others.

            Comment


            • #7
              Originally posted by Jorrit Gosens View Post
              Shouldnt this be:
              Code:
              foreach pi in t3m t6m t1y t2y t3y t5y t7y t10y {
              foreach iv in ed1 ed2 ed3 ed4 ff1 ff2 ff3 ff4 mp1 mp2 mp3 mp4 {
              capture confirm file "$RESULTS/graphs_04/asset_`pi'_`iv'_qe.gph" "$RESULTS/graphs_04/asset_`pi'_`iv'_nqe.gph"
              if _rc == 0 {
              graph combine "$RESULTS/graphs_04/asset_`pi'_`iv'_qe.gph" "$RESULTS/graphs_04/asset_`pi'_`iv'_nqe.gph"
              graph save "$RESULTS/graphs_04/combined/asset_`pi'_`iv'.gph", replace
              }
              }
              }
              That is, check existence of graphs to combine before combining them?
              Right now you are checking the existence of some files, then attempting to graph some others.
              Hello. Thank you for your answer.

              I tried your code, and stata returns nothing. I checked if filenames are well written and they are.
              Anyone has idea of what is wrong?

              Comment


              • #8
                Appears capture confirm will take only one file, or maybe multiple files are possible but I cannot find clear info on how to do this. Comma between files didnt fix it.
                You can make another capture confirm loop though.
                Here it is as a self-contained example.

                Code:
                *some data
                clear
                set obs 100
                foreach v in vix  {
                    foreach s in qe nqe{
                        foreach pi in t3m t6m {
                            foreach iv in ed1 ed2 {
                            gen min_`v'_`pi'_`iv'_`s'_68 = runiform()
                            gen max_`v'_`pi'_`iv'_`s'_68 = runiform()
                            gen min_`v'_`pi'_`iv'_`s'_90 = runiform()
                            gen max_`v'_`pi'_`iv'_`s'_90 = runiform()
                            gen b_`v'_`pi'_`iv'_`s'_90 = runiform()
                            }
                        }
                    }
                }
                gen horizon = runiform()
                
                global RESULTS "C:\Users\jorrit\test"
                
                foreach v in vix  {
                    foreach s in qe nqe{
                        foreach pi in t3m t6m t1y t2y t3y t5y t7y t10y {
                            foreach iv in ed1 ed2 ed3 ed4 ff1 ff2 ff3 ff4 mp1 mp2 mp3 mp4 pc1 {
                            capture confirm variable min_`v'_`pi'_`iv'_`s'_68  max_`v'_`pi'_`iv'_`s'_68 min_`v'_`pi'_`iv'_`s'_90  max_`v'_`pi'_`iv'_`s'_90 b_`v'_`pi'_`iv'_`s'_90
                            if _rc == 0 {
                                scatter min_`v'_`pi'_`iv'_`s'_68  max_`v'_`pi'_`iv'_`s'_68 min_`v'_`pi'_`iv'_`s'_90  max_`v'_`pi'_`iv'_`s'_90 b_`v'_`pi'_`iv'_`s'_90
                                qui: twoway (rarea min_`v'_`pi'_`iv'_`s'_68  max_`v'_`pi'_`iv'_`s'_68 horizon , pstyle(ci)) ///
                                  (line max_`v'_`pi'_`iv'_`s'_90  horizon, lcolor(black) lpattern(dash) lstyle(ci) ) ///
                                  (line min_`v'_`pi'_`iv'_`s'_90  horizon, lcolor(black) lpattern(dash) lstyle(ci)  ) ///
                                  (line b_`v'_`pi'_`iv'_`s'_90 horizon, lcolor(red) lpattern(solid)),  ///
                                title("`v'", color(black) size(medium)) ///
                                    ytitle("Percent", size(medsmall)) xtitle("Horizon", size(medsmall)) ///
                                    graphregion(color(white)) plotregion(color(white)) ///
                                    legend(off) ///
                                    note("Shaded area IC 90% and dashed line IC 68%") ///
                                title("Business Income (`pi',`iv',`s')")
                                graph save  "$RESULTS/graphs_04/asset_`pi'_`iv'_`s'.gph", replace
                                }
                            }
                        }
                    }
                }
                
                foreach pi in  t3m t6m t1y t2y t3y t5y t7y t10y {
                    foreach iv in ed1 ed2 ed3 ed4 ff1 ff2 ff3 ff4 mp1 mp2 mp3 mp4 {
                       capture confirm file "$RESULTS/graphs_04/asset_`pi'_`iv'_qe.gph"
                            if _rc == 0 {
                            capture confirm file "$RESULTS/graphs_04/asset_`pi'_`iv'_nqe.gph"
                                if _rc == 0 {
                                        graph combine "$RESULTS/graphs_04/asset_`pi'_`iv'_qe.gph" "$RESULTS/graphs_04/asset_`pi'_`iv'_nqe.gph"
                                        graph save "$RESULTS/graphs_04/combined/asset_`pi'_`iv'.gph", replace
                                        }
                            }
                    }
                }

                Comment

                Working...
                X