Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Home
- /
- Analytics
- /
- Stat Procs
- /
- calculating variance and covariance using a minimum and maximum no. ob...

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 08-06-2018 07:29 PM
(1716 views)

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

--

Paige Miller

Paige Miller

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- Tags:
- PaigeMiller

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

@Batool wrote:

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

Paige Miller

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- Tags:
- PaigeMiller

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

Paige Miller

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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.

- Tags:
- PaigeMiller

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

@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

Paige Miller

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

So please define "macro regression".

--

Paige Miller

Paige Miller

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

thank you Paige Miller. I think I should search for it more.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

I mean a window

**Available on demand!**

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

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.