Hello!
I ran into a problem after modifying a .do file from a previous analysis.
When using the restore command after earler using preserve I get an error "nothing to restore".
Stata version 18. I am using the ssc command diagt but that was working fine before modifications.
Sorry that the code is not executable due to many locals - I was hoping that anyone could spot the issue right away.
If that is difficult I will try to provide executable code.
Here how the code looked in the beginning and everything works fine:
and after modifications the restore command does not work anymore:
Thanks for any suggestions and support!!
I ran into a problem after modifying a .do file from a previous analysis.
When using the restore command after earler using preserve I get an error "nothing to restore".
Stata version 18. I am using the ssc command diagt but that was working fine before modifications.
Sorry that the code is not executable due to many locals - I was hoping that anyone could spot the issue right away.
If that is difficult I will try to provide executable code.
Here how the code looked in the beginning and everything works fine:
Code:
preserve keep if any_lesion == 1 & dp_study == 0 local description All_Lesions_Pilot local counter = 2 foreach var in `varlist_detect' { local description "`description' `var' " diagt dp_RS_lesion_detect `var' replace description = "`var'" in `counter' replace sensitivity = `r(sens)' in `counter' replace sens_lb = `r(sens_lb)' in `counter' replace sens_ub = `r(sens_ub)' in `counter' replace PPV = `r(ppv)' in `counter' replace PPV_lb = `r(ppv_lb)' in `counter' replace PPV_ub = `r(ppv_ub)' in `counter' *McNemars mcc tc_dp_m_as_df_lesion_detect tc_`var' replace p_value = `r(p_exact)' in `counter' local ++counter } * Store to matrix to prevent deløetion by "restore" mkmat `varlist_sensitivity', matrix(pilot_all) local n = _N levelsof RS_patient local p_n = `r(r)' restore * Matrix to variables after restore local counter = 1 local counter_store = (`counter'+1) foreach i in `description' { replace description = "`i'" in `counter' local ++counter } forvalues i = 2/7 { replace sensitivity = pilot_all[`i',1] in `counter_store' replace sens_lb = pilot_all[`i',2] in `counter_store' replace sens_ub = pilot_all[`i',3] in `counter_store' replace PPV = pilot_all[`i',4] in `counter_store' replace PPV_lb = pilot_all[`i',5] in `counter_store' replace PPV_ub = pilot_all[`i',6] in `counter_store' replace lesions_n = `n' in `counter_store' replace patients_n = `p_n' in `counter_store' replace p_value = pilot_all[`i',7] in `counter_store' local ++counter_store }
Code:
preserve keep if RS_lesion_detect != . & dp_study == 0 local description "`reader': All Lesions Pilot" local counter = 2 set trace on foreach reader in `reader' { unab varlist_sensitivity: `reader'_sens* `reader'_PPV* `reader'_p_value foreach var in ``reader'_varlist_detect' { local description "`description' `var' " diagt binary_RS_lesion_detect `var' replace `reader'_description = "`var'" in `counter' replace `reader'_sensitivity = `r(sens)' in `counter' replace `reader'_sens_lb = `r(sens_lb)' in `counter' replace `reader'_sens_ub = `r(sens_ub)' in `counter' replace `reader'_PPV = `r(ppv)' in `counter' replace `reader'_PPV_lb = `r(ppv_lb)' in `counter' replace `reader'_PPV_ub = `r(ppv_ub)' in `counter' *McNemars local mcc_var = subinstr("`var'", "m_","",.) local mcc_var = subinstr("`mcc_var'", "binary_","",.) mcc tc_`reader'_as_df_lesion_detect tc_`mcc_var' replace `reader'_p_value = `r(p_exact)' in `counter' local ++counter } * Store to matrix to prevent deletion by "restore" mkmat `varlist_sensitivity', matrix(pilot_all) local n = _N levelsof RS_patient local p_n = `r(r)' restore * Matrix to variables after restore local counter = 1 local counter_store = (`counter'+1) foreach i in `description' { replace `reader'_description = "`i'" in `counter' local ++counter } forvalues i = 2/7 { replace `reader'_sensitivity = pilot_all[`i',1] in `counter_store' replace `reader'_sens_lb = pilot_all[`i',2] in `counter_store' replace `reader'_sens_ub = pilot_all[`i',3] in `counter_store' replace `reader'_PPV = pilot_all[`i',4] in `counter_store' replace `reader'_PPV_lb = pilot_all[`i',5] in `counter_store' replace `reader'_PPV_ub = pilot_all[`i',6] in `counter_store' replace `reader'_lesions_n = `n' in `counter_store' replace `reader'_patients_n = `p_n' in `counter_store' replace `reader'_p_value = pilot_all[`i',7] in `counter_store' local ++counter_store } }
Comment