Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Categorize variable with percentile valor of other variable


From   Xavi Barber <[email protected]>
To   [email protected]
Subject   st: Categorize variable with percentile valor of other variable
Date   Tue, 06 Apr 2004 10:27:57 +0200

Dear statalisters:

I have a programming doubt.

This is my program:

********************************************************
pctile varPCT=var if var2==XXX, nq(4)

scalar p25=r(r1)
scalar p50=r(r2)
scalar p75=r(r2)

egen var4c=cut(var), at(p25, p50, p75)

scalar drop p25 p50 p75
drop varPCT

********************************************************

But Stata return a error --> " at (..) invalid "

I think in a new program but I don't like it.

***********************************************************
pctile varPCT=var if var2==XXX, nq(4)

scalar p25=r(r1)
scalar p50=r(r2)
scalar p75=r(r2)

gen var4c=1 if var<p25
replace var4c=2 if (var>=p25 & car<p50)
replace var4c=3 if (var>=p5 & car<p75)
replace var4c=4 if (var>=p75)

scalar drop p25 p50 p75
drop varPCT
***********************************************************

My question is: Which is the best method to categorize variable with percentile of other variable????

Thanks


*
* 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/




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