Announcement

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

  • Conditional statements to avoid looping error due to missing data

    The loop program runs the regression by SICCode by year. However, it stops in the very initial stage saying "no observations" as there are missing values in the first few years of some of the variables. I thinking about encountering this by setting some conditions statements that if there is missing then to ignore and move on to the next.

    Could someone please help me accomplish this or guide me on this ?

    Code:
    set more off
    
    gen ABN_CFO = .                      
    
    egen sicid = group(SICCode Year)
    sum sicid
    local max=r(max)
    
    forvalues i = 1/`max' {
    
     di "Busy with regression " `i' " of " `max'
     qui reg PROD_SLAssset Inverse_LAssets Sales_SLAssets DSales_SLAssets Delta_SalesLag_SLAsset if sicid == `i'
     qui predict res if sicid == `i', res
     qui replace ABN_CFO = res if sicid == `i'
     qui drop res
     
    }
    My data is panel data

    Code:
     
     * Example generated by -dataex-. For more info, type help dataex clear input str9 Ticker int Year str23 Industry byte SICCode float(PROD_SLAssset Inverse_LAssets Sales_SLAssets DSales_SLAssets Delta_SalesLag_SLAsset) "TH:2S"  1994 "Industrials"             11         .             .         .            .            . "TH:2S"  1995 "Industrials"             11         .             .         .            .            . "TH:2S"  1996 "Industrials"             11         .             .         .            .            . "TH:2S"  1997 "Industrials"             11         .             .         .            .            . "TH:2S"  1998 "Industrials"             11         .             .         .            .            . "TH:2S"  1999 "Industrials"             11         .             .         .            .            . "TH:2S"  2000 "Industrials"             11         .             .         .            .            . "TH:2S"  2001 "Industrials"             11         .             .         .            .            . "TH:2S"  2002 "Industrials"             11         .             .         .            .            . "TH:2S"  2003 "Industrials"             11         .             .         .            .            . "TH:2S"  2004 "Industrials"             11         .             .         .            .            . "TH:2S"  2005 "Industrials"             11         .             .         .            .            . "TH:2S"  2006 "Industrials"             11         .             .         .            .            . "TH:2S"  2007 "Industrials"             11 4.6497087 1.5962966e-06  4.737489     .9118366            . "TH:2S"  2008 "Industrials"             11 3.2230334 1.3520456e-06  3.779143    -.2334577     .7723155 "TH:2S"  2009 "Industrials"             11  4.581761 1.7878214e-06  4.576771    -.4204223    -.3087031 "TH:2S"  2010 "Industrials"             11  2.906181  1.094789e-06  3.079102    .27647364   -.25744948 "TH:2S"  2011 "Industrials"             11 3.4135144  9.758983e-07 3.6054766     .8607559    .24644944 "TH:2S"  2012 "Industrials"             11   3.49226  9.435992e-07  3.829722    .34357485     .8322677 "TH:2S"  2013 "Industrials"             11  3.147663   7.98077e-07   3.26576   .026658963     .2905886 "TH:2S"  2014 "Industrials"             11  3.335886  8.197259e-07 3.4718614    .11751344   .027382124 "TH:7UP" 1994 "Resources"               33         .             .         .            .            . "TH:7UP" 1995 "Resources"               33         .             .         .            .            . "TH:7UP" 1996 "Resources"               33         .             .         .            .            . "TH:7UP" 1997 "Resources"               33         .             .         .            .            . "TH:7UP" 1998 "Resources"               33         .             .         .            .            . "TH:7UP" 1999 "Resources"               33         .             .         .            .            . "TH:7UP" 2000 "Resources"               33         .             .         .            .            . "TH:7UP" 2001 "Resources"               33         .             .         .            .            . "TH:7UP" 2002 "Resources"               33 4.0856404  8.065576e-07  4.338902      .416637            . "TH:7UP" 2003 "Resources"               33  3.059031    6.9175e-07 3.2586355    -.4626548    .35733175 "TH:7UP" 2004 "Resources"               33 3.1488006   6.29042e-07   3.54184     .5786035    -.4207146 "TH:7UP" 2005 "Resources"               33  4.045958   3.90379e-07 4.0607376    1.8626966     .3590773 "TH:7UP" 2006 "Resources"               33 3.4078295 2.7327027e-07  3.619166     .7765983    1.3039112 "TH:7UP" 2007 "Resources"               33 2.3345294 2.4704937e-07 2.5703285    -.7015703     .7020819 "TH:7UP" 2008 "Resources"               33 2.0958078  2.648143e-07  2.221718   -.53343874    -.7520192 "TH:7UP" 2009 "Resources"               33  1.209359 2.3933214e-07 1.4020097      -.60592    -.4821078 "TH:7UP" 2010 "Resources"               33  1.425994 2.4231502e-07 1.5356272    .11614354    -.6134719 "TH:7UP" 2011 "Resources"               33 1.2415527  2.270738e-07 1.3578967   -.08114187    .10883828 "TH:7UP" 2012 "Resources"               33 1.0803432 2.4556655e-07 1.2565333    -.2119497      -.08775 "TH:7UP" 2013 "Resources"               33  3.894809  8.253958e-07  3.907181    -.3162661    -.7124032 "TH:7UP" 2014 "Resources"               33  1.725239  8.131668e-07 2.1056044   -1.7436882    -.3115803 "TH:A"   1994 "Property & Construction" 77         .             .         .            .            . "TH:A"   1995 "Property & Construction" 77         .             .         .            .            . "TH:A"   1996 "Property & Construction" 77         .             .         .            .            . "TH:A"   1997 "Property & Construction" 77         .             .         .            .            . "TH:A"   1998 "Property & Construction" 77         .             .         .            .            . "TH:A"   1999 "Property & Construction" 77         .             .         .            .            . "TH:A"   2000 "Property & Construction" 77         .             .         .            .            . "TH:A"   2001 "Property & Construction" 77         .             .         .            .            . "TH:A"   2002 "Property & Construction" 77         .             .         .            .            . "TH:A"   2003 "Property & Construction" 77         .             .         .            .            . "TH:A"   2004 "Property & Construction" 77 1.0460142 4.8528494e-07  .8610736     .3701438            . "TH:A"   2005 "Property & Construction" 77 .22955093  2.489774e-07 .24012475    -.2016525    .18990377 "TH:A"   2006 "Property & Construction" 77 .13090853 2.3376775e-07  .2025974   -.02285851    -.1893339 "TH:A"   2007 "Property & Construction" 77  .3248509  2.328408e-07 .18617764    -.0156164   -.02276787 "TH:A"   2008 "Property & Construction" 77  .4043962 1.9669103e-07 .15804733   .000774766   -.01319187 "TH:A"   2009 "Property & Construction" 77  .3011982 1.7482624e-07  .6006953      .460217  .0006886406 "TH:A"   2010 "Property & Construction" 77  .4767359 1.8711587e-07  .6238623   -.01905962     .4925685 "TH:A"   2011 "Property & Construction" 77 .13769744  1.813995e-07 .28060448    -.3241988   -.01847735 "TH:A"   2012 "Property & Construction" 77  .3409032 1.7449793e-07  .3103165     .0403879    -.3118643 "TH:A"   2013 "Property & Construction" 77  .3273264 1.4564372e-07 .25672096 -.0022829655    .03370953 "TH:A"   2014 "Property & Construction" 77  .5052099 1.1142995e-07 .27166867     .0752551 -.0017466644 "TH:A5"  1994 "Services"                55         .             .         .            .            . "TH:A5"  1995 "Services"                55         .             .         .            .            . "TH:A5"  1996 "Services"                55         .             .         .            .            . "TH:A5"  1997 "Services"                55         .             .         .            .            . "TH:A5"  1998 "Services"                55         .             .         .            .            . "TH:A5"  1999 "Services"                55         .             .         .            .            . "TH:A5"  2000 "Services"                55         .             .         .            .            . "TH:A5"  2001 "Services"                55         .             .         .            .            . "TH:A5"  2002 "Services"                55         .             .         .            .            . "TH:A5"  2003 "Services"                55 1.1525862   9.27463e-06   2.13323    1.6549838            . "TH:A5"  2004 "Services"                55  .8782888 4.1007806e-06  1.278562     .3353536     .7317515 "TH:A5"  2005 "Services"                55  .9454873  3.986303e-06 1.0757637   -.16710582     .3259919 "TH:A5"  2006 "Services"                55  .8153177  4.708519e-06   .790372    -.4802925   -.19738112 "TH:A5"  2007 "Services"                55         .   7.53909e-06 1.9890834     .7235717    -.7690249 "TH:A5"  2008 "Services"                55         . 3.0673905e-06  .8288059   .019517805    .29439586 "TH:A5"  2009 "Services"                55 .50154984  2.404754e-06  .7490495    .09928747   .015301448 "TH:A5"  2010 "Services"                55 1.0619361  5.579828e-06  .8722108     -.865833    .23037992 "TH:A5"  2011 "Services"                55   2.92249  8.166732e-06  3.375139     2.098556    -1.267248 "TH:A5"  2012 "Services"                55 1.8582982  8.965635e-06  1.859912   -1.8453966    2.3038454 "TH:A5"  2013 "Services"                55   .777864 .000010775978  .9920258     -1.24344   -2.2180195 "TH:A5"  2014 "Services"                55  76.49998  .00001781642 1.1354939    -.5046679   -2.0558367 "TH:AA"  1994 "Industrials"             11 .15526025  5.469568e-07 .28518873     .1788937            . "TH:AA"  1995 "Industrials"             11  .2614009  1.410538e-07 .12367302    .05012615    .04613461 "TH:AA"  1996 "Industrials"             11  .1655263  6.650534e-08 .18224686    .12393637    .02363394 "TH:AA"  1997 "Industrials"             11  .1580202  5.070889e-08  .3385713      .199612     .0944988 "TH:AA"  1998 "Industrials"             11  .1568674  2.425732e-08  .2310874   .069126986    .09548724 "TH:AA"  1999 "Industrials"             11 .21467777 2.3942054e-08  .3114601     .0833761    .06822856 "TH:AA"  2000 "Industrials"             11  .3019628  3.158392e-08  .4725594    .06168694    .10998823 "TH:AA"  2001 "Industrials"             11 .27098876 3.1228307e-08  .4884446   .021205833    .06099238 "TH:AA"  2002 "Industrials"             11  .3005794 3.3299195e-08  .4917017   -.02913373   .022612084 "TH:AA"  2003 "Industrials"             11  .4097156  3.456964e-08  .6128936    .10243217   -.03024526 "TH:AA"  2004 "Industrials"             11 .43288425  3.376023e-08  .7015701     .1030268    .10003382 "TH:AA"  2005 "Industrials"             11  .4946924  3.622872e-08  .7147999   -.03806784    .11055996 "TH:AA"  2006 "Industrials"             11 .50810826 3.3656402e-08  .7413872    .07733966  -.035364937 "TH:AA"  2007 "Industrials"             11  .5259682 3.3217717e-08  .7778341    .04611031     .0763316 "TH:AA"  2008 "Industrials"             11         . 3.5009858e-08         .            .    .04859802 "TH:AA"  2009 "Industrials"             11         .             .         .            .            . end format %ty Year

  • #2
    You can add -capture- before the regression command to ignore the warning.

    Code:
    qui capture reg .... if sicid == `i'
    Roman

    Comment


    • #3
      Code:
      forvalues i = 1/`max' {
          di "Busy with regression " `i' " of " `max'
          capture reg PROD_SLAssset Inverse_LAssets Sales_SLAssets DSales_SLAssets ///
              Delta_SalesLag_SLAsset if sicid == `i'
          if c(rc) == 0 { // SUCCESSFUL REGRESSION
              qui predict res if sicid == `i', res
              qui replace ABN_CFO = res if sicid == `i'
              qui drop res
          }
          else if inlist(c(rc), 2000, 2001) { // NO OR INSUFFICIENT OBSERVATIONS
              display "Regression not done -- no, or insufficient observations"
          }
          else { // UNEXPECTED ERROR
             display in red "Unexpected error in regression -- execution terminated"
             error `c(rc)'
             exit
          }
      }
      This code will attempt each regression. If the regression goes to completion, it will then calculate the residuals. If there are too few (or no) observations for the regression, it will send a message to the Results window informing you of that fact, but proceed to the next one. If any other error arises during the regression, it will display an error message in the Results window and terminate execution. (If the regression fails for any reason other than insufficient observations, you should be immediately made aware of that and forced to deal with it--not simply carry on with the error message scrolling of the screen so you never find out about it.)

      Added: I strongly disagree with the naked use of capture as suggested in #2. If it worked, all manner of things could be going wrong and you will not find out about them until much later in your workflow, or, worse, find out about it after the fact when somebody relies on your incorrect results to their detriment and figures out that it was your fault. But, in this case, it won't "work" anyway because the -predict- command will give you a "last estimates not found" error and halt execution after an attempt at a regression with no observations. (In the event of a regression with insufficient observations, however, it is much worse than that: the residuals will be calculated with the results of the previous regression, and you will not be told that this has happened.)

      When Stata gives error messages, it is being your friend, warning you that something is wrong. You suppress and ignore error messages at your peril.
      Last edited by Clyde Schechter; 15 Feb 2022, 17:35.

      Comment


      • #4
        I agree with Clyde Schechter as usual. Noting that

        Code:
        ROD_SLAssset Inverse_LAssets Sales_SLAssets DSales_SLAssets
        Delta_SalesLag_SLAsset
        defines an outcome and four predictors, I would tend to want at least 10 times as many observations as parameters estimated. Regardless of that it would be prudent to go
        Code:
        gen n = .  
        before the loop and
        Code:
        replace n = e(N) if sicid == `i' 
        after each successful regression. Then you have a record of the number of observations used in each regression. You could also save various figures of merit for each regression.

        Comment


        • #5
          #3. Thanks Clyde, commendable as always. Though I was only suggesting how to ignore the warning (as requested in the post), I agree, I should have elaborated the perils of the blind use of 'capture'.
          Roman

          Comment


          • #6
            Clyde Schechter Nick Cox Thank you so much for always being insightful, this worked perfectly for me. I exactly now know which variable is giving me trouble. Appreciate all you help since the beginning of my journey on Stata.

            Roman Mostazir Thank you as well sir

            Comment


            • #7
              Following Clyde Schechter advice earlier I used the following code but Stata throwing me an "error r (198) - program error: code follows on the same line as open brace". I tried indenting back and forth however it still faced with the same issue.

              Code:
              set more off  
              gen ABN_PROD = .                    
              egen sicid = group(SICCode Year)          
              sum sicid
              local max=r(max)  
              
              forvalues i = 1/`max' {
                  di "Busy with regression " `i' " of " `max'
                  capture reg PROD_SLAssset Inverse_LAssets Sales_SLAssets DSales_SLAssets ///
                      Delta_SalesLag_SLAsset if sicid == `i'
                  if c(rc) == 0 { // SUCCESSFUL REGRESSION
                      qui predict res if sicid == `i', res
                      qui replace ABN_PROD = res if sicid == `i'
                      qui drop res
                  }
                  else if inlist(c(rc), 1994, 2014) { // NO OR INSUFFICIENT OBSERVATIONS
                      display "Regression not done -- no, or insufficient observations"
                  }
                  else { // UNEXPECTED ERROR
                     display in red "Unexpected error in regression -- execution terminated"
                     error `c(rc)'
                     exit
                  }
              }

              Please find below a reference of my data which are panel data. I always make sure to xtset my data


              Code:
              * Example generated by -dataex-. For more info, type help dataex
              clear
              input str9 Ticker int Year str23 Industry byte SICCode float(PROD_SLAssset Inverse_LAssets Sales_SLAssets DSales_SLAssets Delta_SalesLag_SLAsset)
              "TH:2S"    1994 "Industrials"             11         .             .         .            .            .
              "TH:2S"    1995 "Industrials"             11         .             .         .            .            .
              "TH:2S"    1996 "Industrials"             11         .             .         .            .            .
              "TH:2S"    1997 "Industrials"             11         .             .         .            .            .
              "TH:2S"    1998 "Industrials"             11         .             .         .            .            .
              "TH:2S"    1999 "Industrials"             11         .             .         .            .            .
              "TH:2S"    2000 "Industrials"             11         .             .         .            .            .
              "TH:2S"    2001 "Industrials"             11         .             .         .            .            .
              "TH:2S"    2002 "Industrials"             11         .             .         .            .            .
              "TH:2S"    2003 "Industrials"             11         .             .         .            .            .
              "TH:2S"    2004 "Industrials"             11         .             .         .            .            .
              "TH:2S"    2005 "Industrials"             11         .             .         .            .            .
              "TH:2S"    2006 "Industrials"             11         .             .         .            .            .
              "TH:2S"    2007 "Industrials"             11 4.6497087 1.5962966e-06  4.737489     .9118366            .
              "TH:2S"    2008 "Industrials"             11 3.2230334 1.3520456e-06  3.779143    -.2334577     .7723155
              "TH:2S"    2009 "Industrials"             11  4.581761 1.7878214e-06  4.576771    -.4204223    -.3087031
              "TH:2S"    2010 "Industrials"             11  2.906181  1.094789e-06  3.079102    .27647364   -.25744948
              "TH:2S"    2011 "Industrials"             11 3.4135144  9.758983e-07 3.6054766     .8607559    .24644944
              "TH:2S"    2012 "Industrials"             11   3.49226  9.435992e-07  3.829722    .34357485     .8322677
              "TH:2S"    2013 "Industrials"             11  3.147663   7.98077e-07   3.26576   .026658963     .2905886
              "TH:2S"    2014 "Industrials"             11  3.335886  8.197259e-07 3.4718614    .11751344   .027382124
              "TH:A"     1994 "Property & Construction" 77         .             .         .            .            .
              "TH:A"     1995 "Property & Construction" 77         .             .         .            .            .
              "TH:A"     1996 "Property & Construction" 77         .             .         .            .            .
              "TH:A"     1997 "Property & Construction" 77         .             .         .            .            .
              "TH:A"     1998 "Property & Construction" 77         .             .         .            .            .
              "TH:A"     1999 "Property & Construction" 77         .             .         .            .            .
              "TH:A"     2000 "Property & Construction" 77         .             .         .            .            .
              "TH:A"     2001 "Property & Construction" 77         .             .         .            .            .
              "TH:A"     2002 "Property & Construction" 77         .             .         .            .            .
              "TH:A"     2003 "Property & Construction" 77         .             .         .            .            .
              "TH:A"     2004 "Property & Construction" 77 1.0460142 4.8528494e-07  .8610736     .3701438            .
              "TH:A"     2005 "Property & Construction" 77 .22955093  2.489774e-07 .24012475    -.2016525    .18990377
              "TH:A"     2006 "Property & Construction" 77 .13090853 2.3376775e-07  .2025974   -.02285851    -.1893339
              "TH:A"     2007 "Property & Construction" 77  .3248509  2.328408e-07 .18617764    -.0156164   -.02276787
              "TH:A"     2008 "Property & Construction" 77  .4043962 1.9669103e-07 .15804733   .000774766   -.01319187
              "TH:A"     2009 "Property & Construction" 77  .3011982 1.7482624e-07  .6006953      .460217  .0006886406
              "TH:A"     2010 "Property & Construction" 77  .4767359 1.8711587e-07  .6238623   -.01905962     .4925685
              "TH:A"     2011 "Property & Construction" 77 .13769744  1.813995e-07 .28060448    -.3241988   -.01847735
              "TH:A"     2012 "Property & Construction" 77  .3409032 1.7449793e-07  .3103165     .0403879    -.3118643
              "TH:A"     2013 "Property & Construction" 77  .3273264 1.4564372e-07 .25672096 -.0022829655    .03370953
              "TH:A"     2014 "Property & Construction" 77  .5052099 1.1142995e-07 .27166867     .0752551 -.0017466644
              "TH:AA"    1994 "Industrials"             11 .15526025  5.469568e-07 .28518873     .1788937            .
              "TH:AA"    1995 "Industrials"             11  .2614009  1.410538e-07 .12367302    .05012615    .04613461
              "TH:AA"    1996 "Industrials"             11  .1655263  6.650534e-08 .18224686    .12393637    .02363394
              "TH:AA"    1997 "Industrials"             11  .1580202  5.070889e-08  .3385713      .199612     .0944988
              "TH:AA"    1998 "Industrials"             11  .1568674  2.425732e-08  .2310874   .069126986    .09548724
              "TH:AA"    1999 "Industrials"             11 .21467777 2.3942054e-08  .3114601     .0833761    .06822856
              "TH:AA"    2000 "Industrials"             11  .3019628  3.158392e-08  .4725594    .06168694    .10998823
              "TH:AA"    2001 "Industrials"             11 .27098876 3.1228307e-08  .4884446   .021205833    .06099238
              "TH:AA"    2002 "Industrials"             11  .3005794 3.3299195e-08  .4917017   -.02913373   .022612084
              "TH:AA"    2003 "Industrials"             11  .4097156  3.456964e-08  .6128936    .10243217   -.03024526
              "TH:AA"    2004 "Industrials"             11 .43288425  3.376023e-08  .7015701     .1030268    .10003382
              "TH:AA"    2005 "Industrials"             11  .4946924  3.622872e-08  .7147999   -.03806784    .11055996
              "TH:AA"    2006 "Industrials"             11 .50810826 3.3656402e-08  .7413872    .07733966  -.035364937
              "TH:AA"    2007 "Industrials"             11  .5259682 3.3217717e-08  .7778341    .04611031     .0763316
              "TH:AA"    2008 "Industrials"             11         . 3.5009858e-08         .            .    .04859802
              "TH:AA"    2009 "Industrials"             11         .             .         .            .            .
              "TH:AA"    2010 "Industrials"             11         .             .         .            .            .
              "TH:AA"    2011 "Industrials"             11         .             .         .            .            .
              "TH:AA"    2012 "Industrials"             11         .             .         .            .            .
              "TH:AA"    2013 "Industrials"             11         .             .         .            .            .
              "TH:AA"    2014 "Industrials"             11         .             .         .            .            .
              "TH:AAV"   1994 "Services"                55         .             .         .            .            .
              "TH:AAV"   1995 "Services"                55         .             .         .            .            .
              "TH:AAV"   1996 "Services"                55         .             .         .            .            .
              "TH:AAV"   1997 "Services"                55         .             .         .            .            .
              "TH:AAV"   1998 "Services"                55         .             .         .            .            .
              "TH:AAV"   1999 "Services"                55         .             .         .            .            .
              "TH:AAV"   2000 "Services"                55         .             .         .            .            .
              "TH:AAV"   2001 "Services"                55         .             .         .            .            .
              "TH:AAV"   2002 "Services"                55         .             .         .            .            .
              "TH:AAV"   2003 "Services"                55         .             .         .            .            .
              "TH:AAV"   2004 "Services"                55         .             .         .            .            .
              "TH:AAV"   2005 "Services"                55         .             .         .            .            .
              "TH:AAV"   2006 "Services"                55         .             .         .            .            .
              "TH:AAV"   2007 "Services"                55         .             .         .            .            .
              "TH:AAV"   2008 "Services"                55         .             .         .            .            .
              "TH:AAV"   2009 "Services"                55         .             .         .            .            .
              "TH:AAV"   2010 "Services"                55  4.761964 4.8375995e-07  5.852879     1.363023            .
              "TH:AAV"   2011 "Services"                55  2.821364  2.054747e-07  3.319978     .8339955    .57893753
              "TH:AAV"   2012 "Services"                55  3.668789 2.6386297e-07 4.2489724   -.01441932     1.070986
              "TH:AAV"   2013 "Services"                55  .5921111 3.0280976e-08  .7111501    .22353695 -.0016547645
              "TH:AAV"   2014 "Services"                55  .5066799  2.225423e-08 .56426746    .04162591    .16428277
              "TH:ABICO" 1994 "Agro & Food Industry"    22         .             .         .            .            .
              "TH:ABICO" 1995 "Agro & Food Industry"    22         .             .         .            .            .
              "TH:ABICO" 1996 "Agro & Food Industry"    22         .             .         .            .            .
              "TH:ABICO" 1997 "Agro & Food Industry"    22         .             .         .            .            .
              "TH:ABICO" 1998 "Agro & Food Industry"    22         .             .         .            .            .
              "TH:ABICO" 1999 "Agro & Food Industry"    22         .             .         .            .            .
              "TH:ABICO" 2000 "Agro & Food Industry"    22         .             .         .            .            .
              "TH:ABICO" 2001 "Agro & Food Industry"    22 .15119787  7.354948e-07 .21247046   -.03742271            .
              "TH:ABICO" 2002 "Agro & Food Industry"    22 .06133033  6.836433e-07 .17776436  -.019727213   -.03478446
              "TH:ABICO" 2003 "Agro & Food Industry"    22 .05033533  8.195801e-07 .15543583   -.05767549    -.0236498
              "TH:ABICO" 2004 "Agro & Food Industry"    22 .05991649   9.61618e-07  .1961845   .013810758   -.06767098
              "TH:ABICO" 2005 "Agro & Food Industry"    22 .06723104 1.0491407e-06 .21577467  .0017342296    .01506776
              "TH:ABICO" 2006 "Agro & Food Industry"    22 .08875208 1.1160976e-06    .24546   .015914435  .0018449093
              "TH:ABICO" 2007 "Agro & Food Industry"    22 .13569953 1.1450085e-06 .25121257 -.0006057094   .016326675
              "TH:ABICO" 2008 "Agro & Food Industry"    22 .24344863  2.021092e-06  .4485066   .005083047 -.0010691577
              "TH:ABICO" 2009 "Agro & Food Industry"    22  .2582402  2.386384e-06  .5337315  .0041618543   .006001757
              end
              format %ty Year
              Thank you and genuiely appreciate you help.
              Last edited by Farhan Hasnat; 25 Feb 2022, 14:26.

              Comment


              • #8
                The only error I see in your code is that you changed -else if inlist(c(rc), 2000, 2001)- to -else if inlist(c(rc), 1994,2014)- The numbers 2000 and 2001 in the code are not years: they are Stata error codes and they must be left exactly as I had them. (You are not the first person to make this mistake when adapting code for this kind of problem. I know 2000 and 2001 look like years in your data set, but that is coincidental. If you read and develop an understanding of the code, which you should always do before running it, you will see that those numbers are being compared to c(rc), and c(rc) is the error code thrown in the -capture reg- command.

                Once that is fixed, the code runs without any error messages using your example data. (The code does print a large number of messages stating regression not done -- no or insufficient observations, but that is because the example data set is too small and does not contain any sicid groups with enough observations to actually do the regression. Presumably that wouldn't happen in your real data.)

                I see no reason for you to be getting the error message "error r (198) - program error: code follows on the same line as open brace". And I cannot reproduce this in my setup; I do not get that error message. It may be a problem with your Stata installation. I would try the following:
                1. Run -update all, force-. This will assure that you have the most up to date build of your Stata version and, in particular, that its ado files and executable are properly synchronized. Then try the code (as corrected in my first paragraph here) again. If that does not solve the problem:
                2. Reboot your computer and try again. If that does not solve the problem:
                3. Uninstall and re-install Stata and try again. If that does not solve the problem:
                4. Contact Stata Technical Support.

                Comment

                Working...
                X