[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: pctile and xtile

From   "Rajesh Tharyan" <[email protected]>
To   <[email protected]>
Subject   st: pctile and xtile
Date   Thu, 17 Jan 2008 04:18:56 -0000

Hi all,

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

I am using the following code 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.  Code shown below.

* 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 = mcap if file, cutpoints(xu)
drop xx xu

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

egen yc=xtile(btom) if file, by(xc) nq(3)

* forming the final 6 groups

gen gp=10*xc+yc
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 below is my present
solution and it seems very complicated. Any suggestions are very much
appreciated. IS it possible to cut at specified percentiles?

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
******************* endworking **********
gen gp=10*mc+bm 

thanks very much

*   For searches and help try:

© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index