Dear all
I am using the PALMS dataset (Post-Apartheid Labour Market Survey) - it is a stacked crossed sectional dataset of the labour market dynamic survey in South Africa (and its predecessors) across the years 1994 to 2017. It is at the individual level.
I am wanting to create a variable for the number of children in the household under the ages of 7 (i.e. 'Young children present'). I gather you do this using the 'egen' command. There is a variable for the household and individual identifier.

The code that i have tried to run is:

egen Y_CHILD = count(personnr) if age <= 7 , by (uqnr)
* Counts number of young children in every uqnr (household identifier)
egen YChild = max (YCHILD), by (uqnr)
*Assigns total number of children to each individual within the same household
tab YChild
recode YChild (0/2=1 "1. 0 - 2 children") (3/4=2 "2. 3 - 4 children") (5/6=3 "3. 5 - 6 children") (7/max=4 "4. 7 or more children"), gen(YChild_cat)
label var YChild_cat "Categorical variable: Number of Young Children present in Household"
*Assess years
tab YChild_cat if year == 2007
tab YChild_cat if year == 2012
tab YChild_cat if year == 2017

However, this does not produce the desired result. I believe i am missing something fundamental about the egen command.
Could anyone help?