Hi Statalist.
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".
I believe I have coded 'impat = 1' and 'impat = 3' correctly, so I appreciate help to code 'impat == 2'.
Note: I have included multiple responses over different waves for a number of couples as I want to ask how I deal with changes in responses over time in my code? Should I take the average or the last level recorded?
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) 110 163 1 1 1 1 1 110 163 2 2 1 1 1 114 115 1 3 1 1 1 114 115 2 3 1 1 1 114 115 3 3 1 1 1 116 279 1 1 1 1 1 116 279 2 1 1 1 1 116 279 3 1 1 1 1 118 119 1 2 1 1 1 118 119 2 3 1 1 1 118 119 3 2 1 1 1 118 119 4 3 1 1 1 123 124 1 3 3 3 3 123 124 2 3 3 3 3 123 124 3 3 3 2 2 123 124 4 3 3 3 3 123 124 5 3 3 2 2 125 132 1 3 1 3 3 126 135 2 3 3 3 3 126 135 3 3 3 3 3 126 135 4 3 3 3 3 129 130 1 1 2 1 1 129 130 2 1 2 1 1 129 130 3 2 1 2 1 138 139 1 3 2 1 1 138 139 2 3 2 1 1 138 139 3 3 3 2 2 138 139 4 2 1 1 1 end
Comment