## How to Double Sort?

Frequent Contributor
Posts: 102

# How to Double Sort?

Hi,

1. I have a panel dataset (below is a small sample). I would like to sort the data independently by Uvalue, and Svalue into quartiles,

By independently, I mean if I use proc rank to output 4 ranks based on Uvalue, I do not consider Svalue. And vice versus if I output based on Svalue.

After the two sorts are done,

I expect 4 ranks within each variable category. 4*4 =16 cells,

My goal is to test whether Dvalue differs significantly within each cell.

2. That is does Dvalue in (Quartile 1 based on Uvalue rank) is significantly different from Dvalue in Quartile 1 based on Dvalue rank.

I know how to single sort, but need your help with double sort, and save the output for T-test in part 2.

thanks!

Lan

 firmid year Uvalue Svalue Dvalue 1001 1992 0.3 10 100 1001 1993 0.6 11 90 1001 1994 1 11 90 1001 1995 0.9 12 100 1001 1996 1.1 12 110 1001 1997 0.92 12 110 1001 1998 1.1 13 111 1002 1993 0.2 9 20 1002 1994 0.3 9 22 1002 1995 0.4 9.1 23 1002 1996 0.9 10 25 1002 1997 0.7 10 30 1003 1995 1 6 15 1003 1996 1.1 5 15 1003 1997 1.4 7 16
Posts: 5,521

## Re: How to Double Sort?

Proc RANK does its own sorting for each variable. You don't have to worry about it. So the answer to your first question is straightforward. The second question however isn't valid statistically as the two sets that you want to compare are not independent. I would simply look at the frequency and Dvalue mean for each combination of quartiles :

proc rank data=have out=haveQuart groups=4;
var Uvalue Svalue;
ranks Uquart Squart;
run;

proc means data=haveQuart n mean nonobs printaltypes;
class Uquart Squart;
var Dvalue;
run;

PG

PG
Discussion stats