Question: R coding library(RSQLite) library(foreign) setwd(xxx) # reset the working directory to the folder which stores the data sets msf

R coding

library(RSQLite)

library(foreign)

setwd("xxx") # reset the working directory to the folder which stores the data sets

msf <- read.dta("msf.dta")

con <- dbConnect(SQLite(),":memory:")

dbWriteTable(con,"msf",msf,overwrite=TRUE)

command <- "SELECT tsymbol,ret

FROM msf

WHERE date BETWEEN '2005-01-01' AND '2013-12-31'

AND tsymbol IN ('stock1', 'stock2', 'SPY')"

result<-dbGetQuery(con,command)

y1<-result[result$tsymbol=='stock1',]$ret

y2<-result[result$tsymbol=='stock2',]$ret

x<-result[result$tsymbol=='SPY',]$ret

(I can't post the data, please use your own data or pick any stock name you want, I need the code that can be apply to this question to study)

1. Choose any two stocks in the database "msf.dta". Change the code above to get the stock ret data and S&P index ret.

2. Estimate each company's abnormal return and beta by CAPM model for the full sample.

3. For each company, randomly select 80% of observations to estimate abnormal returns and beta in the step 2. Repeat the iteration 20 times. Print the abnormal return and beta estimations for 20 samples as a matrix.

4. Compute the average of the abnormal return and beta estimations over 20 samples.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!