Announcement

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

  • Loop not working

    Hello all,

    I have a loop which is not working. The error message is the following:

    "<=4 invalid name"

    Code:
    *M is the number of industries - rows of the matrices*
    global M = 22
    
    *N is the number of simulations - columns of the matrices*
    global N = 4
    
    gen lowskill = 1 if CGEskills == 1 | CGEskills == 2
    
    local  m = 1  
    local  n = 1  
    
    * Options:
    *  a) Standard approach: use (un)employment probabilities directly in determining who loses jobs & target jobs at sub-min workers
    *  b) Hertz approach   : use randomly generated probabilities, weight them by wage gap (probweight) & target jobs at sub-min workers
    *  c) Random aproach   : use randomly generated probabilities and no targeting (this should replicate implicit job loss in CGE)
    
    * If covered = 1 then probweight (wage gap) is only defined for covered workers below the minwage
    
    ***KP: This is the STANDARD setup
    gen pru_sim = pru_unemp if covered == 1  
    gsort +ACTPHDSAM +lowskill -pru_sim
    
    
    * Loops to assign job losses/gains to individuals and by sector
    while `n' <= $N {
             gen usjobloss`n' = 0
             while `m' <= $M {
                     gen cumulwgt = 0
                     replace cumulwgt = pweight if ACTPHDSAM == `m'
                     replace cumulwgt = cumulwgt + cumulwgt[_n-1] if ACTPHDSAM == `m' & cumulwgt[_n-1] ~= .
                     replace usjobloss`n' = 1 if unskilljobs[`m',`n'] < 0 & cumulwgt <= abs(unskilljobs[`m',`n']) & ACTPHDSAM == `m'
                     local m = `m' + 1
                     drop cumulwgt
                     }
             local m = 1
             local n = `n' + 1
             }

  • #2
    This probably means that you did not run the entire do-file in one go. Local macros are local, which means they exist only in the part that is currently running. If you run a do-file line by line, then a local macro does not persist.
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      This may happen if you are executing the code in chunks (e.g. line by line) from a do-file editor window. In such cases local macros defined in earlier chunks are not visible to later chunks.

      Comment


      • #4
        Originally posted by Maarten Buis View Post
        This probably means that you did not run the entire do-file in one go. Local macros are local, which means they exist only in the part that is currently running. If you run a do-file line by line, then a local macro does not persist.
        Right thanks. Will try it now! That's exactly what I did...

        Comment


        • #5
          Chris, one way I avoid this problem is almost always selecting local macros and always running the entire. I'm often worried about lurking macros. Macro drop _all.
          Nathan E. Fosse, PhD
          [email protected]

          Comment


          • #6
            The offending code here is clearly

            Code:
            while `n' <= $N
            as the global is defined as 4 and Stata is just not seeing the local macro, which is why it is puzzled by the operator. I almost never use globals for this kind of programming, but their use is not biting here.

            Comment

            Working...
            X