Bit of a late response, but I just stumbled across this today. If I understand the question, Something like this should do the trick, although I'm not sure it's easily applied to more complex data or if this would even be the best way...
* Create Sample Data
clear
set obs 3
gen str var1 = "a" in 1
replace var1="b" in 2
replace var1="c" in 3
gen var2= _n
* Find number of Unique Groupings to set obs
by var1 var2, sort: gen groups=_n==1
keep if groups==1
drop groups
di _N^2
set obs 9
* Create New Variable
forvalues i = 4(3)9 {
forvalues j = 5(3)9 {
forvalues k = 6(3)9 {
replace var1="a" if _n==`i'
replace var1="b" if _n==`j'
replace var1="c" if _n==`k'
}
}
}
sort var1
egen i=seq(), f(1) t(3)
tostring i, replace
gen NewVar=var1+i
list NewVar
+--------+
| NewVar |
|--------|
1. | a1 |
2. | a2 |
3. | a3 |
4. | b1 |
5. | b2 |
|--------|
6. | b3 |
7. | c1 |
8. | c2 |
9. | c3 |
+--------+
Unfortunately as far as I know, there is no easy way to do this - it will require a fair amount of code. Although, I saw another answer or comment that mentioned cross
which could be very useful here. Another command worth checking out is joinby
. But even with either of these methods, you will have to split your data into 7 different sets based on the variables you want to 'cross combine'.
Anyway, Good Luck if you haven't yet found your solution.