I have a problem with my R code. I would like to run about 100 regressions and perform this process with a loop. I have tried to program the loop myself using help from YouTube and the like, but I am getting nowhere. Therefore, I would like to ask you if you can help me. Specifically, it's about the following: I have a dataset of the 100 companies in the Nasdaq100 and I would like to regress the sales per share with the stock price performance on a quarterly basis. Another problem is that the data set contains these 100 companies and a subset with the respective ticker symbol has to be created for each additional company so that R can access it correctly for each regression.
Here is an excerpt from the code:
Nasdaq_100 = read_xlsx("Nasdaq_100_Sales_Data.xlsx")
#Correlation between quarterly close price and Sales of AMD
AMD <- subset (Nasdaq_100, Nasdaq_100$TickerSymbol=="AMD")
AMD_regression = lm(AMD$Sales ~ AMD$Stockprice_quarterly, data = Nasdaq_100)
summary(AMD_regression)
Can you help me to program this loop for regression analysis? - I would like to analyse all 100 companies.
This is a sample I created to show the structure of my dataset:
TickerSymbol Quarter Sales Stockprice_quarterly
AMD 31.03.2021 $0.45 502.500
AMD 31.12.2020 $1.47 361.100
AMD 30.09.2020 $0.32 280.700
AMD 30.06.2020 $0.13 377.400
AMD 31.03.2020 $0.14 296.900
AMD 31.12.2019 $0.15 274.800
AMD 30.09.2019 $0.11 561.200
AMD 30.06.2019 $0.03 548.650
AMD 31.03.2019 $0.01 509.977
AAPL 31.03.2021 $1.40 359.038
AAPL 31.12.2020 $1.68 358.514
AAPL 30.09.2020 $0.75 357.991
AAPL 30.06.2020 $0.65 357.467
AAPL 31.03.2020 $0.64 356.944
AAPL 31.12.2019 $1.25 356.421
AAPL 30.09.2019 $0.77 355.897
AAPL 30.06.2019 $0.55 355.374
AAPL 31.03.2019 $0.62 354.851
EBAY 31.03.2021 $0.92 325.020
EBAY 31.12.2020 $1.39 324.496
EBAY 30.09.2020 $0.94 323.973
EBAY 30.06.2020 $1.05 323.449
EBAY 31.03.2020 $4.51 322.926
EBAY 31.12.2019 $0.69 322.403
EBAY 30.09.2019 $0.37 321.879
EBAY 30.06.2019 $0.46 321.356
EBAY 31.03.2019 $0.57 320.833
Thanks in advance for any help!