Announcement

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

  • Outreg2/Export results for loop within a loop regression

    Dear All,

    I'm working with a cross-sectional firm-level data from 37 countries. I'm trying to run regression models with 8 different dependent variables with firm-level and country-level controls in addition to other country-level variables of interest. Regression output for 11 blocks in addition to block details with change in r-squared is generated using the code(modified to include outreg2) in link below :

    https://www.statalist.org/forums/for...un-regressions

    Code:

    local controls ltoas lage lemp prof pdr pcgdpgrowth unemp inflation

    foreach response in dr1 dr2 dr3 ldr1 ldr3 sdr1 sdr2 sdr3 {
    nestreg : regress `response' `controls' cr (pcr) (pb)
    outreg2 using E:\2014V7.xls, append bdec(3) tdec(3) rdec(3) pdec(3) stats(coef se) ctitle( `response' `e(model)') title("OLS by Country") addstat("F-Stat",e(F),"Prob > F",e(p))
    }


    The outreg2 code exports results for the last block. Is there an option to export the other 10 blocks? Alternatively, are there other codes that export the required results to excel.


    Thank you.


  • #2
    You should store the estimates after each regression. See

    Code:
    help estimates store

    Comment


    • #3
      Thanks a lot, Andrew. I tried storing estimates after your suggestion for nestreg. But nestreg comes with the following code to store estimates, I suppose:

      nestreg, store: regress dv indp1 i(ndp2) (indp3)

      I'm not able to retrieve the stored results of nestreg to export individual blocks. Do you have any suggestions?

      Comment


      • #4
        Code:
        local controls ltoas lage lemp prof pdr pcgdpgrowth unemp inflation
        local i 1
        estimates clear
        foreach response in dr1 dr2 dr3 ldr1 ldr3 sdr1 sdr2 sdr3 {
            nestreg : regress `response' `controls' cr (pcr) (pb)
            estimates store reg`i'
            local ++i
        }
        outreg2 [reg*] using E:\2014V7.xls, replace bdec(3) tdec(3) rdec(3) pdec(3) stats(coef se) ctitle( `response' `e(model)') title("OLS by Country") addstat("F-Stat",e(F),"Prob > F",e(p))
        Last edited by Andrew Musau; 03 Dec 2020, 07:33.

        Comment

        Working...
        X