Announcement

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

  • Looping regression dropping one group at a time

    Hello, I am using Stata 15.1. I would like to estimate a simple OLS regression x = y using a panel dataset that excludes all firms in one industry at a time and saves the output of each regression. I have a variable 'industry' that denotes the 3 digit SIC code the firm belongs to. So, I would estimate a regression dropping all values of 'industry' that equal 001, then estimate a regression dropping all values of industry that equal 002, etc. and store the output of each regression.

    Thank you

  • #2
    You could try something like this (untested) example below. It uses eststo and esttab from the estout package, downloadable from SSC or the Stata Journal.
    Code:
    local i = 1
    levelsof industry, local(industries)
    foreach industry of local industries {
        eststo est`i': reg y x if industry != `industry'
        local i = `i' + 1
    }
    
    esttab est*

    Comment


    • #3
      Thank you for your help; this does exactly what I want. One issue though is that it appears the eststo and esttab commands only allow for storage of 300 models and I have more than 300 industries. I can simply run the commands multiple times for sub groups, store separately, and combine the files, but if anyone knows how to accomplish the same task without the storage limits it is appreciated.

      Comment


      • #4
        You could look at postfile which writes parameters to a data file. Alternatively, set up variables with all missing and a counter that increases 1 each time through the loop. Then replace the missing values with the appropriate parameters in the appropriate observation number.

        Comment

        Working...
        X