Hi,

I am working on an upward mobility approach which looks at the likelihood that an individual will surpass their parent's place in the distribution by a given amount conditioned on their parents being at or below a given percentile. The equation is: URM_a,ρ = Pr(Y1 − Y0 > a|Y0 ≤ ρ) where a is the probability that the child exceeds the head's place in the distribution.

I have split head and child's earnings into percentile using:

Code:
xtile head_earnings = head_wage, n(100)
xtile child_earnings = child_wage, n(100)

To generate a, I'm using the following command:
a=0
Code:
gen d0 if child_earnings-head_earnings>0

a=10%
Code:
gen d10 if child_earnings-head_earnings>10

and so on till a=30

In order to carry out the regression for a=0, a=10%, a=20%, and a=30%, I using the following command:

Code:
reg d0 if group==1 & head_wage <=10
reg d0 if group==1 & head_wage <=20
reg d0 if group==1 & head_wage <=30
reg d0 if group==1 & head_wage <=40
reg d0 if group==1 & head_wage <=50

I have 4 groups belonging to the year 2005 and 4 belonging to the year 2012. I want to carry out this regression for different values of a and export the result using outreg2 but separately for the two years. Somehow, I have no idea how should I create a loop or maybe double loop for this.
The groups are as follows:
Group 1 and Group 5 are Hindus
Group 2 and Group 6 are Muslims
Group 3 and Group 7 are Scheduled Castes/Tribes
Group 4 and Group 8 are Other Backward Castes


I have attached an example of data set variables:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float group byte(head_earnings child_earnings) float(head_wage d0 d10 d20 d30)
1  2  2 4.3367343 1 0 0 0
1 17 14  9.779411 0 0 0 0
1 28 31 12.339286 0 0 0 0
1 63 68  19.73077 0 0 0 0
1 10 12  7.683594 0 0 0 0
3 93 85  56.95454 0 0 0 0
3 54 49    17.275 0 0 0 0
3  5 13  6.316288 1 0 0 0
4  4  5  5.898693 1 0 0 0
4 95 99  63.96104 1 1 1 0
4 85 29 33.824173 0 0 0 0
4 94 43  61.73684 0 0 0 0
2 40 17 13.716216 0 0 0 0
5 44  3 14.571428 0 0 0 0
5 52 14 16.666666 0 0 0 0
5 86 92      37.5 0 0 0 0
5 26 61        12 1 0 0 0
5 29 32      12.5 0 0 0 0
5 71 77        25 0 0 0 0
5 71 77        25 0 0 0 0
5 93 20        60 0 0 0 0
7 29 32      12.5 0 0 0 0
7 13 15      8.75 0 0 0 0
7 45 61        15 1 0 0 0
8 71 57        25 0 0 0 0
8 29  5      12.5 0 0 0 0
8 11 15     8.125 1 0 0 0
6 88 61        40 0 0 0 0
6 20 10      10.5 0 0 0 0
6 25 20 11.688312 0 0 0 0
end