Announcement

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

  • force loop continue and ignor errors

    when I am using loop, I have 478 value variables. The data not fit the model sometimes, and the loop will get stuck. I tried to use -capture- to tell STATA, pls skip the error and keep working.

    Here is my code:

    Code:
    forvalue i=1(1)478{
    capture noisily:
    arch ut rmrf smb hml umd if id==`i', earch(1) egarch(1) distribution(t)
    predict variance1 if id==`i', variance
    replace var2=variance1 if id==`i'
    drop variance1
    if _rc==0{
    continue
    }
    }

    unfortunately, it doesn't work.

    I am really grateful if someone could help me figure it out.

    Many thanks!

  • #2
    Code:
    forvalue i=1(1)478 {    
        capture noisily arch ut rmrf smb hml umd if id==`i', earch(1) egarch(1) distribution(t)    
        if _rc == 0 {          
            predict variance1 if id==`i', variance        
            replace var2=variance1 if id==`i'        
            drop variance1      
        }
    }

    Comment


    • #3
      I see! Many Big Thx, Nick!!!

      Best,

      Comment


      • #4
        Hello Nick Cox , I faced the same problem, could you please help me. My code is like that:

        Code:
        levelsof id, local(levels) // id is company id
        foreach i of local levels{
            
            
            nlsur (l_gm_Y=ln({A})+({s}/(1-{s}))*(ln(({alph}*gm_K^(({s}-1)/{s}))+((1-{alph})*((exp({g}))*gm_L))^(({s}-1)/{s})))) (l_KY=ln({alph})+(({s}-1)/{s})*(ln(gm_Y/gm_K)-ln({A}))) (l_LY=ln(1-{alph})+(({s}-1)/{s})*(ln(gm_Y/gm_L)-ln({A})-{g})), initial(aa), if id==`i'
            
            replace coeff_A= _b[/A] if id==`i'
            replace coeff_s= _b[/s] if id==`i'
            replace coeff_alph= _b[/alph] if id==`i'
            replace coeff_g= _b[/g] if id==`i'
            
        }
        My panel data include about 280 firms. I am trying to fit my equation for each firm and to save results. However, Stata does not solve the minimization problem for some firms such as firm 6. I have received error code r(430) and my loop does not continue for the rest of the firms. I want that even if there is no solution for some firms, my loop codes ignore these firms and continue for other firms. How can I do that?

        Comment


        • #5
          It's really the same answer adapted to your commands.

          Comment


          • #6
            Thanks a lot Nick Cox

            Comment


            • #7
              Thanks so much, Nick!

              Comment

              Working...
              X