Announcement

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

  • How to generate a pearson correlation matrix in STATA 15?

    I am new to STATA data analysis ? I have fair working understanding of SPSS. I need to run a simple pearson correlation model with all the significance indicated.
    The code I ran
    pwcorr var 1 var 2 var 3
    estpost correlate var 1 var 2 var 3
    esttab ., not unstack
    estimates table, star(.05 .01 .001)

    STATA - Output
    Variables (1) (2) (3) (4)
    (1) 1.000
    (2) 0.250 1.000
    (3) 0.262 0.387 1.000
    Var (1)
    ----------------------------
    Var 1 -0.0709
    Var 2 -0.137*
    Var 3 0.183**

    This code only gives the significance with the first variable only in a separate table, significances for the other variables are not indicated.


    However when i generate the pearson correlation in SPSS. I can get the significance level printed within the table itself.
    SPSS Results
    Variables (1) (2) (3)
    (1) 1.000
    (2) 0.980** 1.000
    (3) 0.0001** 0.000 1.000
    (4) 0.195* 0.158*** -0.006

    Kindly someone teach me the code i need to run to generate the table generated by SPSS in STATA.
    Thank you

  • #2
    Your code isn't legal, let alone reproducible, as spaces are not allowed in variable names.

    Also, your results make no sense unless the correlations are based on extremely different sample sizes. For example if 0.158 deserves *** then all stronger correlations do too, modulo sample size.

    Stata (not STATA please) allows printing of significance levels and sample sizes using pwcorr, which are immensely more informative than arbitrary stars.

    Please do as we ask and study the FAQ Advice (#12, #18) before posting.

    All that said I guess there are community-contributed commands that may do what you want, but I don't follow them to give specific recommendations, and other replies should be able to help more in your quest.

    Comment


    • #3
      Also, the p-values returned by -pwcorr- are from a test that, if I recall correctly, the stated correlation coefficient is zero. Say you have a Pearson correlation of 0.10, and the p-value for that coefficient is less than 0.05. What does that tell you? Basically, that we can reject the null hypothesis that the correlation coefficient is zero. But a Pearson correlation of 0.10 is extremely weak correlation. In my field, Pearson correlations of 0.30 or so are also regarded as weak. If I am looking at correlations between two tests that measure the same subjective construct, I am looking for 0.60 at the very least. I would be more concerned over the magnitudes of the correlations. If my sample were so small that a correlation of 0.60 wouldn't get starred, then the sample is too small.

      If it's very, very important to you or your collaborators to star all the coefficients (e.g. you are submitting to a journal that will reject articles unless you do this), then you can follow Ben Jann's example for how to do this. He is the author of the -esttab- command (note: to other readers, this is available on the Statistical Software Components website).
      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


      • #4
        Hi Shan,

        Not sure if this will work for you exactly, but if you change your code to:

        Code:
        pwcorr var1 var2 var3, star(.05)
        It will star variables sig at p<.05 in the table itself. However, it won't do the "**sig at p<.01, *** sig at p<p.001" part that you want.

        The corr2docx (SSC) might be your best bet -- it has an explicit star() option. It defaults to *** p<0.01, ** p<0.05, * p<0.1, but you can change it.

        You might also find the following user-contribute commands helpful: asdoc, pwcorrs (note the "s"), corrtab, and mkcorr.

        Also, there is a helpful video on how to create a publication quality table of correlations with asdoc on YouTube here
        Last edited by David Benson; 05 Nov 2018, 12:47.

        Comment

        Working...
        X