Announcement

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

  • Incorporates sampling weight in rank correlation

    Dear list,

    I guess this is an old question on this forum, but so far I have not found any solutions yet. Briefly speaking, I want to incorporate weight into my calculation of tie-corrected rank correlation, but neither ktau or spearman supports sampling weight. I would like to propose a solution here and hear about your opinion (I am not sure if there is any literature supporting this approach, or if there is any flaw with this approach):

    1. Use fracrank to calculate fractional ranks of both variables, as fracrank allows the use of weight;
    2. Use the normal command corr to calculate the Pearson's correlation between the two fractional ranks and using weight.

    Code:
    sysuse auto,clear
    fracrank price [aw=weight], gen(rank1 , replace)
    fracrank mpg [aw=weight] , gen(rank2 , replace)
    corr rank1 rank2 [aw=weight]
    spearman price mpg //compare
    fracrank is a user-written command provided by Philippe Van Kerm. It can be installed from within Stata by typing "ssc install sgini". Another package, somersd (by Roger Newson), calcualtes kendall's taua and allows weight, but taua does not correct for ties.
    Last edited by shem shen; 18 Aug 2021, 12:27.

  • #2
    I know this is an old post, but maybe this is helpful for other users as well. One solution to use spearman with sampling weights is generalized bootstrapping. An ado is available.
    Ado: https://github.com/fbittmann/gbs
    Working paper: https://doi.org/10.5281/zenodo.17581255

    Let me know if this works for you.
    Best wishes

    Stata 18.0 MP | ORCID | Google Scholar

    Comment


    • #3
      Another possibility would be to take advantage of the fact that Spearman's rho is identical to the Pearson correlation coefficient computed on the ranks of the variables. -correlate- and -pwcorr- both accept weights. The -egen- function rank() calculates ranks with options for various treatments of ties.

      Comment


      • #4
        There’s a deeper question of what does it even mean to have a weighted rank? Is this a sensible quantity to estimate? I have not seen good justifications on this topic, though they may exist (I haven’t looked much). If anyone has suggested reading, I’d like to learn more.

        Comment

        Working...
        X