Announcement

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

  • Graph Loop Skip "no observations" error without saving graph

    Dear All,

    I'm using the following code to generate graphs with a loop, for some variables there are no observations, the code skipped the "no observations" error and continue to run, but for variables with no observations, the graphs are still generated and saved (the content of the graph is the previous graph with no error). For example, if b has no observation, then graph with name "b" will still be saved, and when open the graph, the content of the graph is the same as graph a.

    Code:
    foreach var of varlist a-z{
                    capture noisily ///
                    catplot `var', title(`var')
                    graph save `var', replace
                    }

    I'm wondering if there is a way to ignore the error but not save the graph?

    Any help will be appreciated.

    Thank you very much!

    Best,
    Craig

  • #2
    Add after catplot call
    Code:
    qui count if !(missing(`var'))
    if(`r(N)'>0){
        graph save `var', replace
    }

    Comment


    • #3
      Hi Mike,

      Thank you very much for your help, it worked perfectly!

      Best,
      Craig

      Comment

      Working...
      X