Hi all,

I just started using STATA, so I don't have much knowledge about it.

My problem is the following:

I have monthly return data for all NYSE stocks for 40 years and have to calculate an individual beta for each stock on a rolling basis.

So for a particular stock and a particular month, I want to regress the returns from the last 5 years on the market returns.

For example stock Apple: beta in January 1980 would be a regression of Apple's returns from January 1975 to December 1979 on the market returns during this period.

The beta for February 1980 would then include date from February 1975 to January 1980.

I know that I have to work with the following command: rolling _b, window(60) saving(betas_`i', replace): regress stockexcessreturn marketexcessreturn

However, I don't know how to apply this command exactly to my problem so that STATA is calculating the beta for each month (is that already included in the rolling command?).

And how can I include that STATA should should just use the returns from a particular stock to calculate its beta and not from other stocks? I think you can't combine the command rolling with by companyID, can you?

I have to include another restriction where I am unsure how to code this: STATA should just calculate the beta for a particular stock if at least 30 return observation were available during the last 60 months (the 5year period).

I know that these are a lot of questions! However, it would make me really happy if someone can help me out...

Thank you very, very much in advance!

I just started using STATA, so I don't have much knowledge about it.

My problem is the following:

I have monthly return data for all NYSE stocks for 40 years and have to calculate an individual beta for each stock on a rolling basis.

So for a particular stock and a particular month, I want to regress the returns from the last 5 years on the market returns.

For example stock Apple: beta in January 1980 would be a regression of Apple's returns from January 1975 to December 1979 on the market returns during this period.

The beta for February 1980 would then include date from February 1975 to January 1980.

I know that I have to work with the following command: rolling _b, window(60) saving(betas_`i', replace): regress stockexcessreturn marketexcessreturn

However, I don't know how to apply this command exactly to my problem so that STATA is calculating the beta for each month (is that already included in the rolling command?).

And how can I include that STATA should should just use the returns from a particular stock to calculate its beta and not from other stocks? I think you can't combine the command rolling with by companyID, can you?

I have to include another restriction where I am unsure how to code this: STATA should just calculate the beta for a particular stock if at least 30 return observation were available during the last 60 months (the 5year period).

I know that these are a lot of questions! However, it would make me really happy if someone can help me out...

Thank you very, very much in advance!

## Comment