Home > Mobile >  How to run a loop regression in r
How to run a loop regression in r

Time:10-11

I am want to run a loop regression for fund1 till fund10 based on the the LIQ-factor. I want to do this regression:

lm(fund1S~ LIQ, data = Merge_Liq_Size)

but for all of the funds simultaneously.

I have attached some picture of the dataset to show you the setup. The dataset has 479 observation/rows. Can anyoune help me to sturcture a code? Sorry if this question is phrased in a wrong way.

dataset

dataset

CodePudding user response:

Perhaps this is what you are looking for:

my_models <- lapply(paste0("fund", 1:10, "S ~ LIQ"), function(x) lm(as.formula(x), data = Merge_Liq_Size))

You can access each model by my_models[[1]] to my_models[[10]].

  •  Tags:  
  • r
  • Related