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
}
0 Response to Creating an indicator variable using the cond() function
Post a Comment