Announcement

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

  • "macro length exceeded"

    Code:
    . quietly : levelsof stockidentifier , local(stocknames) macro length exceeded
    Any idea how to resolve the problem?

  • #2
    There was an error code that you didn't include in your post, perhaps with a link to
    Code:
    help limits
    It would be easier to propose solutions if you told us more about what you are trying to do.

    Comment


    • #3
      I am trying to add missing dates to a panel dataset of stocks. In greater details, here is a sample of the code (below). The problem is that I have a lot of stocks "stockidentifier". Can someone help? Thanks!

      Here is what I am trying to do:

      Code:
      Code: 
       // create easy to reproduce example data: trading dates clear input str10(trading_days) "01/02/2016" "01/03/2016" "01/04/2014" "01/04/2015" "01/04/2016" "01/05/2014" "01/05/2015" "01/06/2015" "01/06/2016" "01/07/2014" "01/07/2015" "01/07/2016" "01/08/2014" "01/08/2016" "01/09/2014" "01/09/2015" "01/09/2016" "01/10/2014" "01/10/2015" "01/11/2016" "01/12/2014" "01/12/2015" "01/12/2016" "02/01/2014" "02/01/2015" "02/02/2015" "02/02/2016" "02/03/2015" "02/03/2016" end  // create a true date variable generate truedate=date(trading_days,"DMY") format truedate %td sort truedate // temporarily save tempfile dates save `"`dates'"'  // create easy to reproduce example data: stock names and values clear input str25(stockidentifier) str10(date) date_ymd hightradefortheday lowtradefortheday lasttradefortheday "4DS.ASX" "24/02/2016" 20160224 .034 .03 .03 "4DS.ASX" "25/02/2016" 20160225 .03 .029 .029 "4DS.ASX" "26/02/2016" 20160226 .03 .029 .029 "4DS.ASX" "29/02/2016" 20160229 .029 .029 .029 "4DS.ASX" "01/03/2016" 20160301 .03 .029 .03 "4DS.ASX" "02/03/2016" 20160302 .033 .032 .032 "88EO.ASX" "02/07/2015" 20150702 .005 .004 .005 "88EO.ASX" "03/07/2015" 20150703 .005 .005 .005 "88EO.ASX" "06/07/2015" 20150706 .006 .005 .006 "88EO.ASX" "07/07/2015" 20150707 .005 .005 .005 "88EO.ASX" "08/07/2015" 20150708 .004 .004 .004 "88EO.ASX" "13/07/2015" 20150713 .005 .004 .005 "88EO.ASX" "15/07/2015" 20150715 .004 .004 .004 "88EO.ASX" "17/07/2015" 20150717 .005 .004 .005 "88EO.ASX" "22/07/2015" 20150722 .004 .004 .004 end format date_ymd  %10.0g // create a true date variable generate truedate=date(date,"DMY") format truedate %td sort truedate // temporarily save tempfile stocks save `"`stocks'"'  // save all names of stocks to local macro quietly : levelsof stockidentifier , local(stocknames) local stockcount : word count `stocknames'  // duplicate trading dates for each stock use `"`dates'"' , clear generate stockidentifier="" local firstobs=1 local lastobs=_N local origN=_N expand `stockcount' foreach stockname of local stocknames {     replace stockidentifier=`"`stockname'"' in `firstobs'/`lastobs'     local firstobs=`firstobs'+`origN'     local lastobs=`lastobs'+`origN' } keep truedate stockidentifier save `"`dates'"' , replace  // join trading dates and stocks use `"`stocks'"' , clear joinby stockidentifier truedate using `"`dates'"' , unmatched(both) _merge(source) sort stockidentifier truedate  // list data list , sepby(stockidentifier)

      Comment


      • #4
        Your sample code displayed as one lone line for me, so can't use your example (This is the second time I have seen that problem recently, and I don't recall seeing it before.) However, what you want sounds like a job for -fillin-.
        What about -fillin stockidentifier trading_days-

        Comment


        • #5
          Hi Mike,

          the stock dataset that contains "stockidentifier" is distinct to the "trading_days" dataset. Can you use "fillin" to join them? How would you do that? Thanks!

          Even if this method works and is more efficient (that would be awesome, thanks Mike), I'm curious to know how to solve "macro length exceeded" problem. Anyone can help with that? Thanks!

          Comment


          • #6
            There is no solution to exceeding the maximum macro length beyond

            1. Using another method entirely.

            2. Joining StataCorp as a developer and changing the source code.

            #2 is clearly impractical on your time scale.

            #1 depends on the original problem in a thread you don't cross-reference here (but should have done). I'm travelling now and can't contribute further; sorry.

            Comment


            • #7
              Francois is wasting people's time, this is just an unnecessary fork from this thread.

              Comment


              • #8
                From help limits:

                The maximum length of the contents of a macro are fixed in Stata/IC and settable in Stata/SE and Stata/MP. The currently set maximum length is recorded in c(macrolen); type display c(macrolen). The maximum length can be changed with set maxvar. If you set maxvar to a larger value, the maximum length increases; if you set maxvar to a smaller value, the maximum length decreases. The relationship between them is maximum_length = 129*maxvar + 200.
                Edit: I just saw that Robert offered a solution in the other thread started by Francois.
                Last edited by Friedrich Huebler; 06 Sep 2017, 10:09.

                Comment


                • #9
                  Responding to Mike's comment in post #4 above, Francois copied the code block from Daniel Bela's post #4 in the previous thread linked to by Robert in post #7 above, and then pasted it into his post #3 above, surrounding it with a code block, and removing some of the lines.

                  Unfortunately, while the contents of code blocks are easy to copy and paste into a text-based editor, they do not copy and paste well into the forum software - line endings seem to be lost. I often will copy, then paste into a window in a plain text editor, and then recopy from that window to paste into the forum.

                  If anyone knows any magic to make this work, I'd be glad to hear. Every so often someone posts code in a code block with a straightforward error, and it would be nice to be able to easily copy it to a code block in a new post to make the correction.

                  Comment


                  • #10
                    William LisowskiI've had the problem you flagged and solved it the same way by using my favourite text editor as washing machine.

                    Comment

                    Working...
                    X