I would like to create a few groups based on some of the categories of an existing variable. 'religb' is the respondent variable, 'p_religb' is the partner variable associated with religious affiliation. The same applies to hgsex (sex). The code for 'faith = 2' & 'faith = 3' below are essentially the same but I'm also testing the effect of gender on these different groupings.
Code:
gen faith = 1 if religb != p_religb & inlist(religb, 2010, 2030, 2050, 2170, 2250, 2330, 2800) /// couple of differemt religion but same religious group (rel1) & inlist(p_religb, 2010, 2030, 2050, 2170, 2250, 2330, 2800) replace faith = 2 if religb != p_religb & /// (hgsex==1 & inlist(religb, 2010, 2030, 2050, 2170, 2250, 2330, 2800) & (p_hgsex==2 & inlist(p_religb, 2110, 2130, 2150, 2270, 2310, 2400))) | /// male respondent + rel1 + female partner + rel2 (p_hgsex==1 & inlist(p_religb, 2010, 2030, 2050, 2170, 2250, 2330, 2800) & (hgsex==2 & inlist(religb, 2110, 2130, 2150, 2270, 2310, 2400))) // male partner + rel1 + female respondent + rel2 replace faith = 3 if religb != p_religb & /// (hgsex==2 & inlist(religb, 2010, 2030, 2050, 2170, 2250, 2330, 2800) & (p_hgsex==1 & inlist(p_religb, 2110, 2130, 2150, 2270, 2310, 2400))) | /// female respondent + rel1 + male partner + rel2 (p_hgsex==2 & inlist(p_religb, 2010, 2030, 2050, 2170, 2250, 2330, 2800) & (hgsex==1 & inlist(religb, 2110, 2130, 2150, 2270, 2310, 2400))) // female partner + rel1 + male respondent + rel2
(A sample of my data)
Code:
100014 100015 4 2010 2010 100014 100015 7 2010 2010 100014 100015 10 2010 2010 100014 100015 14 . 2010 100014 . 18 2010 . 100023 100024 4 2400 2400 100023 100024 7 2400 2400 100023 100024 10 2000 2000 100023 100024 14 2400 2400 100023 100024 18 2400 2400 100023 100024 4 2400 2400 100023 100024 7 2400 2400 100023 100024 10 2000 2000 100023 100024 14 2400 2400 100023 100024 18 2400 2400 100025 . 4 2400 . 100025 . 7 2000 . 100025 . 10 2400 . 100025 1200332 14 2400 2000 100025 1200332 18 2030 . 100026 1000535 10 2400 2400 100026 1000535 14 2400 2400 100026 1000535 18 2400 2400 100057 100058 4 2110 2070 100057 100058 7 2110 2070 100057 100058 10 2110 2070 100057 100058 14 2110 2070 100057 100058 18 2110 2070 end
Array
0 Response to Coding a new categorical variable based on an existing categorical variable
Post a Comment