Hi everyone,
Has anyone experienced errors with levelsof not present with levels commands? This curious case occurs with the following effort to find the value for _n at which rho is maximized or MAE is minimized under specific conditions. The `variables' list has "ihap irlx isad" and `panelrange' is "1/3". The following levels command works:


if "`Ecriterion'"=="rho" | "`Ecriterion'"=="mae" {
qui gen long obsno=_n
foreach var of varlist `variables' {
foreach id of numlist `panelrange' {
capture noisily {
quietly summarize SP_`Ecriterion'_`var'_ID if SP_id_`var'_ID==`id' & SP_d_`var'_ID==`diff', meanonly
if "`Ecriterion'"=="rho" loc a="max"
else if "`Ecriterion'"=="mae" loc a="min"
levels obsno if SP_`Ecriterion'_`var'_ID == r(`a') & SP_id_`var'_ID==`id' & SP_d_`var'_ID==`diff'
loc emax`var'`id'=SP_e_`var'_ID[`r(levels)']
}
}
}
}

The code is not perfect and could use a clean, but it works just fine. I have confirmed this by checking the contents of the `emax`var'`id'' macros. However, curiously, if the "levels" command is replaced with "levelsof", then the following errors result:

SP_e_ihap_ID not found
SP_e_ihap_ID not found
SP_e_ihap_ID not found
SP_e_irlx_ID not found
SP_e_irlx_ID not found
SP_e_irlx_ID not found
SP_e_isad_ID not found
SP_e_isad_ID not found
SP_e_isad_ID not found


This is very strange, I think, because the two commands are often interchangeable (and meant to be so)? If anyone has experienced anything similar or can diagnose the problem, please let me know! The gtools version of levelsof also produces the same errors.

Thanks for any input and time you can offer!
Mike