Good evening,

I am new to Stata and have been researching and consulting the help command on a problem with no luck.

I am trying to create a new variable "hour_groups" that categorizes the "hour" variable into 4 groups, e.g. 0 to 6 (a.m.) is assigned the number 1, 7 to 12 is assigned 2 and so on. I'm trying the foreach and and forvalues command. Any help is appreciated. Is it possible to generate a new variable while categorizing in the same command?