Announcement

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

  • Plotting Spearman's rho Correlation Coefficients

    Hello Stata Users,

    My goal is to produce six plots of Spearman's rho correlation coefficient, since I have six years of data. In addition, I want to group the coeff by another categorical variable (wind_levels).

    I can manually enter the output, and then produce a plot, but I am hoping there is a faster and more efficient way.

    Thanks in advance!
    Elizabeth


  • #2
    What goes on what axis? Spearman's correlation just correlates the ranks on two variables. So, there is a scatter plot and I suppose you could plot either the original data or the ranks. Then there is one Spearman result for each scatter plot.

    Not knowing what plot you mean, and with almost no hint on your variable names or data structure, it is hard to suggest any code.

    Comment


    • #3
      Let me provide more detail.

      I first run the spearman command between electricity_var wind_production_levels


      I have also tried bysort year wind_categorical_var : spearman electricity_var wind_production_levels

      The wind_categorical_var has 12 levels.

      I would like to produce a graph that on the Y axis is the rho between electricity_var wind_gen_var and on the X would be the 12 levels (i.e., 12 rhos per graph).

      Since there are six years of data, I would like to produce six plots, so that I can compare the rho coeff. across groups and years.

      My apologies for the vagueness in the last description. I guess I was assuming that you could read minds.

      Thanks,
      Elizabeth

      Comment


      • #4
        Code:
        sysuse nlsw88, clear
        statsby rho=r(rho), by(race) : spearman grade wage
        twoway bar rho race, ylab(0(.2).6) xlab(1/3, val)
        ---------------------------------
        Maarten L. Buis
        University of Konstanz
        Department of history and sociology
        box 40
        78457 Konstanz
        Germany
        http://www.maartenbuis.nl
        ---------------------------------

        Comment


        • #5
          As Elizabeth's example has a two-way structure, let's extend Maarten's code a little.


          Code:
          sysuse nlsw88, clear
          statsby rho=r(rho), by(race collgrad) : spearman grade wage
          label var rho "Spearman rank correlation" 
          graph hbar (asis) rho, ylab(0(.2)1) over(race) over(collgrad)
          For anything complicated, bars are better horizontal.

          Comment


          • #6
            Once again, Thank you. It worked perfectly.

            Comment

            Working...
            X