I looked for an answer but wasn't able to find one, so I hope this is a topic, which hasn't been touched upon yet.
I have a xlsx panel data file from CRSP for monthly stock returns for all companies in the NYSE from 1963 until 2017. Those are the columns:
Month (in DD/MM/YYYY) | Company Code | Company Name | Industry Code | Return
e.g. 31/03/1981 | AAPL | Apple Inc. | 12345 | -0.07512
Now I want to calculate the demeaning returns in an extra column, i.e. Return(Apple,March1981) MINUS Mean-Return(Apple,whole sample period).
I was trying with the scale function, but obviously, it demeans the return for the mean of all returns, not only apple specific. How do I code that it should only take the apple returns into the mean calucations?
Thank you in advance and have a good day!
Edit: deleted the screenshot, better example provided further below.