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

st: RE: help with ages


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: help with ages
Date   Wed, 17 Sep 2003 19:27:34 +0100

Rodrigo Brice�o

> I have a database with hospital patients that have the age
> format defined in
> this way:
> 00H, 01H, ...until 74H, 01D, ...until 99D, 01M, ...until
> 74M, 01A, ... until
> 99A.
> I want to ask if anybody here could help me to construct
> some specific age
> distribution:
> 1...0-4 years
> 2...5-9 years
> 3...10-14 years and so on
>
> Original codes are: H: hours, D: days, M: months and A: years.

I can't see any way to do it but to crunch through
the possibilities.

I assume a string variable -code- containing
these string literals. I also assume no leading or
trailing spaces, itself assured by

replace code = trim(code)

gen age = 0 if index(code,"H") | index(code,"D")
replace age = real(substr(code,1,length(code)-1)) / 12 if
index(code,"M")
replace age = real(substr(code,1,length(code)-1)) if index(code,"A")

To check what didn't work

list code if missing(age)

Nick
[email protected]

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