Announcement

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

  • Looping graph export: graphs overwritten when using multiple graph options for concord

    I would like to save multiple graphs as a pdf in Stata 17. I am using concord with three graph options: ccc qnormd and loa followed by graph export. Only the graph from the ccc option is exporting with the other graphs being overwritten. Advice would be greatly appreciated on how to uniquely name each of the graph options within the same command.

    Code

    putpdf begin
    putpdf paragraph, font("Times New Roman",12) halign(center)
    putpdf text ("Graphs")

    foreach y in a b c {
    foreach x in d e f {
    concord `y' `x', summary qnormd ccc loa
    graph export "C:\findings and reporting\Graphs\\`y'`x'.png", replace

    putpdf paragraph, halign(center)
    putpdf image "C:\findings and reporting\Graphs\\`y'`x'.png", linebreak width(6)

    }
    }

    putpdf save concord_bland.pdf, replace

    Thank you for your consideration, Sorrel

  • #2
    concord is a community-contributed command from the Stata Journal, as you are asked to explain (FAQ Advice #12). Strictly, the first publication was in the Stata Technical Bulletin; only the first (1998) and latest (2010) public steps are documented here.


    SJ-10-4 st0015_6 . . . . . . . . . . . . . . . . Software update for concord
    (help concord if installed) . . . . . . . T. J. Steichen and N. J. Cox
    Q4/10 SJ 10(4):691
    update explicitly supporting plot() and addplot() and
    allowing systematic control of the reference line


    STB-43 sg84 . . . . . . . . . . . . . . Concordance correlation coefficient
    (help concord if installed) . . . . . . . . T. Steichen and N. J. Cox
    5/98 pp.35--39; STB Reprints Vol 8, pp.137--143
    computes Lin's (1989) concordance correlation coefficient for
    agreement on a continuous measure obtained by two persons or
    methods

    However, the problem reported here is in your own code. concord is willing to draw various graphs but after you've run it as you did only one graph remains in memory and it is that graph and that graph only which you have written code to export. There is no way that your syntax is a translation of your desire to save the other graphs too, if only because you don't refer to them at all and graph export works only on one graph at a time.

    That problem seems soluble in so far as you could write say


    Code:
    concord `y' `x', summary qnormd(name(Q, replace)) ccc(name(C, replace)) loa(name(L, replace))
    and then loop over the named graphs to graph export each one.

    That said, the wider problem attacked is unclear to me. You're producing 9 sets of results for the Cartesian product of variables A B C with variables D E F. It's not clear why all 6 variables aren't being compared with each other and more broadly how far pairwise analyses will get you. In https://www.sciencedirect.com/scienc...69555X05003740 I made the suggestion that the eigenvectors and eigenvalues of a concordance correlation matrix might be useful here, but I have no direct experience to report of such a project. That would be an analogue of principal component analysis.


    Comment


    • #3
      Well noted on reference to concord, my apologies, this community-contributed command is so useful. Use of names worked perfectly. In reference to the wider problem, the variable names were incorrectly specified in my example code - a good lesson in why the FAQ guidance is to paste the exact code. The actual code is:

      foreach y in A B C {
      foreach x in B C D {

      This code results in some repeat comparisons but I could not figure out how to create the foreach loop with the exclusion of these repeat comparisons. Further guidance on this would of course be welcomed!

      Thank you Nick, I appreciate you.

      Comment


      • #4
        Here is some basic technique for looping over distinct pairs.

        Code:
        tokenize "A B C D"
        
        forval i = 1/4 {
            local I = `i' + 1 
            forval j = `I'/4 { 
                local x ``i''
                local y ``j''
                di "`x' `y'" 
            }
        }
        Output showing proof of concept:

        A B
        A C
        A D
        B C
        B D
        C D

        Comment

        Working...
        X