Announcement

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

  • Factor variables with 3 or more levels cause r(111) error when using -nestreg- and -qreg-

    As noted in the subject line, when using -qreg- with -nestreg-, inclusion of factor variables with 3 or more levels is causing an r(111) error. I am using Stata/IC 16.1 for Windows. I am curious to know if folks with Stata 17 can duplicate the problem. Thanks.

    Bruce

    Code:
    * Date:  20-Nov-2021
    * File:  qreg_nestreg_problem.do
    * Problem:  When using -nestreg- with -qreg-, factor
    * variables with more then 2 levels cause an error.
    * Example generated using Stata/IC 16.1 for Windows
    
    clear
    sysuse auto
    // Use -regress- with -nestreg-
    nestreg: regress mpg (c.weight) (i.rep78)
    // Replace -regress- with -qreg-
    capture noisily nestreg: qreg mpg (c.weight) (i.rep78), nolog
    display "Error code:  " _rc
    // Let's try again using computed indicator variables
    tabulate rep78, gen(rep)
    nestreg: qreg mpg (c.weight) (rep1-rep4), nolog
    // That works
    // Once more with i. prefix on the indicators
    nestreg: qreg mpg (c.weight) (i.rep1 i.rep2 i.rep3 i.rep4), nolog
    // That also works
    // So factor variables with 2 levels work, but not with 5 levels?
    // How many levels cause problems?  
    
    forvalues i = 3/5 {
      capture noisily nestreg: qreg mpg (c.weight) (i.rep78) if rep78 < `i', nolog
      display "Levels = " `i'-1 "   Error code:  " _rc
      display "---------------------------------------------"
    }
    
    // Looks like it falls apart with 3 or more levels to a factor variable
    // Generate another factor variable with 3 levels to confirm that it is
    // not something peculiar about variable rep78.
    
    generate byte newvar = mod(_n,3)
    fre newvar
    capture noisily nestreg: qreg mpg (c.weight) (i.newvar), nolog
    display "Error code:  " _rc
    // The previous line generates an r(111) error--variable b not found
    // If I use only 2 levels of newvar, everything works!
    nestreg: qreg mpg (c.weight) (i.newvar) if newvar < 2, nolog
    nestreg: qreg mpg (c.weight) (i.newvar) if newvar > 0, nolog
    nestreg: qreg mpg (c.weight) (i.newvar) if newvar != 1, nolog
    --
    Bruce Weaver
    Email: [email protected]
    Version: Stata/MP 19.5 (Windows)

  • #2
    Yes, same behavior with
    Code:
    Stata/MP 17.0 for Windows (64-bit x86-64)
    Revision 17 Nov 2021
    Copyright 1985-2021 StataCorp LLC
    
    Total physical memory:       32.00 GB
    Available physical memory:   18.30 GB
    
    Stata license: Single-user 4-core  perpetual

    Comment


    • #3
      Thanks Clyde.
      --
      Bruce Weaver
      Email: [email protected]
      Version: Stata/MP 19.5 (Windows)

      Comment

      Working...
      X