Dear Statalist,
I am analyzing a dataset that incorporates a directed-dyad year unit of analysis. But, for the past week or so, I have been struggling to think of how to code a condition based on the values of the directed dyad-years. (I assuming this is the port of call, since this is a bit of a logic game).

The dyads are cities. Let’s call them City I and City II. The city codes are numerical.

I am trying to come up with a way to code for a variable “Z” depending on the values of one member of the dyad. Variables A-D, Y and Z are all coded as "." “0” or “1.” If there is nothing coded for A-D, then Y=0.



The following are the rules for the condition, using the example of the small dataset seen below:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input byte(city1 city2) int year byte(a b c d y z)
10 11 1990 1 . 1 . 1 0
11 10 1990 1 . 1 . 1 0
10 12 1990 . . . 1 1 0
12 10 1990 . . . 1 1 0
11 12 1990 . . . . 0 1
12 11 1990 . . . . 0 1
10 13 1990 . 1 . . 1 0
13 10 1990 . 1 . . 1 0
11 13 1990 . . . . 0 .
13 11 1990 . . . . 0 .
end
----------


Y is coded as “1” if at least one variable between A-D is coded as “1.”

If Y=1 for the dyad-year City 10 and City 11 in 1990 (and similarly for the directed-dyad year (City 11 and City 10 in 1990),

and if Y=1 City 10 and City 12 in 1990,

then, Z=1 if City 11 and City 12 in 1990, so along as Y=0 for the dyad City 11 and City 12 in 1990 (i.e. there is nothing coded for A-D).

In other words, these conditions are all dependent on the members of the dyad, and this is where I am struggling trying to put a condition together in Stata.

Essentially, I am trying to code CITY I (11) and City II (13) in the same way. For the dyad City 10 and 13 in the year 1990, Y=1. City 10 and City 11, Y=1. I am trying to code City 11 and City 13 as Z=1, given also the fact that they (City 11 and City 13) have no values for A-D (hence, Y=0).

Thank you in advance for any help.