Hi, I have the following dataset
clear
input id str10 date1 CF TV
1 "03/31/2000" -100 100
1 "06/30/2000" -100 200
1 "09/30/2000" 0 220
1 "12/31/2000" 0 230
1 "03/31/2001" 0 230
2 "06/30/2005" -80 80
2 "09/30/2005" 0 85
2 "12/31/2005" -20 105
2 "03/31/2006" 15 110
2 "06/30/2006" 32 118
2 "09/30/2006" 118 0
end
gen date = date(date1, "MDY")
format date %td
gen qdate = qofd(date)
format qdate %tq
xtset id qdate
For each id, there are a series of cash flows (CF), by date, with a positive value being an outflow. For each date, there is also a terminal value. I would like to generate a new variable (IRR) that is the internal rate of return for that id as of each date. The IRR is based on the periodic cash flows from the id's first observation in the dataset through the current date, plus the terminal value on the current date. For instance, for id == 1 and date == 9/30/2000, the series of values for the IRR calculation would be -100, -100, 220, resulting in an IRR = 28.62% (this is the value excel calculates with the xirr function). My dataset consists of 200,000 id-date observations with approximately 40 observations per id, so I am looking to calculate around 40 different IRR values for each of the approximately 5,000 unique ids. I have tried reading up on the irr and finxirr commands from ssc, but I cannot figure out how to apply it to panel data like I have. Exporting the data to excel to run calculations is not an option for me, either. I would be so grateful for the forum's help.
Thanks,
Becky
clear
input id str10 date1 CF TV
1 "03/31/2000" -100 100
1 "06/30/2000" -100 200
1 "09/30/2000" 0 220
1 "12/31/2000" 0 230
1 "03/31/2001" 0 230
2 "06/30/2005" -80 80
2 "09/30/2005" 0 85
2 "12/31/2005" -20 105
2 "03/31/2006" 15 110
2 "06/30/2006" 32 118
2 "09/30/2006" 118 0
end
gen date = date(date1, "MDY")
format date %td
gen qdate = qofd(date)
format qdate %tq
xtset id qdate
For each id, there are a series of cash flows (CF), by date, with a positive value being an outflow. For each date, there is also a terminal value. I would like to generate a new variable (IRR) that is the internal rate of return for that id as of each date. The IRR is based on the periodic cash flows from the id's first observation in the dataset through the current date, plus the terminal value on the current date. For instance, for id == 1 and date == 9/30/2000, the series of values for the IRR calculation would be -100, -100, 220, resulting in an IRR = 28.62% (this is the value excel calculates with the xirr function). My dataset consists of 200,000 id-date observations with approximately 40 observations per id, so I am looking to calculate around 40 different IRR values for each of the approximately 5,000 unique ids. I have tried reading up on the irr and finxirr commands from ssc, but I cannot figure out how to apply it to panel data like I have. Exporting the data to excel to run calculations is not an option for me, either. I would be so grateful for the forum's help.
Thanks,
Becky
Comment