Obsidian | Level 7

## Divide sample into top quartile and bottom quartile by group

by each year, by each SIC, i want do divide this dataset into 2 dataset of top quartile and bottom quartile based on Qratio.

data firm;

input YEAR SIC Qratio;

datalines;

2009 1111 1.5
2009 1111 2.5
2009 1111 3.5
2009 1111 4.5
2009 1111 4.5
2009 1111 4.5
2009 1111 4.5
2009 2222 1.7
2009 2222 1.7
2009 2222 1.7
2009 2222 1.7
2009 2222 1.7
2010 1111 2.7
2010 1111 3.7
2010 1111 4.7
2010 1111 5.7
2010 2222 6.7
2010 2222 7.7
2010 2222 8.7
2010 2222 9.7
2010 3333 10.7
2010 3333 11.7
2010 3333 12.7
2010 3333 13.7
2010 4444 14.7
2010 4444 15.7
2010 4444 16.7
2010 4444 17.7
2010 4444 18.7
2010 4444 19.7

1 ACCEPTED SOLUTION

Accepted Solutions
Diamond | Level 26

## Re: Divide sample into top quartile and bottom quartile by group

It's not a one-step process, it takes two steps.

PROC RANK with the option GROUPS=4 creates quartiles.

Then you take the output data set and split the data into the upper and lower quartiles.

--
Paige Miller
3 REPLIES 3
Super User

## Re: Divide sample into top quartile and bottom quartile by group

Look at PROC RANK which will group your data based on quartiles.

@Takdir wrote:

by each year, by each SIC, i want do divide this dataset into 2 dataset of top quartile and bottom quartile based on Qratio.

data firm;

input YEAR SIC Qratio;

datalines;

2009 1111 1.5
2009 1111 2.5
2009 1111 3.5
2009 1111 4.5
2009 1111 4.5
2009 1111 4.5
2009 1111 4.5
2009 2222 1.7
2009 2222 1.7
2009 2222 1.7
2009 2222 1.7
2009 2222 1.7
2010 1111 2.7
2010 1111 3.7
2010 1111 4.7
2010 1111 5.7
2010 2222 6.7
2010 2222 7.7
2010 2222 8.7
2010 2222 9.7
2010 3333 10.7
2010 3333 11.7
2010 3333 12.7
2010 3333 13.7
2010 4444 14.7
2010 4444 15.7
2010 4444 16.7
2010 4444 17.7
2010 4444 18.7
2010 4444 19.7

Obsidian | Level 7

## Re: Divide sample into top quartile and bottom quartile by group

I looked at the Proc Rank. But I am still confused how to create different dataset for each group since I am really new to this coding. Could you help me with some codes ? 🙂

Diamond | Level 26

## Re: Divide sample into top quartile and bottom quartile by group

It's not a one-step process, it takes two steps.

PROC RANK with the option GROUPS=4 creates quartiles.

Then you take the output data set and split the data into the upper and lower quartiles.

--
Paige Miller
Discussion stats
• 3 replies
• 834 views
• 0 likes
• 3 in conversation