Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: AW: RE: AW: AW: Categorize variable
From
"Martin Weiss" <[email protected]>
To
<[email protected]>
Subject
st: AW: RE: AW: AW: Categorize variable
Date
Mon, 12 Apr 2010 19:53:53 +0200
<>
Re -irecode()-, you may also like
http://www.stata-journal.com/article.html?article=st0181
HTH
Martin
-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Nick Cox
Gesendet: Montag, 12. April 2010 19:51
An: [email protected]
Betreff: st: RE: AW: AW: Categorize variable
gen mygroups = 10 * ceil(weight/10)
would get you most of the way. This has two small but notable
advantages:
1. The values are transparent as bin limits, 170 meaning (160, 170] etc.
2. Very simple code, including no need for value labels.
I realise that this will produce more classes than intended if there are
values below 140 or above 190, but there are solutions for that if it's
a real nuisance (e.g. -recode-).
The larger question is why you want to do this, as it is throwing away
detail that might be useful.
-irecode()- is another way to do it.
Nick
[email protected]
Martin Weiss
BTW, my solution is a bit more complicated than initially imagined
(http://www.stata.com/statalist/archive/2002-08/msg00178.html):
*************
clear*
set seed 123456
set obs 1000
gen weight=rnormal(165,6)
su weight, mean
egen float mygroups = cut(weight), at(`=r(min)-0.01' 150(10)180
`r(max)')
icodes
la def mylab 0 "<150" 1 "150-160" 2 "160-170" 3 "170-180" 4 ">180"
la val mygroups mylab
table mygroups, contents(freq min weight max weight) mis
*************
Martin Weiss
Look at -help egen, cut()-
Saretta
I have a continuous variabile called weight. How can I categorize this
variable into groups: <=150lb (150-160], (150-160], (170-180] and >180?
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/