Announcement

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

  • error 123 : invalid numlist has too many elements

    Hello all ,

    I am trying to obtain cumulative abnormal returns using stata based on event dates . However when I run the loop foreach am not able to get the desired result because i get the error error 123 : invalide numlist has too many elements .

    The following is my code:

    egen ID = group(permno)

    foreach i of numlist 1 / 2701 {
    quietly regress ret vwretd if ID == `i' & estimation_window == 1
    predict p if ID == `i'
    replace predicted_return = p if ID == `i'
    drop p
    }

    Can you tell me where i went wrong or how i could make this code better ?

    Thanks and Regards,

    Kishore

  • #2
    Use
    Code:
    forvalue i = 1/2701 {

    Comment


    • #3
      This is precisely why forvalues exists:

      Code:
      forval i = 1 / 2701 {
      Rather than laboriously calculating a numlist, forvalues just loops over the range specified.

      Comment


      • #4
        Ok, just to add see

        Code:
        help limits
        where you will find that a numlist can only hold 2,500 values.
        Best
        Daniel
        Last edited by daniel klein; 15 Sep 2017, 05:17.

        Comment


        • #5
          Thanks a lot people - the code works well now - forval it is

          Comment

          Working...
          X