I would like to categorise a variable into seven categories based on specific definitions. The categories I want to create have multiple conditions, though when I -tabulate- 'fam', Stata gives me "error r111 "variable fam not found". I've attached the output of -tabulate- 'religb' - the variable of interest and as you can see, use both the respondent and partner variable in the categories
Code:
label define fam 1 ...
foreach v in religb p_religb { 
    gen `v'2 = cond(religb==p_religb & inrange(`v', 2000, 2999), 1,  ///
               cond(religb==p_religb & !inrange(`v', 2000, 2999) & !(inrange(`v', 7000, 9000)), 2,  ///
               cond(religb!=p_religb & inrange(`v', 2000, 2999), 3,  ///
               cond(religb!=p_religb & !inrange(`v', 2000, 2999) & !(inrange(`v', 7000, 9000)), 4,  ///
               cond(p_religb==7000 & inrange(`v', 2000, 2999), 5,  ///
               cond(p_religb==7000 & !inrange(`v', 2000, 2999) & !(inrange(`v', 7000, 9000)), 6,  ///
               cond(religb==7000 & p_religb==7000 , 7, .)))))))
    label val `v'2 fam 
}
]Can this work using the cond() or should I use -generate, replace- Help very much appreciated. Array