Dear Stata Users,
I would like to create a loop but i have some difficulty to deal with it.
Here is an overview of my data. I have an id for every firms, a variable for 'va' and for the 'sector' to which the firm belong.
I would like to generate the variable demeaning_va_sector. This variable is the difference between the variable 'va' and the average of the sector for the 'va' to which the company belongs.
For example, for the first sector, the mean is (600+400+500)/3 = 500. So the demeaning_va is (600-500) =100
I have more than 20000 firms and i have 78 sectors.
Thanks for your help,
Pierre
I would like to create a loop but i have some difficulty to deal with it.
Here is an overview of my data. I have an id for every firms, a variable for 'va' and for the 'sector' to which the firm belong.
I would like to generate the variable demeaning_va_sector. This variable is the difference between the variable 'va' and the average of the sector for the 'va' to which the company belongs.
For example, for the first sector, the mean is (600+400+500)/3 = 500. So the demeaning_va is (600-500) =100
id | va | sector | demeaning_va_sector |
1 | 600 | 1 | 100 ==>( 600-500) |
2 | 300 | 2 | -150 ==>(300 - 450) |
3 | 400 | 1 | -100 |
4 | 500 | 1 | 0 |
5 | 600 | 2 | 150 |
6 | 700 | 3 | 300 |
7 | 100 | 3 | -300 |
Thanks for your help,
Pierre
Comment