Hello, I'm sorry if this has been answered before but some solutions I found don't really suit my problem or I'm not able to understand them.
I have a database that looks like this, the table below is a simplified example:
The above is a simple example, but what I have are 3 ids, and for each I have data from 20 years. This means that I have 240 monthly returns for each id.
I want to create a new variable called annual return, created from the values from month return. I need to calculate it as a simple return: (e.g. (1+returnannual ) = (1+rmonth1)*(1+rmonth3)*(1+rmonth4)* ... * (1+rmonth12) )
To be more clear, what I need should look like this:
If anyone could have some insight on how to do this, it would be wonderful. I'm not very skilled in Stata so I can't figure out how to do this. The missing values in the table above could just be the obtained annual return. The key is to create a new variable that has data for each year, from the monthly data.
Thank you in advance,
Carolina
I have a database that looks like this, the table below is a simplified example:
year | month | id | month return |
1999 | 1 | 1 | 1.01 |
1999 | 2 | 1 | 0.9 |
1999 | 3 | 1 | 1.03 |
1999 | 4 | 1 | 0.8 |
1999 | 5 | 1 | 1.03 |
1999 | 6 | 1 | 0.89 |
1999 | 7 | 1 | 1.01 |
1999 | 8 | 1 | 0.9 |
1999 | 9 | 1 | 1.03 |
1999 | 10 | 1 | 0.9 |
1999 | 11 | 1 | 0.8 |
1999 | 12 | 1 | 1.05 |
I want to create a new variable called annual return, created from the values from month return. I need to calculate it as a simple return: (e.g. (1+returnannual ) = (1+rmonth1)*(1+rmonth3)*(1+rmonth4)* ... * (1+rmonth12) )
To be more clear, what I need should look like this:
year | month | id | month return | annual return |
1999 | 1 | 1 | 1.01 | . |
1999 | 2 | 1 | 0.9 | . |
1999 | 3 | 1 | 1.03 | . |
1999 | 4 | 1 | 0.8 | . |
1999 | 5 | 1 | 1.03 | . |
1999 | 6 | 1 | 0.89 | . |
1999 | 7 | 1 | 1.01 | . |
1999 | 8 | 1 | 0.9 | . |
1999 | 9 | 1 | 1.03 | . |
1999 | 10 | 1 | 0.9 | . |
1999 | 11 | 1 | 0.8 | . |
1999 | 12 | 1 | 1.05 | (1+returnannual ) |
Thank you in advance,
Carolina
Comment