Hello,
I have a panel dataset of 100 firms each with 5 years of data. For each of the five years, I want to calculate the mean of the debt ratio variable of all firms weighted by the assets variable of each firm. Thus, I want a weighted average measure for debt ratio by year. A snapshot of the data is as follows:
Can you please advise me on the code I can use for this? Thanks.
I have a panel dataset of 100 firms each with 5 years of data. For each of the five years, I want to calculate the mean of the debt ratio variable of all firms weighted by the assets variable of each firm. Thus, I want a weighted average measure for debt ratio by year. A snapshot of the data is as follows:
id | year | assets | debt ratio |
19420 | 2001 | 364.3988 | 0.019435 |
19420 | 2002 | 365.549 | 0.080575 |
19420 | 2003 | 365.7212 | -0.02357 |
19420 | 2004 | 364.701 | 0.010654 |
19420 | 2005 | 372.4104 | 0.060513 |
59796 | 2001 | 294.1355 | 0.043929 |
59796 | 2002 | 293.2148 | 0.063242 |
59796 | 2003 | 293.305 | 0.149902 |
59796 | 2004 | 377.0879 | 0.154791 |
59796 | 2005 | 463.3691 | 0.205261 |
192855 | 2001 | 1754.285 | 0.244634 |
192855 | 2002 | 1745.32 | 0.185563 |
192855 | 2003 | 2055.629 | 0.227559 |
192855 | 2004 | 2457.257 | 0.27855 |
192855 | 2005 | 2748.261 | 0.273795 |
243328 | 2001 | 9156.501 | 0.102508 |
243328 | 2002 | 8912.646 | 0.086499 |
243328 | 2003 | 8790.42 | 0.065551 |
243328 | 2004 | 8562.688 | 0.069552 |
243328 | 2005 | 8542.187 | 0.069065 |
Can you please advise me on the code I can use for this? Thanks.
Comment