Announcement

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

  • Export correlation matrix

    Dear all,

    I am trying to Export my pwcorr Matrix to word. However, all commands I found and tried so far do not work.


    So far I tried:

    Code:
    pwcorr $ylist $xlist, star(.05)
    Code:
    esttab using Correlations.rtf, unstack compress b(2)
    Please can anybody suggest some help on this?

    Thank you very much.
    Best, Sophie

  • #2
    Sophie, see if this example does it?
    Be aware that it can be very hard to answer a question without sample data. You can use the dataex command for this. Type help dataex at the command line.

    When presenting code or results, please use the code delimiters format them. Use the # button on the formatting toolbar, between the " (double quote) and <> buttons.

    Comment


    • #3
      If Weiwens solution doesn't help you, you can try the following:
      Code:
      estpost pwcorr $ylist $xlist, star(.05)
      eststo correlation
      esttab correlation using Correlations.rtf, unstack compress b(2)
      I know you mentioned that esttab doesn't work, but I don't know whether you saved the correlation matrix.

      Comment


      • #4
        Originally posted by Rob Sukaldi View Post
        If Weiwens solution doesn't help you, you can try the following:
        Code:
        estpost pwcorr $ylist $xlist, star(.05)
        eststo correlation
        esttab correlation using Correlations.rtf, unstack compress b(2)
        I know you mentioned that esttab doesn't work, but I don't know whether you saved the correlation matrix.
        It's Ben Jann's solution, not mine. But your observation about saving the correlation matrix is spot on. To the original poster: the esttab and estout commands work with e(b) and e(V) matrices - these are matrices produced by estimation commands. e(b) refers to the parameter estimates, and e(V) to the variance-covariance matrix of the parameters. e(V) gets you the confidence intervals, p-values, and stars in Stata's own tables and in estout.

        Stata normally posts the output from -pwcorr- to r(C). You have to get it into an e(b) matrix if you want to use -esttab-, which is what -estpost correlate- or -eststo- do.
        Be aware that it can be very hard to answer a question without sample data. You can use the dataex command for this. Type help dataex at the command line.

        When presenting code or results, please use the code delimiters format them. Use the # button on the formatting toolbar, between the " (double quote) and <> buttons.

        Comment


        • #5
          Thank you everybody, that gave me a lot of insight!

          I tried the estpost corr command, then store and then esttab, it works perfectly!

          Comment


          • #6
            Originally posted by Rob Sukaldi View Post
            If Weiwens solution doesn't help you, you can try the following:
            Code:
            estpost pwcorr $ylist $xlist, star(.05)
            eststo correlation
            esttab correlation using Correlations.rtf, unstack compress b(2)
            I know you mentioned that esttab doesn't work, but I don't know whether you saved the correlation matrix.
            I tried to replicate this for my own work. Here is the necessary code
            Code:
            eststo clear
            estpost pwcorr tr1 tr2 tr3  tr4a tr4b tr4c 
            eststo corrtr
            esttab using "$texpath/tr_corrtable.tex", replace b(3) p lines not noobs nonum booktabs unstack compress ///
            star (c 0.10 b 0.05 a 0.01) 
            eststo clear
            However after the second line, Stata returns the following

            Code:
            . eststo clear
            
            . estpost pwcorr tr1 tr2 tr3  tr4a tr4b tr4c 
            invalid subcommand
            r(198);
            
            end of do-file
            
            r(198);
            If I run the same without estpost , I would get the following output (which is what I am trying to export)
            Code:
            .  pwcorr tr1 tr2 tr3  tr4a tr4b tr4c
            
                         |      tr1      tr2      tr3     tr4a     tr4b     tr4c
            -------------+------------------------------------------------------
                     tr1 |   1.0000 
                     tr2 |  -0.0779   1.0000 
                     tr3 |   0.6476  -0.0801   1.0000 
                    tr4a |  -0.0532  -0.0047  -0.0940   1.0000 
                    tr4b |  -0.0635   0.0104  -0.0714        .       1.0000 
                    tr4c |  -0.0842   0.0472  -0.1476   0.1882   0.0466   1.0000
            I should note that the error is not because there are missing values for (tr4a, tr4b) . This happens even when I restrict the table to only tr1, tr2 and tr3.
            Thanks.

            Comment


            • #7
              Originally posted by Branon Xerxes View Post

              I tried to replicate this for my own work. Here is the necessary code
              Code:
              eststo clear
              estpost pwcorr tr1 tr2 tr3 tr4a tr4b tr4c
              eststo corrtr
              esttab using "$texpath/tr_corrtable.tex", replace b(3) p lines not noobs nonum booktabs unstack compress ///
              star (c 0.10 b 0.05 a 0.01)
              eststo clear
              However after the second line, Stata returns the following

              Code:
              . eststo clear
              
              . estpost pwcorr tr1 tr2 tr3 tr4a tr4b tr4c
              invalid subcommand
              r(198);
              
              end of do-file
              
              r(198);
              ...
              So, I didn't notice the issue before, but the documentation does indicate that -pwcorr- is not a valid sub-command. -estpost- is like a wrapper calling one of several admissible commands, and it will accept -correlate-, but not -pwcorr-. However, the documentation also says that -estpost correlate- does this:

              estpost correlate varlist [if] [in] [weight] [, matrix nohalf print(#) bonferroni sidak listwise casewise quietly esample ] posts the pairwise correlations between the first variable in varlist and the remaining variables. Alternatively, if the matrix option is specified, all pairwise correlations among the variable in varlist are posted.
              Be aware that it can be very hard to answer a question without sample data. You can use the dataex command for this. Type help dataex at the command line.

              When presenting code or results, please use the code delimiters format them. Use the # button on the formatting toolbar, between the " (double quote) and <> buttons.

              Comment


              • #8
                Just wanted to say a big Thank You to everyone above. Your questions and answers are super helpful! This saves me so much time!

                Comment


                • #9
                  You might also be interested in the one-liner solution of asdoc for exporting correlation matrix to Word. Watch this YouTube Video.

                  For those who are not yet familiar with asdoc, asdoc can be downloaded from SSC and can be used with almost all Stata commands. Here is a short blog post that shows how asdoc can be used with any Stata command http://fintechprofessor.com/2018/02/...basic-example/. You can also watch several YouTube videos that show the use of asdoc https://www.youtube.com/watch?v=zdI6...LwodAk2oqLYhr-

                  Code:
                  * For installation of the stable version 
                  ssc install asdoc
                  
                  * For installation of the new beta version
                  net install asdoc, from(http://fintechprofessor.com) replace
                  help asdoc
                  Regards
                  --------------------------------------------------
                  Attaullah Shah, PhD.
                  Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
                  FinTechProfessor.com
                  https://asdocx.com
                  Check out my asdoc program, which sends outputs to MS Word.
                  For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

                  Comment


                  • #10
                    The new version of asdoc has been uploaded to the SSC. Details of the updates are given in this post
                    https://www.statalist.org/forums/for...ord-from-stata
                    Regards
                    --------------------------------------------------
                    Attaullah Shah, PhD.
                    Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
                    FinTechProfessor.com
                    https://asdocx.com
                    Check out my asdoc program, which sends outputs to MS Word.
                    For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

                    Comment


                    • #11
                      estpost correlate varlist, matrix listwise
                      est store storagename
                      esttab * using filename.tex, unstack not noobs compress

                      Comment


                      • #12

                        If Weiwens solution doesn't help you, you can try the following:
                        Code:
                        estpost pwcorr $ylist $xlist, star(.05) eststo correlation esttab correlation using Correlations.rtf, unstack compress b(2)
                        "estpost pwcorr" gives me an "invalid subcommand" error.

                        Comment


                        • #13
                          The new version of asdoc has been uploaded to the SSC. Details of the updates are given in this post
                          https://www.statalist.org/forums/for...ord-from-stata
                          asdoc writes documentation that is false.

                          In particular, the following code:

                          Code:
                          asdoc pwcorr var1 var2 var3, star(0.05)
                          writes a .docfile which contains the following:

                          *** p<0.01, ** p<0.05, * p<0.1
                          This is not true: 1 star indicates a 5% significance level, not 10%, and there are no ** nor ***

                          Comment


                          • #14
                            I think you are referring the to the table note reported by asdoc at the bottom of the table. Since asdoc allows significance stars for three levels (Stata allows only one) with the pwcorr command, the table note always remain the same, that is
                            Code:
                            *** p<0.01, ** p<0.05, * p<0.1
                            The note was meant for use with the star(all) option (see example below). As you have reported, this might be misleading when someone wishes to report the significance stars for a single level, in which case only one star is reported. I shall fix the table note in a week or so.

                            Example of using option star(all) option.

                            Code:
                            sysuse nlsw88
                            asdoc pwcorr tenure  race, sig star(all) replace
                            Click image for larger version

Name:	Capture.PNG
Views:	1
Size:	14.1 KB
ID:	1674382

                            Regards
                            --------------------------------------------------
                            Attaullah Shah, PhD.
                            Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
                            FinTechProfessor.com
                            https://asdocx.com
                            Check out my asdoc program, which sends outputs to MS Word.
                            For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

                            Comment


                            • #15
                              I found time today and fixed the table note. The new version of asdoc can be installed from my site. Copy and paste the following line in Stata and press enter.

                              Code:
                              net install asdoc, from(http://fintechprofessor.com) replace
                              asdoc pwcorr tenure  race, sig star(.05) replace
                              Click image for larger version

Name:	Capture.PNG
Views:	1
Size:	19.5 KB
ID:	1674403

                              Please note that the above line has to be copied in full. After installation of the new version, then restart Stata.


                              asdocx is now available
                              A more powerful and flexible version of asdoc is now available. I call it asdocx. You may like to check the details here

                              https://fintechprofessor.com/asdocx


                              Please do remember to cite asdoc. To cite:

                              In-text citation
                              Tables were created using asdoc, a Stata program written by Shah (2018).

                              Bibliography
                              Shah, A. (2018). ASDOC: Stata module to create high-quality tables in MS Word from Stata output. Statistical Software Components S458466, Boston College Department of Economics.
                              Regards
                              --------------------------------------------------
                              Attaullah Shah, PhD.
                              Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
                              FinTechProfessor.com
                              https://asdocx.com
                              Check out my asdoc program, which sends outputs to MS Word.
                              For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

                              Comment

                              Working...
                              X