Announcement

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

  • Issue with stcurve in loop after estimates store/save

    Dear all,

    I am analying a dataset on cancer using Fine and Gray model (stcrreg) and is trying to draw CIF on various cancer types after stcrreg.
    Since it is taking a long time for stcrreg to run, I have been tryig to use estimates store/save on cancer type 1 to 13, then restore the estimates and then draw the curves over loop so I can modify how the graphs look without having to re-run the models. However, I have bumped into the issue of stcurve returning "no obseravtions" error after estimates restore/use. The code I am using are as follows.

    Code:
    foreach cat in  1 2 3 4 5 6 7 8 9 10 11 12 13 { 
        use "/Users/breeshi/Desktop/Cancer/Saved dataset/Analysis SET B_step3 Ready for analysis.dta", clear
        stset bmi_to, failure(cancercat == `cat') id(id) origin(bmi_from) scale(365.25)
        replace failuretype=5 if cancercat~=. & cancercat~=`cat'
        stcrreg i.obese_vary , compete(failuretype==2 3 5)
        local title  `:label (cancercat) `cat''
        estimates store cancercat`cat'
        estimates save `"cancercat`cat'"',replace
        }     
    
    foreach cat in  1 2 3 4 5 6 7 8 9 10 11 12 13 { 
            estimates restore cancercat`cat'
            stcurve, at(obese_vary=(0 1)) cif ytitle("Cumulative Cancer Incidence",size(small)) ///
            graphregion(color(white)) title("`title'",size(med)) legend(off) ///
            xtitle("Years post-transplant",size(small)) lpattern( dash solid) ///
            lcolor(ebblue orange_red) xlabel(, labsize(small)) ylabel(, labsize(small)) saving("SetB_cancercat_`cat'", replace)
          }
    The code gives me the first graph (i.e. cancercat==1) graph alright, but from the 2nd graph, it gives me "no observations
    r(2000);" It is highly inefficient for me and I have been pulling my hair out trying to resolve this.

    Appreciate any help in advance.

    Best Regards,
    Bree

  • #2
    You don't show example data, but I tried doing a simulation of your problem using the StataCorp website hypoxia data set and a simplified version of your code. In doing that, I did not replicate the failure mode you describe. However, I will point out that in order for this to work properly, you must re-stset- your data for each graph so that it designates the appropriate failure types. The following works:
    Code:
    clear*
    webuse hypoxia
    levelsof failtype, local(failure_types)
    foreach i of local failure_types {
        local failtype: list failure_types - i
        stset dftime, failure(failtype == `i')
        stcrreg ifp tumsize pelnode, compete(failtype == `failtype')
        estimates store fail`i'
        stcurve, cif
    }
    
    foreach i of local failure_types {
        local failtype: list failure_types - i
        stset dftime, failure(failtype == `i') // CODE WILL NOT RUN PROPERLY WITHOUT THIS
        estimates restore fail`i'
        stcurve, cif name(fail`i', replace)
    }
    Perhaps if you revise your code modeled on this approach you will have success. If not, when posting back, please show example data, using the -dataex- command.

    If you are running version 18, 17, 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.
    Last edited by Clyde Schechter; Today, 10:51.

    Comment

    Working...
    X