Announcement

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

  • Loops: forcing stata to skip over groups with no observations

    Hi all -

    This might be a weird request, but I have a loop that pairs one of 18 different countries (tagged with i = 1/18) with one of 14 different other countries (tagged with j = 19/32). As I have it written now, the loop pairs each country i with each potential partner j and regresses on a number of outcomes specified in the local `outcomes'. The code looks something like this:

    Code:
    * diff in diff
    est drop _all 
    foreach outcome of local outcomes {
        forvalues i = 1/18 {
            forvalues j = 19/32 {
                eststo: qui reg `outcome' `dnd_interactions' `controls'  (id_a == `i' | id_b == `j') [pw = round(weight, 1)], cluster(countryname)
            }
        }
        esttab using "X~X", not nostar noobs keep(term of interest) 
        est drop _all
    }
    I've run something similar to this in the past and had no problems. However, now there is an issue wherein the 128th regression on one of the outcomes produces an error, "no observations." While I'm happy to interrogate why that is for this particular pair (and I certainly plan to do just that), I would like to see the other results from the regressions in which there are sufficient observations.

    Is there a way to force Stata to run through the rest of the loop and just insert a missing value for the output, or do I have to remove this outcome variable/figure out why there are no observations? Any help here is greatly appreciated. Happy to explain further if anything I've written is unclear.

  • #2
    See

    Code:
    help capture
    So

    Code:
    capture noisily{
     
      LOOP
    
    }

    Comment


    • #3
      Thanks, Andrew!

      Comment

      Working...
      X