# Help Needed: Multivariate Regression Using R

#### Alexinvestments

##### New Member
I am testing the a couple of CAPM based models for my dissertation, and I have a healthy amount of stocks to regress, 5000 according to my last calculations, they’d have to be done as 75 stocks at a time, (in a portfolio). The number makes it an unrealistic task to accomplish manually, I have tried to build on the scripts Ive found here, which were of extreme use, however I lack the skills to make it actually work, I can post a copy of my modified script and if possible I can send you a copy of one of my excel sheets to figure out if that is the root of the problem.
my script, its probably primitive and vulgar. Any help is greatly appreciated.
Attached is a .txt file of the one I currently am using
Hameedalmaa@gmail.com

# Load CSV file into R (tried multiple files, hence the name might not be consistent with the uploaded file)

# Extract Fama-French Factors and Fund Returns
rmrf <- ff_data[,1]
smb <- ff_data[,2]
hml <- ff_data[,3]
rf <- ff_data[,4]
fund1 <- ff_data[,5]
fund2 <- ff_data[,6]
fund3 <- ff_data[,7]
fund4 <- ff_data[,8]
fund5 <- ff_data[,9]
fund6 <- ff_data[,10]
fund7 <- ff_data[,11]
fund8 <- ff_data[,12]
fund9 <- ff_data[,13]
fund10 <- ff_data[,14]
fund11 <- ff_data[,15]
fund12 <- ff_data[,16]
fund13 <- ff_data[,17]
fund14 <- ff_data[,18]
fund15 <- ff_data[,17]
fund16 <- ff_data[,20]
fund17 <- ff_data[,21]
fund18 <- ff_data[,22]
fund19 <- ff_data[,23]
fund20 <- ff_data[,24]
fund21 <- ff_data[,25]
fund22 <- ff_data[,26]
fund23 <- ff_data[,27]
fund24 <- ff_data[,28]
fund25 <- ff_data[,29]
fund26 <- ff_data[,30]
fund27 <- ff_data[,31]
fund28 <- ff_data[,32]
fund29 <- ff_data[,33]
fund30 <- ff_data[,34]
fund31 <- ff_data[,35]
fund32 <- ff_data[,36]
fund33 <- ff_data[,37]
fund34 <- ff_data[,38]
fund35 <- ff_data[,39]
fund36 <- ff_data[,40]
fund37 <- ff_data[,41]
fund38 <- ff_data[,42]
fund39 <- ff_data[,43]
fund40 <- ff_data[,44]
fund41 <- ff_data[,45]
fund42 <- ff_data[,46]
fund43 <- ff_data[,47]
fund44 <- ff_data[,48]
fund45 <- ff_data[,49]
fund46 <- ff_data[,50]
fund47 <- ff_data[,51]
fund48 <- ff_data[,52]
fund49 <- ff_data[,53]
fund50 <- ff_data[,54]
fund51 <- ff_data[,55]
fund52 <- ff_data[,56]
fund53 <- ff_data[,57]
fund54 <- ff_data[,58]
fund55 <- ff_data[,59]
fund56 <- ff_data[,60]
fund57 <- ff_data[,61]
fund58 <- ff_data[,62]
fund59 <- ff_data[,63]
fund60 <- ff_data[,64]
fund61 <- ff_data[,65]
fund62 <- ff_data[,66]
fund63 <- ff_data[,67]
fund64 <- ff_data[,68]
fund65 <- ff_data[,69]
fund66 <- ff_data[,70]
fund67 <- ff_data[,71]
fund68 <- ff_data[,72]
fund69 <- ff_data[,73]
fund70 <- ff_data[,74]
fund71 <- ff_data[,75]
fund72 <- ff_data[,76]
fund73 <- ff_data[,77]

ffregression <- lm(fund1 ~ rmrf + smb + hml)
# Print summary of regression results
print(summary(ffregression))}

ffregression <- lm(fund2 ~ rmrf + smb + hml)
# Print summary of regression results
print(summary(ffregression))}

ffregression <- lm(fund3 ~ rmrf + smb + hml)
# Print summary of regression results
print(summary(ffregression))}

ffregression <- lm(fund4 ~ rmrf + smb + hml)
# Print summary of regression results
print(summary(ffregression))}

ffregression <- lm(fund5 ~ rmrf + smb + hml)
# Print summary of regression results
print(summary(ffregression))}

ffregression <- lm(fund6 ~ rmrf + smb + hml)
# Print summary of regression results
print(summary(ffregression))}

ffregression <- lm(fund7 ~ rmrf + smb + hml)
# Print summary of regression results
print(summary(ffregression))}

ffregression <- lm(fund8 ~ rmrf + smb + hml)
# Print summary of regression results
print(summary(ffregression))}

and so on....