Dears,
I have a total of 175 purchasers across five regions. I need to create a variable that for each farmers have the mean of a variable called penalties of the farmers selling to other purchasers (so excluding the value of the observation i am looking at).
Schematically this would be
so my new var for farmers selling to the same purchaser (Leex) would be:
(5+2+6)/3
to the second Coop_s
(1+2+3+6)/4...and so on
I tried with this loop but I am not producing what i would need
any suggestion?
Thank you in advance
Federica
I have a total of 175 purchasers across five regions. I need to create a variable that for each farmers have the mean of a variable called penalties of the farmers selling to other purchasers (so excluding the value of the observation i am looking at).
Schematically this would be
Farmer | Regions | Purchasers | Penalities | my_new_var |
1 | A | Leex | 1 | 4.3 |
2 | A | Leex | 2 | 4.3 |
3 | A | Leex | 3 | 4.3 |
4 | A | Coop_s | 5 | 3 |
5 | A | Coop_s | 2 | 3 |
6 | A | Nilson | 6 | 2.6 |
7 | B | Roos | 2 | 3.5 |
8 | B | Roos | 8 | 3.5 |
9 | B | Xia | 2 | 4.75 |
10 | B | Xia | 3 | 4.75 |
11 | B | Fax | 8 | 3.75 |
12 | B | Fax | 1 | 3.75 |
so my new var for farmers selling to the same purchaser (Leex) would be:
(5+2+6)/3
to the second Coop_s
(1+2+3+6)/4...and so on
I tried with this loop but I am not producing what i would need
Code:
foreach x of numlist 1/175 { bys Reg: egen mean_Penalities`x'= mean(Penalities) if names!=`x' }
Thank you in advance
Federica
Comment