Hello,

I'm new in R. I have a data set with 245 variables and 32 regions or geographic area. I need to obtain the ols model coefficients for each of the 32 areas,

I thought this code was going to work:

y<- c(MMSI_2016$escacu_inf) #dependent variable

x1<- c(MMSI_2016$escacu_pad) #independent variable

x2<- c(MMSI_2016$escacu_mad) #independent variable

edo<- c(MMSI_2016$ubica_geo_enh) #**This variable goes fron 1:32**

predictorlist<- list("x1","x2")

## for (i in edo){

model[i] <- lm(y[i] ~ x1[i] + x2[i])

summary(model_[i])

}

It works but it returns the result for all the data set, not each different region (1:32)

I'll be very grateful if someone can help me.

Thanks