I am trying to generate variables that present the ratio of subgroup means for different years.
The dataset is structured as follows: I have observations for several years, and five income groups - income quintiles (incq) - for each year. For each income group, I have created the mean annual expenditure (meanex) for different items, e.g. electricity, this is the same value for each observation in that income group already. Now I'd like to generate a new variable that contains the ratio of spending which divides mean spending of the first income quintile by the mean spending of the fifth income quintile per year (meanex if incq==1/meanex if incq==5). My ultimate aim is to be able to plot that ratio by year to see how inequality in expenditure changes over time.
Here is a simplified example of my dataset:
Code:
clear input id year incq meanex 1 1 1 2.4 2 1 1 2.4 3 1 2 3.1 4 1 2 3.1 5 1 3 4.2 6 1 3 4.2 7 1 4 4.8 8 1 4 4.8 9 1 5 5.1 10 1 5 5.1 11 2 1 1.1 12 2 1 1.1 13 2 2 1.7 14 2 2 1.7 15 2 3 2.1 16 2 3 2.1 17 2 4 2.5 18 2 4 2.5 19 2 5 3.6 20 2 5 3.6 21 3 1 1.6 22 3 1 1.6 23 3 2 2.3 24 3 2 2.3 25 3 3 2.8 26 3 3 2.8 27 3 4 3.7 28 3 4 3.7 29 3 5 6.8 30 3 5 6.8 end
0 Response to Generate variables with ratios of subgroup values
Post a Comment