Hi all,
I am using Stata 14.2 on Windows and am currently working with some financial data.
I want to generate a variable, displaying the sum of the return on assets from a period t to t+2 for each company, specified by the ds_code in a way that the generated value is represented as new variable in the row of year t.
I first only aggregated the roa across a company using, but the code does not specify the time-frames I am interested in:
egen roa3y = sum(roa), by(ds_code)
I am struggling to include the condition to only calculate the sum of the years t=0 to t=2 referring to the year of the observation. My data looks somewhat like this:
ds_code year roa
"130062" 2004 .1783172
"130062" 2005 6.661182
"130062" 2006 2.339188
"130062" 2007 .16718867
"130062" 2008 .12236715
"130088" 2004 .22295973
"130088" 2005 .04354694
"130088" 2006 .3157642
"130088" 2007 .11244648
"130088" 2008 5.147346
So in e.g. in row 1, I want to generate a new variable roa3y that is the sum of the roa of firm "130062" from years 2004, 2005, and 2006 (9.1786872 in this case).
Really appreciate any help, you may be able to provide!
I am using Stata 14.2 on Windows and am currently working with some financial data.
I want to generate a variable, displaying the sum of the return on assets from a period t to t+2 for each company, specified by the ds_code in a way that the generated value is represented as new variable in the row of year t.
I first only aggregated the roa across a company using, but the code does not specify the time-frames I am interested in:
egen roa3y = sum(roa), by(ds_code)
I am struggling to include the condition to only calculate the sum of the years t=0 to t=2 referring to the year of the observation. My data looks somewhat like this:
ds_code year roa
"130062" 2004 .1783172
"130062" 2005 6.661182
"130062" 2006 2.339188
"130062" 2007 .16718867
"130062" 2008 .12236715
"130088" 2004 .22295973
"130088" 2005 .04354694
"130088" 2006 .3157642
"130088" 2007 .11244648
"130088" 2008 5.147346
So in e.g. in row 1, I want to generate a new variable roa3y that is the sum of the roa of firm "130062" from years 2004, 2005, and 2006 (9.1786872 in this case).
Really appreciate any help, you may be able to provide!
Comment