Hello -- I was unsure how to word the title, but hopefully it offers some clue as to what I am trying to do. I have the following dataset:
I would like to create a new variable "j" which would would allow each possible i, j pair to be represented, with respect to k. I.e. k = DEU, i = ARG, j = AUS would be the first observation, then k = DEU, i = ARG, j = AUT would be next, and so on. Once all the i, j pairs are created for DEU, the i, j pairs would then be created for USA. My initial (naive) attempt at this was:
, but of course that does not create all of the pairs for each i country that I needed. Thank you for your help.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float year str8(k i) 1996 "DEU" "ARG" 1996 "DEU" "AUS" 1996 "DEU" "AUT" 1996 "DEU" "BEL" 1996 "DEU" "BGR" 1996 "USA" "ARG" 1996 "USA" "AUS" 1996 "USA" "AUT" 1996 "USA" "BEL" 1996 "USA" "BGR" end
Code:
gen j = i[_n+1]
Comment