Hi. I am trying to graph across two variables using a nested loop. My first variable refers to disease cases, the second to a medical stage. I am trying to graph the number of medical stages over time for each disease case. So for each disease in the local diseases_needed, I want to create a histogram for each stage by counting the variable "year". However, the code below appears to not work. It creates graphs with filenames "graphs_0", "graphs_1", etc for only HIV. Instead of having 20 graphs (5 stages x 4 diseases) I only have 5 graphs. Any help in identifying what wrong here will be much appreciated. thank you.

Code:
decode Stage, gen(Stage_str)
local stages 0 1 2 3 4

#delimit ;
local diseases_needed
    Asthma
    "Pain, nociceptive, general"
    "HIV"
    "Cancer"
    
;
#delimit cr

foreach disease of local diseases_needed {
    foreach stage of local stages {
        
        local graph_title = "Number of " + Stage_str + " Events over time (" + Disease + ")"
        histogram year if Disease=="`disease'" & Stage==`stage',  width(1) ///
            frequency color("${orange}") ylabel(#10, angle(0)) xtitle("Year") ///
            title("`graph_title'")
    graph export "${dodir}\graphs\`disease'_`stage'.pdf", as(pdf) replace
    }
    }