Announcement

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

  • How can I see the specific version of code ran in each iteration of a foreach loop?

    I ran the code below. It is a foreach loop where it runs a regression on a different subset of the data for each iteration. Each subset corresponds to the rows that have a unique value for the variable project_id. When the code runs it displays the results from each of the regressions it runs. I would like to know which regression result corresponds to which values of each proejct_id. Put differently, I would like to be able to see the specific code that is run for each iteration of the loop. How can I do this?


    Code:
    levelsof id, local(project_id)
    foreach i in `project_id' {
    reg vote_share treatment if id == `i' | treatment == 0
    }

  • #2
    The easiest might be to include a line inside the loop to display the id, something like this:
    Code:
    levelsof id, local(project_id)
    foreach i in `project_id' {
        dis "Regression for `i':"
        reg vote_share treatment if id == `i' | treatment == 0
    }

    Comment


    • #3
      Hemanshu Kumar was spot on in terms of general advice. If I follow what is being done correctly, you would benefit from much more reporting, including two counts

      Code:
      count if id == `i' & treatment < . 
      
      count if treatment == 0 & id != `i'
      as these are the disjoint subsets being pooled in each regression.

      I am ruling out | (or) being a typo for & (and) as insisting on treatment == 0 would give you no regression.

      Comment

      Working...
      X