I am regressing stock returns (of "Firms v") on an index ("Index") during each Quarter ("Quarter"). Hence my STATA file has a column "Daily date", a column "Quarter" (i from from 1 to 12 -as there are 12 Quarters in the file), a column "Index" (that is a Daily Index) and 140 columns named "firm1" .... "firm140" (that show Daily stock returns of firms 1 to 140).
I want the R2 (r-squares) of the daily regression of the 140 stock returns on the index during each quarter (there would be 12 R2 per firm, as there are 12 Quarters in the STATA file).
I was able to develop the following code:
foreach v of varlist Firm* {
forvalues i=1/12 {
regress `v' Index if Quarter==`i'
scalar R2_`v'_`i'=e(r2)
}
}
scalar list
The code works well but returns a list of scalars R2_`v'_`i' when what I need would be to create a Matrix (or table) that has rows āiā (the 12 Quarters) and columns āvā (the 140 Firms, with the R2_`v'_`i' value that the code gives). Any hint on how to do this ? (I believe the Matrix function in STATA has to be used, but so far, I have not been able to write the code to create this Matrix in/ from the above code).
Thank you.
Best,
Emmanuel
I want the R2 (r-squares) of the daily regression of the 140 stock returns on the index during each quarter (there would be 12 R2 per firm, as there are 12 Quarters in the STATA file).
I was able to develop the following code:
foreach v of varlist Firm* {
forvalues i=1/12 {
regress `v' Index if Quarter==`i'
scalar R2_`v'_`i'=e(r2)
}
}
scalar list
The code works well but returns a list of scalars R2_`v'_`i' when what I need would be to create a Matrix (or table) that has rows āiā (the 12 Quarters) and columns āvā (the 140 Firms, with the R2_`v'_`i' value that the code gives). Any hint on how to do this ? (I believe the Matrix function in STATA has to be used, but so far, I have not been able to write the code to create this Matrix in/ from the above code).
Thank you.
Best,
Emmanuel

Comment