Announcement

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

  • Any way to limit errors in bootstrapped commands, esp with sqreg?

    I am running sqreg and it appears that of the estimations isn't behaving well. That is, the display of bootstrap replications is just repeated x's. (see below, please). Is there any way to direct Stata to give up after a certain number of errors when bootstrapping like this? I've thought of doing qreg separately for each quantile and capture any failed estimation, but I don't know how to induce qreg to fail after a certain number of errors. Thank you for any advice.

    Code:
    . sqreg crowdFav_shortfall_50 ib(#4).agent_type_encoded , q(0.25 .5) reps(20)
    (fitting base model)
    
    Bootstrap replications (20): xxxxxxxxxxxxxxxxxxxx done
    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx--Break--
    r(1);
    _______________________________________

    Glenn Hoetker
    Professor in Business Strategy

    Melbourne Business School, University of Melbourne
    200 Leicester Street, Carlton, Victoria 3053, Australia
    Email: [email protected]

    I acknowledge the Traditional Owners of the land on which I work, the Wurundjeri people of the Kulin Nations, and pay my respects to their Elders, past and present.

  • #2
    I am not aware of any such functionality in Stata. I guess you need to do the bootstrapping manually and count the number of failures, using bsample and postfile (for example).

    In any case, if the setup follows your example where every resample fails, there might be more substantial issues with the data or the model.
    Best wishes

    Stata 18.0 MP | ORCID | Google Scholar

    Comment


    • #3
      Here's an inelegant hack that might work. The big ideas are: 1) put a wrapper around -sqreg-; 2) count the number of failed executions of -sqreg- in a global-; 3) execute -sqreg- only if the global failure count is below some threshold. This is the first time in my long Stata career that I have found a use for a global, which makes me think there must be a cleaner way to do this -- suggestions welcome.

      Code:
      cap prog drop wrapper
      prog wrapper, rclass
        if ($failures > 10 {
           // don't bother trying -sqreg-
           return desired scalar values as missing
        }
        else { 
           // Try sqreg and count if it fails.
           sqreg ......
           if (sqreg terminated normally) {
              return scalar values as desired 
           }
           else {
              return scalar values as missing
              global failures = $failures + 1
           }
        }
      end
      //
      global failures = 0
      bootstrap r() r() ... , reps(1000): wrapper

      Comment


      • #4
        Thank you, all. My challenge is that sqreg never seems to fail. I just keeps trying to get successful bootstraps. Have to appreciate its dedication I suppose. Because this is part of a loop over multiple quantiles and subsets of data, it's hard skip problematic versions of the model. For the moment, I'm just going with analytic standard error (in NFL terms, "punting"). The model still fails, but it does so gracefully, reporting "0" for coefficients and no standard errors, then continuing on.

        For anyone's future reference, I did a bit of research and have the outline of a solution -- I haven't implemented it however. I now know that these types of errors are more likely when there is a high proportion of observations with exactly the value of the quantile. In my case, there was a pile of observations at 0, which was the value of the 25th quantile. One can use a combination of count, summarise and some macro math to determine if more than some fixed percentage (would take some experimentation to figure out what it is) of obs meet that condition. If so, use the continue command to skip running that model and go on to the next one. I think it requires moving from sqreg to multiple invocations of qreg.

        Helpful to know I'm not just missing some obvious option. Much appreciated.
        _______________________________________

        Glenn Hoetker
        Professor in Business Strategy

        Melbourne Business School, University of Melbourne
        200 Leicester Street, Carlton, Victoria 3053, Australia
        Email: [email protected]

        I acknowledge the Traditional Owners of the land on which I work, the Wurundjeri people of the Kulin Nations, and pay my respects to their Elders, past and present.

        Comment

        Working...
        X