Hi, I am very new to stata. I have x1, y1, z variables in data1.dta and x2, y2, N in data2.dta.

I am trying to run an analysis where:
  1. Step 1: x1 and x2 will be matched (merge) first.
  2. Step 2: Within the matched result y1 and y2 will be matched (merge).
  3. Expected result will be the data where y1 and y2 have finally matched (merge) and I'll get to see the z and N where x1=x2 within which y1=y2.
Constraints are:
Data within x1, y1, x2, y2 aren't unique which is why I can't merge or append the datasets.

I was hoping to run this process in a loop.

Thanks in advance.