Hello,

I am having trouble generating a categorical variable by the name of Age which is supposed to display categories in this format:
Age
5-9 years
10-14 years
15-19 years
20-24 years
All ages (5-24 years)
I am able to generate the first 4 categories using a loop however I am unable to understand as to how I can generate the final category "All ages (5-24 years)"

I used the following command to generate the first 4 categories and was wondering if you can help out with generating the last one within the categorical variable:

local x = 1
gen Age = 1
label variable Age "Age in Years"
forvalue j=5(5)24{
replace Age =`x' if s1aq05>=`j'
replace Age = . if (s1aq05<5 | s1aq05>24)
replace Age = 5 if Age==
local ++x
}

similarly, how may I add value labels to these categories within the loop?

Looking forward.