stata - Check if varlist contains factor variables? -


i trying check if varlist in program contains factor variables. follow recommendation statacorp in page (http://www.stata.com/support/faqs/programming/factor-variable-support/). suggested codes are:

syntax varlist(fv) local fvops = "`s(fvops)'" == "true" | _caller() >= 11 if `fvops' {     // within loop, can expand factor variable list,     // create local version control , perform other     // steps needed factor operated varlists } 

nevertheless, appears me macro s(fvops) not check existence of factor variables in varlist. simple example illustrate:

capture program drop test_fvops program test_fvops syntax varlist(fv) local fvops = "`s(fvops)'" == "true" | _caller() >= 11 qui reg `varlist' if `fvops'  {     di "factor variables specified" } else {     di "factor variables not specified" } end  sysuse auto,clear test_fvops price mpg foreign weight i.rep78 test_fvops price mpg foreign weight rep78 

oddly, last 2 lines of code both return "factor variables specified". program not tell second line has no factor variables.

a further probe on properties of macro s(fvops) makes me more confused.

sysuse auto,clear qui reg price mpg foreign weight i.rep78 local fvops = "`s(fvops)'" != "true" | _caller() >= 11 di "|s(fvops)=`s(fvops)'|fvops=`fvops'|"  qui reg price mpg foreign weight rep78 local fvops = "`s(fvops)'" != "true" | _caller() >= 11 di "|s(fvops)=`s(fvops)'|fvops=`fvops'|" 

in both cases, s(fvops) empty fvops 1. tried return list , sreturn list , did not see s(fvops).

am using fvops code correctly? running stata 13 on win 7.

added: nick's comment clarifies couldn't find in manual. _caller() segment shouldn't have been included, , quote linked page needed understand s(fvops).

"to check if factor variables specified in varlist, may use saved macro s(fvops) syntax, equal “true” when factor variables specified >and empty otherwise."

with own program: working stata 13 , program not set version else.

hence _caller() greater 11 in both cases , test no test.

why not try displaying value of s(fvops)?

with later code, "further probe": why expect s(fvops) visible? never created it, did not use syntax. local macro fvops 1 same reason: _caller() more 11 , | operator selects 1.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -