Hi all -
Suppose I have data that looks like this:
The values of Var1, Var2 are unimportant.
I want to regress Var1 on Var2 among a sample only restricted to certain pairs within the group variable. More specifically, I want each group for which identifier == 0 to be paired with all groups for which identifier == 1, one at a time. Here, B would be paired with A and C, and D would be paired with A and C as well. A and C would not be a pair and neither would B and D.
There are 32 groups in the actual data, about half of which have identifier == 0, though, so writing
reg var1 var2 if inlist(group, A, B)
reg var1 var2 if inlist(group, B, C)
for all permutations is horribly inefficient. Is there a way to assign a numeric value (call it id) to each pair, so that instead I can write something to the effect of
forvalues i = 1/n {
qui reg var1 var2 if id == `i'
est sto var1_`i'
}
Most methods I've been able to find only work if the pairs are formed from observations in two separate variables, whereas I want to create groups within a variable.
Happy to clarify anything if my question is confusing.
Suppose I have data that looks like this:
| group | identifier | var1 | var2 |
| A | 1 | ||
| B | 0 | ||
| C | 1 | ||
| C | 1 | ||
| D | 0 |
I want to regress Var1 on Var2 among a sample only restricted to certain pairs within the group variable. More specifically, I want each group for which identifier == 0 to be paired with all groups for which identifier == 1, one at a time. Here, B would be paired with A and C, and D would be paired with A and C as well. A and C would not be a pair and neither would B and D.
There are 32 groups in the actual data, about half of which have identifier == 0, though, so writing
reg var1 var2 if inlist(group, A, B)
reg var1 var2 if inlist(group, B, C)
for all permutations is horribly inefficient. Is there a way to assign a numeric value (call it id) to each pair, so that instead I can write something to the effect of
forvalues i = 1/n {
qui reg var1 var2 if id == `i'
est sto var1_`i'
}
Most methods I've been able to find only work if the pairs are formed from observations in two separate variables, whereas I want to create groups within a variable.
Happy to clarify anything if my question is confusing.

Comment