I want to code 'impat' with three categories (1 = both low, 2 = one high, 3 = both high). These three levels reflect the levels/categories of each of the categorical variables in my dataset. Note, each variable has a value for the respondent (e.g. relimp, relat) and for their partner (e.g. p_relimp, p_relat). In words, I want "impat == 2" only if relimp or relat == 3, but not both as this is captured in "impat == 3".
Code:
gen impat = 1 if (relimp2 == p_relimp2 & relimp2 == 1) & (relat2 == p_relat2 & relat2 == 1) // both low replace impat = 2 // one high (import/attend) replace impat = 3 if (relimp2 == p_relimp2 & relimp2 == 3) & (relat2 == p_relat2 & relat2 == 3) // both high
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input long(id p_id) byte wave float(relimp2 p_relimp2 relat2 p_relat2) 100010 1200063 1 1 1 1 1 100010 1200063 2 2 1 1 1 100014 100015 1 3 1 1 1 100014 100015 2 3 1 1 1 100014 100015 3 3 1 1 1 100016 200179 1 1 1 1 1 100016 200179 2 1 1 1 1 100016 200179 3 1 1 1 1 100018 100019 1 2 1 1 1 100018 100019 2 3 1 1 1 100018 100019 3 2 1 1 1 100018 100019 4 3 1 1 1 100023 100024 1 3 3 3 3 100023 100024 2 3 3 3 3 100023 100024 3 3 3 2 2 100023 100024 4 3 3 3 3 100023 100024 5 3 3 2 2 100025 1200332 1 3 1 3 3 100026 1000535 2 3 3 3 3 100026 1000535 3 3 3 3 3 100026 1000535 4 3 3 3 3 100029 100030 1 1 2 1 1 100029 100030 2 1 2 1 1 100029 100030 3 2 1 2 1 100038 100039 1 3 2 1 1 100038 100039 2 3 2 1 1 100038 100039 3 3 3 2 2 100038 100039 4 2 1 1 1 end
0 Response to Coding a new variable: where a category selects 'high' responses for one variable only if there are low responses for another variable
Post a Comment