Announcement

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

  • exporting estpost corr to .rtf with the number of observations for each variable pair using esttab

    I am trying to create a correlation matrix in Stata that a) includes the number of observations for each row and b) can be exported to a .docx or .rtf file. I am currently using estout, specifically the estpost corr option. My problem is that estpost corr reports the e(count) number in the last column, but using esttab with the unstack option makes the e(count) disappear. Since estpost corr returns e(count) as vector, there should be a way to add these, but I am not sure how. I want the correlations to be formatted like unstack does. I just want one new column with the number of observations after the variable names / labels. I am using Stata 18 on Windows 10.

    The title should read "for each variable using esttab" instead of "for each variable pair using esttab".

    Code:
    input id trial1 trial2 trial3
    1 1.5 1.4 1.6
    2 1.5 . 1.9
    3 . 2.0 1.6
    4 . . 2.2
    5 1.9 2.1 2
    6 1.8 2.0 1.9
    7 . .  . end  
    
    estpost corr trial1 trial2 trial3, matrix
    esttab using correlations.rtf, replace unstack
    Here is how an illustration where I want to insert the number of observations:
    Code:
    input nobs trial1 trial2 trial3
    4 1 . .
    3 0.994 1 .
    6 0.700 0.644 1
    end
    Crossposted on Stackoverflow.
    Last edited by Felix Kaysers; 02 Jun 2023, 09:31.
    __________________________________________________ __________

    Cheers, Felix
    Stata Version: MP 18.0
    OS: Windows 11

  • #2
    estout is from SSC (FAQ Advice #12). See

    Code:
    help matrix extraction
    to see how you can extract part of a matrix from a larger matrix. Here, the larger matrix is named -e(count)-.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(id trial1 trial2 trial3)
    1 1.5 1.4 1.6
    2 1.5   . 1.9
    3   .   2 1.6
    4   .   . 2.2
    5 1.9 2.1   2
    6 1.8   2 1.9
    7   .   .   .
    end
    
    estpost corr trial1 trial2 trial3, matrix
    ereturn list
    mat count1= e(count)["r1", "trial1:"]
    estadd matrix count1=count1
    esttab, cells("count1 b" ) noobs nonumb unstack eqlab(none) nomtitles
    You need to extract the specific "trial" matrices as well to have multiple models and specify the -pattern()- option of estout to exclude the extra columns of count1. I am out here.

    Res.:

    Code:
    . esttab, cells("count1 b" ) noobs nonumb unstack eqlab(none) nomtitles
    
    ------------------------------------------------------------------------------------------
                       count1            b       count1            b       count1            b
    ------------------------------------------------------------------------------------------
    trial1                  4            1                                                    
    trial2                  3     .9939441                         1                          
    trial3                  4     .7001401                  .6439209                         1
    ------------------------------------------------------------------------------------------
    
    .

    Comment

    Working...
    X