Many listers get flak for vague, circuitous or otherwise
unanswerable questions. This is a model of clarity!
I guess that when you say "byte" you mean "digit".
I also note that if this is the case then nobody dies at age
100 or above.
I will call your variable -ndeath-.
It will be convenient to convert this to a string by
gen sdeath = string(ndeath)
Death in years is given by
gen ydeath = real(substr(sdeath,2,.)) if substr(sdeath,1,1) == "1"
which will be missing for deaths below 1 year.
Death in months is given by
gen mdeath = real(substr(sdeath,2,.)) if substr(sdeath,1,1) == "2"
which will be missing for deaths at or above 1 year or below 1 month.
Death in days is given by
gen mdeath = real(substr(sdeath,2,.)) if substr(sdeath,1,1) == "3"
which will be missing for deaths at or above 1 month.
And so on.
Those might be useful for later applications. For example,
you might want a combined variable which could be
gen death = cond(ydeath < ., ydeath, 0) + cond(mdeath < ., mdeath/12, 0)
+ cond(ddeath < . , ddeath / 365.25, 0)
with extra terms for the other variables.
Your classification is
gen myclass = 1 if substr(sdeath,1,1) != "1"
replace myclass = 2 if ndeath < 5
replace myclass = 3 if ndeath < 15 & missing(myclass)
and other commands like the last.
And the moral is:
The functions are your friends.
Browse in the help for -functions-.
Nick
[email protected]
LaVera Crawley
> I am working with a 3 byte numeric variable of age at death where the
> first integer (prefix) codes whether the next 2 integers are in
> years, months, days, hours, or minutes. So it lists age in years
> as 1 + years; It lists months as 2 + months; days are 3 + days
> etc. For example, a person who died at 59 years of age is coded as
> 159; a child who died at 3 months of age is coded as 203; death at 4
> days is 304; death 6 hours after birth is 406; etc.
>
> I need to convert this to the following 11 age intervals in years:
> 0 to less than 1;
> 1 to 4;
> 5 to 14;
> 15 to 24;
> 25 to 34;
> continuing 10 year intervals up to 85+.
>
> I am having trouble creating a stata command for this because of how
> the bytes are set up (because of the prefix month, day, hour, &
> minute integers.) Please help!
*
* 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/