# st: pctile and xtile question again

 From "Rajesh Tharyan" <[email protected]> To <[email protected]> Subject st: pctile and xtile question again Date Thu, 17 Jan 2008 10:50:38 -0000

```Hi all,

Sorry for the repeat post..not sure if the pevious mail has been ignored
as the subject line did say please ignore...

This is my problem

I have two variables x and y, which I have to put into 6 groups.

I am using the code below (code I) to first cut the x variable  into 2
groups based on its 70th percentile value. And then, for each group of
the x variable I cut the y variable into 3 equal groups, and finally put
the two together to form the final six groups.

What I would like to do is cut the y variable for each group of x based
on the 30th and 70th percentile value. The code (Code II) below is my
present solution and it seems very complicated. Any suggestions are very
much appreciated. IS it possible to cut at specified percentiles?

Code I
*************start********************
* this bit cuts the x variable into two groups based on the 70th
percentile value

pctile xu=x, nq(10) genp(xx)
replace xu=. if xx~=70

sort xu (Is this step necessary? I get slightly different numbers if I
sort and when I do not sort for example for one group I get 481 with and
477 without sorting)

xtile xc = x, cutpoints(xu)
drop xx xu

* this bits cuts the y variable into three groups for each group of x

egen yc=xtile(y), by(xc) nq(3)

* forming the final 6 groups

gen gp=10*xc+yc

****************end*******************

Code II
************start*********

pctile xu=x, nq(10) genp(xx)
replace xu=. if xx~=70
sort xu
xtile xc = x, cutpoints(xu)
drop xx xu

pctile xmmu=y if xc==1, nq(10) genp(yy)
replace xmmu=. if yy~=30 & yy~=70
pctile xmmcu1=y if xc==2, nq(10) genp(yy1)
replace xmmcu1=. if yy1~=30 & yy1~=70

xtile yc=y if mc==1, cutpoints(xmmu)
xtile yc1=y if mc==2, cutpoints(xmmu1)
replace yc=yc1 if yc==. & xc==2
drop xmmu xmmu1 yc1 yy yy1
gen gp=10*xc+yc

***********end************

thanks very much
rajesh

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```