Announcement

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

  • Correlation between variables

    Hello Statalists,
    Please, could anyone help with the correct command?
    I have two datasets measuring the weight of a product using two different methods. I want to know the correlation between this two variables called 'grams1' and 'grams2'.
    The two data sets have the same id variable, the same time var and the grams var differ between both data. The two data sets samples and my codes are below. Is this the correct way to assess the correlation between this two variables? What I expect is that the correlation is very high indicating that both weighting methods are similar and yield close weight in grams.
    Thank you!

    Grams1.dta

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(id grams1 time)
    11 13 1
    11 12 2
    11 19 3
    22 21 1
    22 10 2
    22 15 3
    33 35 1
    33 29 2
    33 20 3
    end

    Grams2.dta

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(id grams2 time)
    11   21 1
    11   12 2
    11   18 3
    22 21.5 1
    22   11 2
    22 14.7 3
    33   36 1
    33   29 2
    33 20.6 3
    end

    I then tried to do the following:
    Code:
    use grams1,clear
    sort id time
    merge 1:1 id time using grams2
    I get the following merged dataset:
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(id grams1 time grams2) byte _merge
    11 13 1   21 3
    11 12 2   12 3
    11 19 3   18 3
    22 21 1 21.5 3
    22 10 2   11 3
    22 15 3 14.7 3
    33 35 1   36 3
    33 29 2   29 3
    33 20 3 20.6 3
    end
    label values _merge _merge
    label def _merge 3 "matched (3)", modify
    And finally I did:
    Code:
    pwcorr grams1 grams2, star(0.01)

  • #2
    Yes, that will do it.

    Since you are only working with 2 variables, you can also use -corr- instead of -pwcorr-; everything will come out the same.

    Comment


    • #3
      Many thanks Clyde!

      Comment


      • #4
        the correlation is very high indicating that both weighting methods are similar and yield close weight in grams
        This is not what correlation measures. It measures linearity of relationship, not agreement. Consider that y = a + b x and x are correlated at 1 so long as b is any positive value whatsoever. But y is not equal to x unless a = 0 and b = 1 and y is not close to x without a being comparatively small and b being close to 1.


        Concordance correlation is a measure of agreement. In your case it is high too.


        Code:
         . concord grams1 grams2 
        
        Concordance correlation coefficient (Lin, 1989, 2000):
        
         rho_c   SE(rho_c)   Obs    [   95% CI   ]     P        CI type
        ---------------------------------------------------------------
         0.937     0.046       9     0.847  1.026    0.000   asymptotic
                                     0.753  0.985    0.000  z-transform
        
        Pearson's r =  0.946  Pr(r = 0) = 0.000  C_b = rho_c/r =  0.990
        Reduced major axis:   Slope =     1.025   Intercept =    -1.595
        
        Difference = grams1 - grams2
        
                Difference                 95% Limits Of Agreement
           Average     Std Dev.             (Bland & Altman, 1986)
        ---------------------------------------------------------------
            -1.089       2.670                 -6.322      4.144
        
        Correlation between difference and mean = 0.076
        
        Bradley-Blackwood F = 0.679 (P = 0.53773)
        I used concord from the Stata Journal.

        Comment


        • #5
          Many thanks Nick Cox!

          Comment

          Working...
          X