Hi all,

I am trying to create a dummy variable based on the particular combination of two other dummy variables.
Based on the example data set below, I have created a group id called as 'idtemp' based on the combination of three variables - state, year and const. The variable called 'order' explains the rank of the individual, therefore if order=1, he/she is the winner and if order=2, the individual is the loser. With each id('idtemp'), there is only one winner and one loser.

Now, I would like to create a dummy variable within each id, based on the following set of combinations. Let's call the dummy variable I intend to create as 'temp' and I want temp=1 for the following two set of combinations within each id.

1. "within each id", if the dummy1=1 for the winner(order=1) and dummy2=1 for the loser(order=2), then I want temp=1, and
2. "within each id", if the dummy1=1 for the loser(order=2) and dummy2=1 for the winner(order=1), then also I would like to set temp=1.

Therefore in the example dataset below, the variable 'temp' takes on 1, for the idtemp values of 3, 4 and 15, as the required condition has been satisfied. And for all other ids the variable 'temp' has been set as zero

Any suggestions would be helpful.

Regards

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str17 state float year str29 const float(order idtemp dummy1 dummy2 temp)
"Andhra Pradesh" 1994 "Achampet"   1  1 0 1 0
"Andhra Pradesh" 1994 "Achampet"   2  1 0 1 0
"Andhra Pradesh" 1994 "Achanta"    1  2 0 0 0
"Andhra Pradesh" 1994 "Achanta"    2  2 0 1 0
"Andhra Pradesh" 1994 "Addanki"    1  3 1 0 1
"Andhra Pradesh" 1994 "Addanki"    2  3 0 1 1
"Andhra Pradesh" 1994 "Adilabad"   1  4 0 1 1
"Andhra Pradesh" 1994 "Adilabad"   2  4 1 0 1
"Andhra Pradesh" 1994 "Adoni"      1  5 0 1 0
"Andhra Pradesh" 1994 "Adoni"      2  5 0 1 0
"Andhra Pradesh" 1994 "Alair"      1  6 0 1 0
"Andhra Pradesh" 1994 "Alair"      2  6 0 1 0
"Andhra Pradesh" 1994 "Alampur"    1  7 0 1 0
"Andhra Pradesh" 1994 "Alampur"    2  7 0 1 0
"Andhra Pradesh" 1994 "Alamuru"    1  8 0 1 0
"Andhra Pradesh" 1994 "Alamuru"    2  8 0 1 0
"Andhra Pradesh" 1994 "Allagadda"  1  9 0 1 0
"Andhra Pradesh" 1994 "Allagadda"  2  9 0 1 0
"Andhra Pradesh" 1994 "Amarchinta" 1 15 0 1 1
"Andhra Pradesh" 1994 "Amarchinta" 2 15 1 0 1
end