Announcement

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

  • error 122: invalid numlist has too few elements

    Hello all,

    I am trying to create a graph for Quantile Regression for Panel Data. However, when I run the loop for each am not able to get the desired result because I get the error 122: invalid numlist has too few elements.

    The following is my code:

    local quantiles 5 10 25 50 75 90 95
    local models ""
    local xlabel ""
    local j=1

    foreach q of numlist `quantiles' {
    qregpd yield_ndvi avg8_ndvi avg8_cired avg8_msavi avg8_ndre, id(fid_ndvi) fix(year_ndvi) quantile(`q')
    nlcom (me_tu:_b[avg8_ndvi]+_b[avg8_cired]+_b[avg8_msavi]+_b[avg8_ndre]), post
    estimates store me_tu`q'
    local models `"`models' me_tu`q' || "'
    local xlabel `"`xlabel' `j++' "Q{sub:`q'}""'
    }


    I would much appreciate it if someone could correct my code.

    Best regards,
    Last edited by Zara Ruzim; 14 May 2021, 10:27.

  • #2
    Did you run the entire block of code/do-file at once, or in segments? Local macros are just that, local to context. When you run a block of code from the do file, the locals cease to exist exactly when the code execution is completed. So if you run the block that contains the definitions of the locals as one block, then later run the loop as another block, the reference to those local macros are undefined (and are replace with nothing, rather than the contents you expected).

    Comment


    • #3
      Thank you for your reply. I selected whole my code then run it at the same time from the do file.

      Comment


      • #4
        The first test is to tell us what happens when you do this


        Code:
        local quantiles 5 10 25 50 75 90 95
        
        
        foreach q of numlist `quantiles' {
            di `q' 
        }

        Comment


        • #5
          Dear Nick Cox,

          Thank you for your reply. I run this code here what I got error:

          invalid numlist has too few elements

          Comment


          • #6
            So, something is wrong your end, such as using a slightly different macro names -- check especially for letter i and numeral 1. You should copy and paste the exact commands you used as the assertion that you're using the same code appears incorrect.

            Again, as Leonardo Guizzetti explained the definition of the local and its use must be in the same code chunk.

            Comment

            Working...
            X