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
PROC CORR will calculate covariances and variances for you. Use the BY statement to have this calculated for each company.
thank you Paige Miller, I know that correlation can provide such information, however, the only thing is to determine the time span between 24 and 60. what I need is a macro with a loop but I do not know how to construct it.
@Batool wrote:
thank you Paige Miller, I know that correlation can provide such information, however, the only thing is to determine the time span between 24 and 60. what I need is a macro with a loop but I do not know how to construct it.
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".
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.
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?
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.
@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?
I mean a macro regression. and Rf is another variable in my data.
So please define "macro regression".
I mean a window
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Lock in the best rate now before the price increases on April 1.
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.