I have to do following estimation for firm's misvaluation. I have gathered the data to Excel (market value of equity, book value of equity, Net Income and leverage ratio) for all the firms. I know that based on the below formulas I would have to do following: Estimate equation 10 for each industry and year separately. Then average the coefficients from these regressions over time and plug them into equation 11, but I don't know how I should do these in R.

In below picture is the formulas, and the table 2 is the output I would like to achieve.

I would be very grateful for any help, thank you.