Announcement

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

  • Putdocx: make pwcorr table with sig.

    Hi all,

    I am trying to make a table using putdocx with standard Pearson correlation coefficients and significance.

    I am able to get 2 tables in a Word using putdocx:
    1: correlation coefficients
    2: significance.

    Example:

    Code:
    clear all
    set more off
    
    sysuse auto
    putdocx begin
    
    pwcorr mpg price displacement rep78, sig
    
    mat C = r(C)
    matrix sig = r(sig)
    
    putdocx table table_name = matrix(C), rownames colnames nformat(%6.2f)
    putdocx table table_name = matrix(sig), rownames colnames nformat(%6.2f)
    
    putdocx save mydoc, replace
    this look like this:

    Click image for larger version

Name:	Sin título.png
Views:	1
Size:	20.7 KB
ID:	1692104


    But my goal it get only one table like this:

    Click image for larger version

Name:	1.png
Views:	1
Size:	9.0 KB
ID:	1692103

    Thanks in advance,
    Regards

  • #2
    Here is some code to get you started

    Code:
    mata :
    
    transmorphic matrix concat_row_wise(
        
        transmorphic matrix X,
        transmorphic matrix Y
        
        )
    {
        real scalar ncols
        
        
        if (eltype(X) != eltype(Y))     _error(3250)
        if (rows(X) != rows(Y))         _error(3200)
        if ((ncols=cols(X)) != cols(Y)) _error(3200)
        
        return( colshape((X, Y), ncols) )
    }
    
    end
    
    
    local varlist mpg price displacement rep78
    
    
    sysuse auto
    
    pwcorr `varlist', sig
    
    mata : st_matrix("Cp", concat_row_wise(st_matrix("r(C)"), st_matrix("r(sig)")))
    matrix colnames Cp = `varlist'
    local rownames = subinstr("`varlist'", " ", " p-value ", .)
    matrix rownames Cp = `rownames' "p-value"
    
    matlist Cp
    Last edited by daniel klein; 06 Dec 2022, 06:56. Reason: "pvalue" -> "p-value"

    Comment


    • #3
      Thanks daniel klein , your code work great.

      Regards
      Rodrigo

      Comment

      Working...
      X