Announcement

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

  • Disappearing stored values in graphs

    I wonder if somebody could help me understand this curious behaviour:

    Stata/BE 17.0 for Mac (Intel 64-bit)
    Revision 13 Oct 2022

    I work on a condition called Kawasaki disease (KD). KD is treated with an agent (called IVIG), and children can either respond or not respond to that treatment. I have data from a large (N=470) prospective cohort study that I run in Australia. The data relevant to this question are structured as follows:

    Each row is a case of KD.
    txflr_yn: (Treatment Failure, Yes / No), labelled binary variable 0=No, 1=Yes
    path1_crp: (Pre-treatment C-Reactive Protein), %10.0g

    I am trying to make a table of graphs by combining a marginplot and a roctab graph:

    Code:
    use "$masterdir/${filedate}_master.dta", clear
    set scheme cleanplots, perm // This scheme is nice.
    graph set window fontface "Abel" // A thin san-serif typeface. Use Merriweather for Titles
    
    **# CRP
    // ULR of Pre-IVIG CRP (path1_crp) to predict Treatment Failure (txflr_yn)
    logit txflr_yn path1_crp
    
    // Margins Plot
    margins, at(path1_crp=(5 20 50 100 200)) ///
    plot( ytitle("Pr(Treatment Non-Response)") ///
    xtitle("CRP (mg/L)") ///
    title("") ///
    note("N = `e(N)'" "Pseudo R{superscript:2} = `: di %6.3f e(r2_p)'" "p = `: di %12.7f e(p)'"))
    graph save "$figdir/logit_crp.gph", replace
    
    // ROC Plot
    roctab txflr_yn path1_crp, graph ///
    msymbol(point) ///
    note("N = `r(N)'" "AUC = `: di %4.3f r(area)' (95% CI = `: di %4.3f r(lb)' {char 150} `: di %4.3f r(ub)')")
    graph save "$figdir/roc_crp.gph", replace
    The incantation to insert the stored values into the graph has worked many times, however I have observed strange behaviour such that if the graphs are made together (i.e. the above code is run through) then the stored values (usually for the second graph, although not always) do not insert. I end up with a ROC graph in which the note says:

    N =
    95%CI =

    There is a particular quirk whereby I can get the ROC graph to work correctly without a graph name, however as soon as I add a name to the code the stored value insertion fails.
    I can only imagine that for some reason the stored values of the -roctab- are either not being stored or are being overwritten.

    Please let me know if my explanation of the problem is lacking. I will very much appreciate understanding this behaviour.
    Last edited by Ryan Lucas; 16 Nov 2022, 14:43.

  • #2
    The problem is that r class results are ephemeral and may disappear when you run the next r class command, which could be unknowing as some command can run one for you. If you run

    Code:
    return list
    you can check what is visible. Use local macros here.

    Comment


    • #3
      Thanks Nick, that makes sense. I did as you suggested and it worked beautifully!
      Kind regards,
      Ryan

      Comment

      Working...
      X