I am struggling with restructuring my data.
Below is the format of my data: PID stands for individuals and values under age* describe the income level of one's job which he/she had at each age.
The reason why there are more than two lines of each PID is that each individuals has more than two jobs in their lives.
I want to make one line for each PID by summing all the values in different columns by
Code:
collapse (sum) age*, by(PID)
However, as you can see, PID 61 and 71 have a period when they had two jobs at the same time. (I made these cells bolded)
Thus, by using above command, stata automatically sums up both values.
Array
I want to make the format in either way:
1) make an average of two values : e.g fill PID 71's income level (168+250)/2 = 209 in the age22~24
2) take the latter (below) value by ignoring the first one: e.g fill PID 71's income level 168 in the age22~24
Thank you very much for your help.
Sincerely, Halim.
0 Response to Making an average when there are more than two values in different lines (of the same ID)
Post a Comment