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

Age groups [was: st: RE: RE: Question about tabsort ... ]


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   Age groups [was: st: RE: RE: Question about tabsort ... ]
Date   Fri, 12 Jul 2002 18:21:26 +0100

Rodrigo Briceņo" <rbriceno@sanigest.com>

2.  Months ago I asked to the list how can I generate some age groups.
I use that help in order to have a frequency of the hospital discharges
by age groups. The problem here is that I found that my variable age
was a string8 variable. Then the options to generate a new variable
was restricted: I tried typing:

gen str8 rank_edad=1 if inrange(edad,0,0)

to construct my age groups (less than 1 year, between 1 and 4,
between 5 and 9, 10-19, 20-29, 30-39, 40-49, 50-59 and the last one 60 or
more)

> That's not going to work as you typed it because
> strings need to be in " ".

This not work for me so I try:

encode edad, gen (edad2)

like I learned from my net course on Stata.
The things appear to be ok, because when I type

tab edad2 I see all the ages correctly. The problem here is that I'm
building three groups (the first three) that donīt have data on it.  But
Stata is calculating something on it, I don't know why.

gen byte rank_edad=1 if range(edad2,0,0)
replace rank_edad=2 if inrange (edad2,1,4)
replace rank_edad=3 if inrange (edad2,5,9)
replace rank_edad=4 if inrange (edad2,10,19)
and so on.....

tab  rank_edad

  rank_edad |      Freq.     Percent        Cum.
------------+-----------------------------------
   1-4_anos |         90        1.73        1.73
   5-9_anos |       1190       22.88       24.61
 10-19_anos |       2114       40.64       65.24
 20-29_anos |        892       17.15       82.39
 30-39_anos |        304        5.84       88.24
 40-49_anos |        202        3.88       92.12
 50-59_anos |        162        3.11       95.23
Mas_60_anos |        248        4.77      100.00
------------+-----------------------------------
      Total |       5202      100.00

Do you know or guess why Stata is putting data on the first three groups
that is supposed to be empty (I build those groups because I'm making a do
file, that I can apply to other databases).

Thanks....

Rodrigo

Nick
n.j.cox@durham.ac.uk

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index