Announcement

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

  • Finding maximum/minimum value across multiple correlation tables

    Dear Statalist-Users,

    I would like to kindly ask for your help again. For my analysis of overall ten years, I have been asked by reviewers to provide a table which shows the range of correlation values over the single years. So e.g. for the correlation of independent_variable_1 and independent_variable_2 the correlation might range from 0.04** in e.g. 2001 (the minimum value over all years) to 0.34*** in e.g. 2010 (the maximum value over all yeaers). I would then like to have a matrix which tells me for every combination the range of values, like (0.04**; 0.34***). I have started doing this by hand, but it takes forever and is very prone to silly mistakes and I would like to at least try if I can let Stata do it.


    I have 10 matrices computed by -pwcorr-, m1 to m10, which include all correlation coefficients for every single year. I have overall 15 independent variables. Now I think a loop would be necessary, which loops over the same cells in the table and seeks the maximum and minimum value.


    So 10 tables like this:

    For year == 2001, stored as "matrix m1"
    indep_var_1 Indep_var_2 Indep_var_3 ... indep_var_15
    ind_var_1 1
    ind_var_2 0.04 1
    ind_var_3 0.30 0.02 1
    ...
    ind_var_15 0.12 0.45 0.23 1

    [...]

    For year == 2010, stored as "matrix m10"
    indep_var_1 Indep_var_2 Indep_var_3 ...
    ind_var_1 1
    ind_var_2 0.34 1
    ind_var_3 0.25 0.05 1
    ...

    I can then add the significance values by hand, but at least the numbers would be correct.

    I know that I can access every cell like this:

    HTML Code:
    forvalues i = 1/15 {
        forvalues j = 1/15 {
                matrix C[`i',`j']= [...]
        }
    }
            
    matrix list C
    I am unsure about how to go step by step through every one of the matrices. I think I should add "foreach var in varlist matrix m1 m2 m3 [..] {", but "matrix m1" always returns as unknown.

    I have been looking into Mata and whether there are already questions on it, but could not find anything.

    Could you provide me with any help?
    Last edited by sladmin; 06 Feb 2018, 09:36. Reason: anonymize user

  • #2
    Mata is great, but given that you have the matrices in Stata, this boils down to loops over matrices, over rows and over columns.

    Here I use Mata just to set up sandbox matrices. They aren't even correlation matrices, but that is irrelevant to the principle. But for correlations, it will be reasonable to initialise the min at 1 and max at -1 and change your mind whenever you see more extreme values than those so far seen.


    Code:
    * sandbox to play
    set seed 2803
    
    mata:
    
    m1 = 2 :* runiform(5,5) :- 1
    m1 = (m1 :+ m1') :/ 2
    
    m2 = 2 :* runiform(5,5) :- 1
    m2 = (m2 :+ m2') :/ 2
    
    st_matrix("m1", m1)
    st_matrix("m2", m2)
    
    end
    
    * your #rows #columns #matrices will differ
    
    matrix min = J(5,5,1)
    matrix max = J(5,5,-1)
    
    forval k = 1/2 {
        forval i = 1/5 {
            forval j = 1/5 {
                matrix min[`i', `j'] = min(min[`i', `j'], m`k'[`i', `j'])
                matrix max[`i', `j'] = max(max[`i', `j'], m`k'[`i', `j'])
            }
        }
    }
    
    . mat li m1, format(%3.2f)
    
    symmetric m1[5,5]
           c1     c2     c3     c4     c5
    r1   0.85
    r2  -0.65  -0.64
    r3   0.57   0.26  -0.81
    r4  -0.64  -0.53  -0.86   0.16
    r5   0.01   0.24  -0.05  -0.59  -0.08
    
    . mat li m2, format(%3.2f)
    
    symmetric m2[5,5]
           c1     c2     c3     c4     c5
    r1  -0.25
    r2  -0.39   1.00
    r3   0.29   0.75  -0.77
    r4  -0.46  -0.71  -0.56   0.46
    r5  -0.47  -0.29   0.60  -0.58  -0.54
    
    . mat li min, format(%3.2f)
    
    symmetric min[5,5]
           c1     c2     c3     c4     c5
    r1  -0.25
    r2  -0.65  -0.64
    r3   0.29   0.26  -0.81
    r4  -0.64  -0.71  -0.86   0.16
    r5  -0.47  -0.29  -0.05  -0.59  -0.54
    
    . mat li max, format(%3.2f)
    
    symmetric max[5,5]
           c1     c2     c3     c4     c5
    r1   0.85
    r2  -0.39   1.00
    r3   0.57   0.75  -0.77
    r4  -0.46  -0.53  -0.56   0.46
    r5   0.01   0.24   0.60  -0.58  -0.08




    Last edited by Nick Cox; 11 May 2017, 04:08.

    Comment


    • #3
      Nick Cox, this is really great, thank you so much! May I add one question: I wasn't able to check your code fully yet, because at the moment my matrices are empty. I saved my -pwcorr- results in the following way:

      Code:
      pwcorr [variables] if year==2014
      matrix m14 = r(C)
      When I use -matrix list- the matrix appears to be full of zeros ("0.00"). I red up on -format- and again on how to store results in -pwcorr-, but I cannot find the mistake.

      and the end-result then looks of course empty as well:

      HTML Code:
      . mat li min, format(%3.2f)
      
      symmetric min[15,15]
             c1    c2    c3    c4    c5    c6    c7    c8    c9   c10   c11   c12   c13   c14   c15
       r1  0.00
       r2  0.00  0.00
       r3  0.00  0.00  0.00
       r4  0.00  0.00  0.00  0.00
       r5  0.00  0.00  0.00  0.00  0.00
       r6  0.00  0.00  0.00  0.00  0.00  0.00
       r7  0.00  0.00  0.00  0.00  0.00  0.00  0.00
       r8  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
       r9  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
      r10  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
      r11  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
      r12  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
      r13  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
      r14  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
      r15  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  1.00


      The mistake is most likely in "matrix m[k]= r(C)", but what could be wrong with it?

      Comment


      • #4
        Thanks for the thanks, but you're not showing the exact and complete code you used, so we can't easily comment on what is wrong.

        Nothing in my code implies that you should be using

        Code:
        matrix m[k]= r(C)
        and indeed that is not even legal syntax as in Stata two subscripts are mandatory for matrix cells.

        I appreciate that your matrices are bigger (and more numerous) than you want to post but I need more than #3 to help further.

        Comment


        • #5
          So I might need something like "matrix m14[i,j] = r(C)" then?

          You are right, here is the full code. I just excluded the variable names and replaced them with "var" or a variation of "xx". It is a long output, but I rather post too much than too little:

          Code:
          set more off
          preserve
          keep if !missing[var]
          pwcorr [var] if syear==2014
          matrix m14 = r(C)
          pwcorr [var] if syear==2013
          matrix m13 = r(C)
          pwcorr [var] if syear==2012
          matrix m12 = r(C)
          pwcorr [var] if syear==2011
          matrix m11 = r(C)
          pwcorr [var] if syear==2010
          matrix m10 = r(C)
          pwcorr [var] if syear==2009
          matrix m9 = r(C)
          pwcorr [var] if syear==2008
          matrix m8 = r(C)
          pwcorr [var] if syear==2007
          matrix m7 = r(C)
          pwcorr [var] if syear==2006
          matrix m6 = r(C)
          pwcorr [var] if syear==2005
          matrix m5 = r(C)
          
          
          
          matrix min = J(15,15,1)
          matrix max = J(15,15,-1)
          
          forval k = 5/14 {
              forval i = 1/15 {
                  forval j = 1/15 {
                      matrix min[`i', `j'] = min(min[`i', `j'], m`k'[`i', `j'])
                      matrix max[`i', `j'] = max(max[`i', `j'], m`k'[`i', `j'])
                  }
              }
          }
          
          mat li m14, format(%3.2f)
          
          mat li m8, format(%3.2f)
          
          mat li min, format(%3.2f)
          
          mat li max, format(%3.2f)
          
          
          restore
          The output (not including all matrices, since they are repetitive):

          HTML Code:
          set more off
          
          . preserve
          
          . keep if !missing(xx)   /*to keep sample size across all -pwcorr- constant*/
          (10,765 observations deleted)
          
          . pwcorr xx if syear==2014
          
                       |    xx       xx      x      x   x    x    x
          -------------+---------------------------------------------------------------
                 x |   1.0000
                   x |   0.1831   1.0000
                  x |  -0.0377  -0.1623   1.0000
                   x |  -0.0745  -0.2026   0.0165   1.0000
                 x |  -0.0427   0.0579  -0.1816   0.0468   1.0000
                 x |  -0.0720  -0.2280  -0.1526   0.0622  -0.1137   1.0000
                 x |   0.0256   0.1644  -0.0777  -0.0370   0.1235  -0.2071   1.0000
                  x |   0.0514   0.1904  -0.1035  -0.0588   0.1147  -0.0789   0.3633
                 x |   0.0241  -0.0146  -0.0981   0.2975   0.3370  -0.0669   0.1713
              x |  -0.0214  -0.1743   0.1314   0.8892   0.0137   0.0418  -0.0383
                 x |  -0.0054   0.1039  -0.1727  -0.1438   0.0239   0.0291   0.0487
                 x |   0.3076   0.2262  -0.0272  -0.0035  -0.0867  -0.0920   0.0064
               x |   0.0264  -0.0013  -0.0889   0.4328   0.0482   0.0776  -0.0351
            x |  -0.0382  -0.0219   0.0438  -0.0330   0.0399   0.0406  -0.0120
                x |  -0.1239  -0.1634   0.0361   0.0653   0.0652   0.0430  -0.0084
          
                       |    x    x  x     x     x  x x
          -------------+---------------------------------------------------------------
                  x |   1.0000
                 x|   0.1255   1.0000
               x  -0.0560   0.2776   1.0000
                 x|  -0.0730   0.0170  -0.1956   1.0000
                 x|   0.1105  -0.0444   0.0378  -0.0505   1.0000
              x |  -0.0241   0.2139   0.3727   0.2565   0.1345   1.0000
            x |  -0.0041   0.0218  -0.0379   0.0565  -0.0988   0.0930   1.0000
               x |  -0.0679   0.1171   0.0610  -0.0331  -0.2087  -0.0521  -0.2752
          
                       |   x
          -------------+---------
                x |   1.0000
          
          . matrix m14 = r(C)
           
          . /*and the exact same procedure for all other tables*/
          .
          . matrix min = J(15,15,1)
          
          . matrix max = J(15,15,-1)
          
          .
          . forval k = 5/14 {
            2.     forval i = 1/15 {
            3.         forval j = 1/15 {
            4.             matrix min[`i', `j'] = min(min[`i', `j'], m`k'[`i', `j'])
            5.             matrix max[`i', `j'] = max(max[`i', `j'], m`k'[`i', `j'])
            6.         }
            7.     }
            8. }
          
          .
          . mat li m14, format(%3.2f)
          
          symmetric m14[15,15]
                         x        x        x        x     x      x     x       x      x   x       x      x    x
                x       0.00       0.00
                x       0.00       0.00       0.00
               x       0.00       0.00       0.00       0.00
              x      0.00       0.00       0.00       0.00       0.00
             x       0.00       0.00       0.00       0.00       0.00       0.00
             x       0.00       0.00       0.00       0.00       0.00       0.00       0.00
              x       0.00       0.00       0.00       0.00       0.00       0.00       0.00       0.00
             x       0.00       0.00       0.00       0.00       0.00       0.00       0.00       0.00       0.00
            x       0.00       0.00       0.00       0.00       0.00       0.00       0.00       0.00       0.00       0.00
              x     0.00       0.00       0.00       0.00       0.00       0.00       0.00       0.00       0.00       0.00       0.00
              x      0.00       0.00       0.00       0.00       0.00       0.00       0.00       0.00       0.00       0.00       0.00       0.00
            x       0.00       0.00       0.00       0.00       0.00       0.00       0.00       0.00       0.00       0.00       0.00       0.00       0.00
          x       0.00       0.00       0.00       0.00       0.00       0.00       0.00       0.00       0.00       0.00       0.00       0.00       0.00       0.00
             x       0.00       0.00       0.00       0.00       0.00       0.00       0.00       0.00       0.00       0.00       0.00       0.00       0.00       0.00       1.00
          
          .
          
          . mat li min, format(%3.2f)
          
          symmetric min[15,15]
                 c1    c2    c3    c4    c5    c6    c7    c8    c9   c10   c11   c12   c13   c14   c15
           r1  0.00
           r2  0.00  0.00
           r3  0.00  0.00  0.00
           r4  0.00  0.00  0.00  0.00
           r5  0.00  0.00  0.00  0.00  0.00
           r6  0.00  0.00  0.00  0.00  0.00  0.00
           r7  0.00  0.00  0.00  0.00  0.00  0.00  0.00
           r8  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
           r9  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
          r10  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
          r11  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
          r12  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
          r13  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
          r14  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
          r15  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  1.00
          
          .
          . mat li max, format(%3.2f)
          
          symmetric max[15,15]
                 c1    c2    c3    c4    c5    c6    c7    c8    c9   c10   c11   c12   c13   c14   c15
           r1  0.00
           r2  0.00  0.00
           r3  0.00  0.00  0.00
           r4  0.00  0.00  0.00  0.00
           r5  0.00  0.00  0.00  0.00  0.00
           r6  0.00  0.00  0.00  0.00  0.00  0.00
           r7  0.00  0.00  0.00  0.00  0.00  0.00  0.00
           r8  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
           r9  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
          r10  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
          r11  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
          r12  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
          r13  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
          r14  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
          r15  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  1.00
          
          .
          .
          . restore
          
          .
          end of do-file
          Last edited by sladmin; 06 Feb 2018, 09:37. Reason: anonymize user

          Comment


          • #6
            I can't see anything wrong with the code. I have to be alarmed that m14 is all zeros. If one matrix is full of garbage it won't be ignored by the code.

            You need to check all the other input matrices too.

            Comment


            • #7
              All other matrices return zero as well.

              I have found out why it goes wrong: I seem to have too many variables in -pwcorr-; once I reduce to eight variables (or less), it works. I increased -matsize-, but that did not change anything (and the default is clearly enough for a 15x15 matrix).

              Do you maybe have an idea of why this might be the reason of error?

              Edit: I found more. This is my list of variables and when I just take one or two out of them, this is what happens:

              HTML Code:
              . pwcorr ev dr sex age agree neuro extra /*open consc*/ workexp chil linc married migration region if syear==2014
              
              | ev dr sex age agree neuro extra
              -------------+---------------------------------------------------------------
              ev | 1.0000
              dr | 0.1753 1.0000
              sex | -0.1198 -0.0908 1.0000
              age | 0.0239 -0.1170 0.0070 1.0000
              agree | 0.0604 0.0804 -0.1477 0.0389 1.0000
              neuro | -0.1094 -0.2397 -0.2029 0.0118 -0.1105 1.0000
              extra | 0.0907 0.1920 -0.1172 -0.0655 0.0680 -0.1523 1.0000
              workexp | 0.0204 -0.0524 0.1726 0.8463 -0.0077 -0.0513 -0.0231
              chil | 0.0555 0.1183 -0.1990 -0.1766 0.0363 -0.0321 0.0977
              linc | 0.1762 0.1590 -0.0656 0.0428 -0.0358 -0.0978 0.0778
              married | 0.0863 0.1719 -0.0843 0.3638 0.0617 0.0126 0.0217
              migration | -0.0672 0.0613 0.0654 -0.0025 0.0506 0.0250 0.0082
              region | -0.1007 -0.1384 0.0223 0.0910 0.0092 0.0556 -0.0839
              
              | workexp chil linc married migrat~n region
              -------------+------------------------------------------------------
              workexp | 1.0000
              chil | -0.2312 1.0000
              linc | 0.0884 0.0024 1.0000
              married | 0.2815 0.2764 0.1853 1.0000
              migration | -0.0448 0.0568 -0.1067 0.1308 1.0000
              region | 0.0462 -0.0539 -0.1682 -0.0662 -0.2727 1.0000
              
              . matrix m14 = r(C)
              
              .
              . mat li m14
              
              symmetric m14[13,13]
              ev dr sex age agree neuro extra workexp chil linc married migration region
              ev 0
              dr 0 0
              sex 0 0 0
              age 0 0 0 0
              agree 0 0 0 0 0
              neuro 0 0 0 0 0 0
              extra 0 0 0 0 0 0 0
              workexp 0 0 0 0 0 0 0 1
              chil 0 0 0 0 0 0 0 -.23118918 1
              linc 0 0 0 0 0 0 0 .08840243 .0024249 1
              married 0 0 0 0 0 0 0 .28149498 .27641853 .18525371 1
              migration 0 0 0 0 0 0 0 -.04479515 .05677316 -.10672552 .13080006 1
              region 0 0 0 0 0 0 0 .04621034 -.053887 -.16821264 -.06619564 -.27269534 1
              Does this maybe help in order to find why my code does not work yet?
              Last edited by sladmin; 06 Feb 2018, 09:37. Reason: anonymize user

              Comment


              • #8
                Every time we solve a puzzle, another one emerges.

                I can't explain or reproduce your problem with pwcorr

                Let's back up and try a different route. corrci from Stata Journal lets you save correlations to datasets. You can merge those with a dataset of sample sizes and then work out minimum and maximum correlations directly. You can also work out P-values in one fell swoop.

                Here's token code. You must install
                corrci first.


                Code:
                webuse grunfeld, clear
                
                * loop over years, saving correlations
                local files
                
                quietly forval t=1/20 {
                    corrci invest mvalue kstock if time == `t', saving(mycorr`t', replace)
                    local files `files' mycorr`t'
                }
                
                * get sample sizes
                keep if !missing(invest, mvalue, kstock)
                contract time, freq(n)  
                save samplesize, replace
                
                * now put correlations together
                clear
                gen time = .
                quietly forval t = 1/20 {
                    append using mycorr`t'
                    replace time = `t' if missing(time)
                }
                
                * merge in sample sizes
                merge m:1 time using samplesize
                assert _merge == 3
                drop _merge
                
                * P-values all at once
                gen p = min(2 * ttail(n-2, abs(r)*sqrt(n-2)/ sqrt(1-r^2)),1)
                
                * what did we get
                format r %4.3f
                format p %5.4f
                list, sepby(time)
                
                table var1 var2, c(min r max r)


                with some results:


                Code:
                . list, sepby(time)
                
                     +----------------------------------------------------------------------+
                     | time     var1     var2        r       lower      upper    n        p |
                     |----------------------------------------------------------------------|
                  1. |    1   invest   mvalue    0.930    .7254378    .983695   10   0.0001 |
                  2. |    1   invest   kstock   -0.233    -.752482    .464427   10   0.5162 |
                  3. |    1   mvalue   kstock   -0.250   -.7598396   .4508432   10   0.4867 |
                     |----------------------------------------------------------------------|
                  4. |    2   invest   mvalue    0.834    .4305262    .959703   10   0.0027 |
                  5. |    2   invest   kstock   -0.142   -.7081662   .5356946   10   0.6961 |
                  6. |    2   mvalue   kstock   -0.138   -.7061485   .5385663   10   0.7043 |
                     |----------------------------------------------------------------------|
                  7. |    3   invest   mvalue    0.808    .3643102   .9529957   10   0.0046 |
                  8. |    3   invest   kstock    0.278   -.4264025   .7723403   10   0.4371 |
                  9. |    3   mvalue   kstock    0.222   -.4735774   .7473483   10   0.5370 |
                     |----------------------------------------------------------------------|
                 10. |    4   invest   mvalue    0.797     .335503   .9498857   10   0.0058 |
                 11. |    4   invest   kstock    0.551   -.1203892   .8765363   10   0.0988 |
                 12. |    4   mvalue   kstock    0.383   -.3246088   .8160252   10   0.2741 |
                     |----------------------------------------------------------------------|
                 13. |    5   invest   mvalue    0.887    .5826837   .9731261   10   0.0006 |
                 14. |    5   invest   kstock    0.463   -.2357255   .8458403   10   0.1783 |
                 15. |    5   mvalue   kstock    0.307   -.3999361   .7849051   10   0.3882 |
                     |----------------------------------------------------------------------|
                 16. |    6   invest   mvalue    0.906    .6417851   .9777108   10   0.0003 |
                 17. |    6   invest   kstock    0.354    -.354874   .8042689   10   0.3159 |
                 18. |    6   mvalue   kstock    0.242   -.4574525    .756298   10   0.5009 |
                     |----------------------------------------------------------------------|
                 19. |    7   invest   mvalue    0.919    .6864108   .9809726   10   0.0002 |
                 20. |    7   invest   kstock    0.401    -.306191   .8227456   10   0.2512 |
                 21. |    7   mvalue   kstock    0.324   -.3838967   .7920733   10   0.3610 |
                     |----------------------------------------------------------------------|
                 22. |    8   invest   mvalue    0.924    .7054951   .9823185   10   0.0001 |
                 23. |    8   invest   kstock    0.419    -.286087   .8297378   10   0.2281 |
                 24. |    8   mvalue   kstock    0.402   -.3045584   .8233265   10   0.2492 |
                     |----------------------------------------------------------------------|
                 25. |    9   invest   mvalue    0.914     .669186    .979733   10   0.0002 |
                 26. |    9   invest   kstock    0.319   -.3884048   .7900909   10   0.3685 |
                 27. |    9   mvalue   kstock    0.261   -.4413027   .7648282   10   0.4668 |
                     |----------------------------------------------------------------------|
                 28. |   10   invest   mvalue    0.934    .7374426   .9845093   10   0.0001 |
                 29. |   10   invest   kstock    0.123   -.5491931   .6985015   10   0.7351 |
                 30. |   10   mvalue   kstock    0.065   -.5888932   .6671689   10   0.8590 |
                     |----------------------------------------------------------------------|
                 31. |   11   invest   mvalue    0.951    .8014982   .9886812   10   0.0000 |
                 32. |   11   invest   kstock    0.155   -.5260038   .7148287   10   0.6691 |
                 33. |   11   mvalue   kstock    0.115   -.5550436   .6941662   10   0.7525 |
                     |----------------------------------------------------------------------|
                 34. |   12   invest   mvalue    0.946    .7820257   .9874429   10   0.0000 |
                 35. |   12   invest   kstock    0.266   -.4363839   .7673448   10   0.4568 |
                 36. |   12   mvalue   kstock    0.277   -.4266942   .7721964   10   0.4376 |
                     |----------------------------------------------------------------------|
                 37. |   13   invest   mvalue    0.944    .7751963   .9870025   10   0.0000 |
                 38. |   13   invest   kstock    0.601   -.0456558   .8928705   10   0.0660 |
                 39. |   13   mvalue   kstock    0.640    .0170636   .9049056   10   0.0463 |
                     |----------------------------------------------------------------------|
                 40. |   14   invest   mvalue    0.887    .5830573   .9731561   10   0.0006 |
                 41. |   14   invest   kstock    0.584   -.0716016   .8874664   10   0.0760 |
                 42. |   14   mvalue   kstock    0.695    .1159424   .9213759   10   0.0257 |
                     |----------------------------------------------------------------------|
                 43. |   15   invest   mvalue    0.928      .71853   .9832216   10   0.0001 |
                 44. |   15   invest   kstock    0.662    .0557474   .9116822   10   0.0370 |
                 45. |   15   mvalue   kstock    0.743    .2124211   .9350706   10   0.0139 |
                     |----------------------------------------------------------------------|
                 46. |   16   invest   mvalue    0.926     .710229    .982648   10   0.0001 |
                 47. |   16   invest   kstock    0.670     .070631   .9141712   10   0.0339 |
                 48. |   16   mvalue   kstock    0.741    .2086224   .9345693   10   0.0142 |
                     |----------------------------------------------------------------------|
                 49. |   17   invest   mvalue    0.929    .7221689   .9834715   10   0.0001 |
                 50. |   17   invest   kstock    0.636    .0102706   .9036672   10   0.0482 |
                 51. |   17   mvalue   kstock    0.756     .240148   .9386439   10   0.0115 |
                     |----------------------------------------------------------------------|
                 52. |   18   invest   mvalue    0.918    .6845347   .9808387   10   0.0002 |
                 53. |   18   invest   kstock    0.727    .1787477   .9305239   10   0.0173 |
                 54. |   18   mvalue   kstock    0.824    .4029323   .9569793   10   0.0034 |
                     |----------------------------------------------------------------------|
                 55. |   19   invest   mvalue    0.941    .7650061   .9863394   10   0.0000 |
                 56. |   19   invest   kstock    0.858    .4954627   .9657431   10   0.0015 |
                 57. |   19   mvalue   kstock    0.882     .568772       .972   10   0.0007 |
                     |----------------------------------------------------------------------|
                 58. |   20   invest   mvalue    0.925    .7076629   .9824696   10   0.0001 |
                 59. |   20   invest   kstock    0.920    .6886023   .9811286   10   0.0002 |
                 60. |   20   mvalue   kstock    0.894    .6047162   .9748722   10   0.0005 |
                     +----------------------------------------------------------------------+
                
                .
                . table var1 var2, c(min r max r)
                
                --------------------------
                          |      var2    
                     var1 | kstock  mvalue
                ----------+---------------
                   invest | -0.233   0.797
                          |  0.920   0.951
                          |
                   mvalue | -0.250        
                          |  0.894        
                --------------------------

                Comment

                Working...
                X