Hi all,
I'm looking for some help on collapsing weighted sum. I'm currently working with a US income data set. It contains variables: year, income, and weight, and I'm trying to calculate the income share of top 10 percentile.
What I did was:
1) For each year, using xtile function to divide observations into 10 groups (10% percentile, 10%-20% percentile, ... etc. up to the top 10% percentile). Let's call this new variable percentile. (percentile = 1, 2, .., 10)
Now I have a grand data set containing all the observations and variables year, income, weight, percentile.
2) Collapse sum by year and percentile. My code is: collapse (sum) income [aweight = weight], by(year percentile) (Weight is float so I used aweight in my code.)
3) Following step 2, sum up income by year to get total income for each year. For each percentile, income share = income/total income
The problem with this code is that, when calculating aweighted-sum, Stata needs to normalize aweight. Ideally, I would like to have weights normalized by year, then I would like to sum up all the incomes in each percentile group after observations have been weighted correctly. But since I'm collapsing by both year and percentile, Stata normalizes weights also by both year and percentile.
Is there a way to get around this? Thank you in advance!
I'm looking for some help on collapsing weighted sum. I'm currently working with a US income data set. It contains variables: year, income, and weight, and I'm trying to calculate the income share of top 10 percentile.
What I did was:
1) For each year, using xtile function to divide observations into 10 groups (10% percentile, 10%-20% percentile, ... etc. up to the top 10% percentile). Let's call this new variable percentile. (percentile = 1, 2, .., 10)
Now I have a grand data set containing all the observations and variables year, income, weight, percentile.
2) Collapse sum by year and percentile. My code is: collapse (sum) income [aweight = weight], by(year percentile) (Weight is float so I used aweight in my code.)
3) Following step 2, sum up income by year to get total income for each year. For each percentile, income share = income/total income
The problem with this code is that, when calculating aweighted-sum, Stata needs to normalize aweight. Ideally, I would like to have weights normalized by year, then I would like to sum up all the incomes in each percentile group after observations have been weighted correctly. But since I'm collapsing by both year and percentile, Stata normalizes weights also by both year and percentile.
Is there a way to get around this? Thank you in advance!
Comment