Announcement

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

  • #16
    Vinh, you are picking up quickly but you need to read the documentation (and posts on the list) more carefully. Stata is case-sensitive, so r(rho) is not the same as r(Rho). The former is a scalar; you want the latter.

    If you have three variables, you obviously want three coefficients so you need to extract three cells from r(Rho), i.e., three calls to el(), not just one. You also want to create three new variables, not just one, like you do now. I leave it to you to figure out the rest of the code as I believe this will help you more than me posting the solution. You have the basics down already.

    Just one more word of advice. Do not even try to call rangerun until you get what you want from your program. Likewise, do not even write the program until you figure out how to get what you want interactively after a simple call to spearman.

    Best
    Daniel

    Comment


    • #17
      As suggested by Nick, you might to try something like
      Code:
      webuse grunfeld, clear
      
      capture drop program cor3
      program cor3
        correlate invest mvalue
        generate rho1 = r(rho)
        correlate invest kstock
        generate rho2 = r(rho)
        correlate mvalue kstock
        generate rho3 = r(rho)
      end
      
      rangerun cor3, interval(year . .) by(company)
      Ho-Chuan (River) Huang
      Stata 19.0, MP(4)

      Comment


      • #18
        Although Daniel's advice is excellent, I fear that this thread will converge very slowly without a bigger push.

        There are three bugs in #15.

        1. As Daniel points out in #16, you need to look for results in r(Rho) not r(rho).

        2. As I pointed out in #10 and as Daniel also underlines and as River exemplifies in #17 you need a new variable for each correlation.

        3. Diagonal elements such as (3, 3) of the correlation matrix are not of use or interest: they just contain correlations of 1.


        Code:
        webuse grunfeld, clear
        
        capture drop program cor3
        program cor3
          spearman invest mvalue kstock
          generate rho_im= el(r(Rho), 2, 1)
          generate rho_ik= el(r(Rho), 3, 1)
          generate rho_km= el(r(Rho), 3, 2)
        end
        
        rangerun cor3, interval(year . .) by(company)
        
        tabdisp company, c(rho*)
        
        ----------------------------------------------
          company |     rho_im      rho_ik      rho_km
        ----------+-----------------------------------
                1 |   .5804511    .8661654    .3052632
                2 |    .485897    .5009403    .0300752
                3 |   .2345865    .8300752    .0300752
                4 |   .6616541    .7318541    .1496803
                5 |    .712782     .712782     .875188
                6 |   .9233083    .9428571    .9669173
                7 |  -.0015038    .8977444    .0827068
                8 |   .7172933    .7338346    .7037594
                9 |   .6616541    .8135338    .4721805
               10 |   .0781955    .7729324    .1398496
        ----------------------------------------------
        Last edited by Nick Cox; 05 Jan 2018, 05:15.

        Comment


        • #19
          Dear all,

          Thank you very much for your suggestions. I really appreciate all your help.

          The code works well now.

          Best,

          Vinh

          Comment

          Working...
          X