BookmarkSubscribeRSS Feed
Batool
Fluorite | Level 6

Hello everyone,

 

I need to calculate stock beta using the formula: beta= covariance (Rm,Ri) / variance (Rm). I need to calculate beta using 24-60 observations. So, I need to create a new column that has the betas for each date-company calculated depending on the last 24-60 observations (no problem if it started from the current observation). I can create lags but I want more practical solution please giving that my data have several companies. here is how my data looks:

 

date                 company       Ri      Rm

Jan-2001              A                      3%       3.5%

Feb-2001              A                      3.2%     3.9%

Mar-2001              A                      2.7%     3.1%

.

.

.

Jan-2001              B                      3.9%       3.5%

Feb-2001              B                      4.1%     3.9%

Mar-2001              B                      3.3%     3.1%

.

.

 

your help is appreciated.

thank you in advance 

11 REPLIES 11
PaigeMiller
Diamond | Level 26

PROC CORR will calculate covariances and variances for you. Use the BY statement to have this calculated for each company.

--
Paige Miller
Batool
Fluorite | Level 6

thank you Paige Miller

PaigeMiller
Diamond | Level 26

@Batool wrote:

thank you Paige Miller


You do NOT need a macro.

 

Explain further, give a concrete example of what you mean by "determine the time span between 24 and 60".

--
Paige Miller
Batool
Fluorite | Level 6

i need 24-60 observations to calculate the  variance and covariance. so the minimum number of observations used to calculate the variance and covariance should be 24 and the maximum is 60. 

PaigeMiller
Diamond | Level 26

So if there are less than 24 observations, then you don't calculate the variance and covariance? Is that correct?

 

If there are more than 60 observations, then what do you do?

--
Paige Miller
Batool
Fluorite | Level 6

that is right. if there is more than 60 i want to use the last 60 only. 

 

I was searching and I think I found what i need (code attached),

 

can you please help me making it a roll regression so instead of calculating the beta using cov/var, i want to calculate it as the estimated coefficient from the model: (Ri-Rf)= beta (Ri-Rm) using the same window.

PaigeMiller
Diamond | Level 26

@Batool wrote:

that is right. if there is more than 60 i want to use the last 60 only. 

 

I was searching and I think I found what i need (code attached),

 

can you please help me making it a roll regression so instead of calculating the beta using cov/var, i want to calculate it as the estimated coefficient from the model: (Ri-Rf)= beta (Ri-Rm) using the same window.


So if I am interpreting this properly, you no longer need help with the original problem? Is that correct?

 

What is a "roll regression"? What is Rf?

--
Paige Miller
Batool
Fluorite | Level 6

I mean a macro regression. and Rf is another variable in my data.

PaigeMiller
Diamond | Level 26

So please define "macro regression".

--
Paige Miller
Batool
Fluorite | Level 6
thank you Paige Miller. I think I should search for it more.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 11 replies
  • 1766 views
  • 0 likes
  • 2 in conversation