Announcement

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

  • Plotting a histogram with multiple correlations

    Hi, I have a dataset with columns named i, j, product, v, value.


    How can I calculate the correlation coefficient between v and value for each triple of i-j-product, and then plot what I get with a histogram?

    I know how to get the correlation matrix for each group, but not how to use that to get the plot. This is what I tried:

    Code:
    bysort i j product: pwcorr v value
    gen correlation = r(rho)
    Thanks!

  • #2
    To get a histogram, you need the correlations in a variable, but that approach can find only one correlation left in memory after pwcorr, which is why you are asking the question.

    Here is a silly example to show some technique. I use rangestat from SSC, which must be installed before you can use it. Here the histogram is not interesting enough to show, but I am optimistic that this is what you're seeking.

    If you have many correlations, and some are based on very small samples, I would keep a close eye on the sample sizes used, which are automatically generated too.


    Code:
    webuse nlswork, clear 
    
    egen group = group(msp nev_mar collgrad)
    rangestat (corr) ln_wage age, int(group 0 0)
    tabdisp group, c(msp nev_mar collgrad corr_*)
    
    egen tag = tag(group) 
    
    * options to suit 
    histogram corr_x if tag
    So, although you don't give a data example, something like this should help:


    Code:
    egen group = group(i j product)
    ssc install rangestat 
    rangestat (corr) v value, int(group 0 0)
    tabdisp group, c(i j product corr_*)
    
    * select just one observation from each group, to avoid multiple counting
    egen tag = tag(group) 
    
    * add options to suit 
    histogram corr_x if tag

    Comment


    • #3
      Nick Cox, thank you so much!
      Last edited by Arthur Carvalho Brito; 23 Aug 2023, 08:43.

      Comment


      • #4
        The fix is to ignore it. You could fire up list to show you the results, but you wouldn't want (I guess) really to look through thousands of them.

        Comment


        • #5
          Nick Cox thank you, you are right in that I don't need to look at the individual values

          Comment

          Working...
          X