Hi,
I have a database of donations and I want to use it to generate a new var to indicate donors ideology. Firstly, calculate donor's ideology using the variable "dwnom1" of his recipients/candidates. Then calculate candidates' ideology using the donors index we got last step. Here is my code.
Code:
bysort donorid: egen donorave = sum(dwnom1*amount)
bysort donorid: egen donortotal = sum(amount)
gen donorindex = donorave/donortotal
bysort candid: egen candave = sum(donorindex*amount)
bysort candid: egen candtotal = sum(amount)
gen candindex = candave/candtotal
But there is a feedback loop, donor contributions to candidates will affect that candidate's scaling because that candidate is included in the estimate of the donor's ideology. I want to leave out certain candidate i when calculating donors' ideology, then use the donors' ideology to scale that candidate i's ideology. Below mathematical expression may help to understand. Is there any possible way to do that? Many thanks! [ATTACH=CONFIG]temp_15513_1566618554180_619[/ATTACH]

Here is my data
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str11 donorid long amount str10 candid double dwnom1
"29075807371"   250 "cand1297"  -.397
"9423"         1000 "cand645"   -.225
"9423"         1000 "cand645"   -.225
"3734270681"    200 "cand42555"     .
"4145347783"    750 "cand1327"  -.439
"2675854749"   1000 "cand1269"  -.305
"151787"       1000 "cand132"   -.328
"151787"       1000 "cand132"   -.328
"143206"        500 "cand364"    .704
"143206"        500 "cand364"    .704
"2692876123"    700 "cand1229"   .339
"29055799837"   250 "cand192"   -.421
"29356125709"   250 "cand192"   -.421
"29386443969"   250 "cand192"   -.421
"70001128"     2053 "cand662"   -.321
"70001128"     2053 "cand662"   -.321
"29075800235"   500 "cand1553"   .406
"52502762825"  1000 "cand1553"   .406
"29065810925"   500 "cand1553"   .406
"141572"          3 "cand52256"     .
"141572"          3 "cand52256"     .
"223230"        100 "cand1219"  -.145
"223230"        100 "cand1219"  -.145
"2469756684"    500 "cand53"    -.667
"2999006487"    333 "cand1288"   .518
"29095842545"  1000 "cand1244"  -.169
"54005220240"   300 "cand43935"     .
"268748"        500 "cand469"    .031
"268748"        500 "cand469"    .031
"103572"       -400 "cand519"    .336
"103572"       -400 "cand519"    .336
"165605"       -250 "cand687"    .265
"165605"       -250 "cand687"    .265
"165605"       -300 "cand692"    .296
"165605"       -300 "cand692"    .296
"2089"         -100 "cand647"     -.1
"2089"         -100 "cand647"     -.1
"106971"       -500 "cand509"    .543
"106971"       -500 "cand647"     -.1
"106971"       -500 "cand647"     -.1
"106971"       -500 "cand509"    .543
"106971"      -1000 "cand157"   -.518
"106971"      -1000 "cand157"   -.518
"106971"       -500 "cand465"    .383
"106971"       -500 "cand465"    .383
"9910"         -250 "cand726"    .407
"9910"         -250 "cand726"    .407
"35691"        -500 "cand469"    .031
"35691"        -500 "cand469"    .031
"2559802768"    200 "cand40683"     .
end