Hello,

I have time-series dyadic data and need to run a regression (DV and IVs are absolute differences) with standard errors clustered by a dyad. However, my data is somehow unstructured in a sense that it is not correct to use the egen, group() to create a unique ID for a dyad. This is the example of my data set:

Code:
input firm_id1    firm_id2    year    y_abs_dif    x_abs_dif
1    2    2010    10    1
2    1    2011    15    3
1    2    2012    20    5
3    4    2010    50    3
3    4    2011    60    7
4    3    2012    70    9
end
If I type:
Code:
egen dyad_id=group(firm_id1 firm_id2)
I get the following outcome:
Code:
     +------------------------------------------------------------+
     | firm_id1   firm_id2   year   y_abs_~f   x_abs_~f   dyad_id |
     |------------------------------------------------------------|
  1. |        1          2   2010         10          1         1 |
  2. |        2          1   2011         15          3         2 |
  3. |        1          2   2012         20          5         1 |
  4. |        3          4   2010         50          3         3 |
  5. |        3          4   2011         60          7         3 |
     |------------------------------------------------------------|
  6. |        4          3   2012         70          9         4 |
     +------------------------------------------------------------+
In line 2, how could I make dyad_id equal to 1 instead of 2, as lines 1-3 contain information on the same pair of firms? The same holds for lines 4-6. I cannot simply type
Code:
replace dyad_id = 1 in 2
replace dyad_id = 3 in 6
because I have numerous dyad-year observations.

I would be grateful for your help.