Hello,
I have a household panel data set containing individual data for 6 years. For each year, ca. 15000 individuals are divided into 50 groups. I also have a variable, say "income", that is a decimal for every individual.
Now I want to calculate for each year and group the sum of the differences between an individual i's income and the income of all other individuals in his group if their income is higher (respectively lower) than the income of individual i and divide this value by 'the number of individuals minus 1' in the group.
I tried various combinations of foreach and forvalues loops without success. The group sizes differ every year and ca. 1% of observations of "income" are missing in every group
I am grateful for any idea of how to implement a loop to generate the values for "higher" and "lower" income as described.
Thanks and best wishes,
Johannes
I have a household panel data set containing individual data for 6 years. For each year, ca. 15000 individuals are divided into 50 groups. I also have a variable, say "income", that is a decimal for every individual.
Now I want to calculate for each year and group the sum of the differences between an individual i's income and the income of all other individuals in his group if their income is higher (respectively lower) than the income of individual i and divide this value by 'the number of individuals minus 1' in the group.
I tried various combinations of foreach and forvalues loops without success. The group sizes differ every year and ca. 1% of observations of "income" are missing in every group
I am grateful for any idea of how to implement a loop to generate the values for "higher" and "lower" income as described.
Thanks and best wishes,
Johannes
Comment