Announcement

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

  • Writing to a file using esttab r(coefs, transpose)

    I am running several sets of regressions (100plus sets of 64 regressions) that need to be displayed in a table so that the models are in rows rather than columns. While I am able to do this using esttab, I am not able to write the table produced by esttab to any external files using the customary "using" command. My full code is below. I receive an error matrix r(coefs) not found) when I run the line esttab r(coefs, transpose) using filename,replace. There is no error if I do not use "using".

    Is there a conflict between calling the coefficients from Stata and also writing to an external file ? If esttab is not the correct approach, I would be grateful for some advice pointing me in the right direction.

    sysuse auto,clear
    eststo clear //Clear previously stored regressions.


    levelsof rep78, local(levelrep78)
    di "`levelsrep78'"

    foreach l of local levelrep78 {
    di "rep78: `l'"
    capture noisily eststo Route`l': reg p turn head if rep78==`l'

    }

    esttab using r, p scalars(F df_m df_r) keep( turn ) replace
    mat list r(coefs)


    esttab r(coefs, transpose) using filename,replace //Final Table

    matrix r(coefs) not found

    Best,

    Claudia

  • #2
    This modification of your code works:

    Code:
    sysuse auto, clear
    eststo clear //Clear previously stored regressions.
    matrix drop _all
    
    levelsof rep78, local(levelrep78)
    di "`levelsrep78'"
    
    foreach l of local levelrep78 {
        di "rep78: `l'"
        capturenoisilyeststo Route`l': reg p turn head if rep78==`l'
    }
    
    esttab using r, p scalars(F df_m df_r) keep( turn ) replace 
    mat list r(coefs) 
    mat rename r(coefs) foo
    mat list foo
    
    esttab matrix(foo, transpose) using filename, replace //Final Table

    The error is not related to the using option; the error occurs even without it. Rather, it's something about r(coefs) being a special matrix to estout. It is, after all, a matrix created by estout. I sidestepped the issued by renaming the matrix r(coefs) to foo before esttabbing it.

    Comment


    • #3
      Great! Thank you very much for your help. This worked perfectly!

      Comment

      Working...
      X