Announcement

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

  • Outreg2 in a loop - add tables not append

    Hi all!

    I need to do regression with lots of different dependent variables and so I am using a loop.

    My baseline regression looks something like this:

    yit = β0 + β1 x1it + β2x2it + εit

    My code so far is

    local educationVars = "educ1 educ2 educ3 educ4"
    foreach var of local educationVars {
    reg `var' x1 x2
    outreg2 using education.doc, replace ctitle(baseline)

    }

    Now this gives me four regression tables and what I want is for outreg2 to put them all in one document one after the other - not appended in the same table or replace like I have in my code at the moment!
    Is this possible and if so anyone knows how?

    Any help would be greatly appreciated!!

  • #2
    I would just write multiple files and then copy and paste.

    Comment


    • #3
      This is how I'd code it:

      * the first tile through you replace the excel file with the first variable
      foreach var of varlist educ1{
      reg `var' x1 x2
      outreg2 using education.doc, replace ctitle(baseline)
      }

      * for subsequent variables you'd loop with the append statement
      foreach var of varlist educ2 educ3 educ4{
      reg `var' x1 x2
      outreg2 using education.doc, append ctitle(baseline)
      }


      Comment


      • #4
        Dear Statalists,

        I regress a firm’s hourly production on post-treatment-post-interaction variable. I need to perform the regression for each hour separately. In order to do that, I run the following code:

        forvalues h = 1/24 {

        reghdfe production treat if hour == `h', absorb(i.firm#i.hour i.hour#i.day) vce(cluster firm calday)
        outreg2 using file.xls, ctitle(tonns/hour) alpha(0.01, 0.05, 0.1) symbol(***, **, *) dec(5) fmt(fc) replace

        }

        I obtain the results for hour==1, and then I receive the error: v1 not found, r(111). As far as I understand, the problem is in the “outreg2” command. However, I cannot find my mistake. There is no “v1” variable in my dataset…

        Please advise me on this issue if possible.

        Thank you.

        Comment

        Working...
        X