Hi, I am a newbie in R and running a multiple regression for the following data set
Year | ROA | ENV1 | ENV2 |
---|---|---|---|
2012 | 34 | 12 | 32 |
2012 | 42 | 13 | 32 |
2012 | 34 | 16 | 33 |
2013 | 42 | 15 | 33 |
2013 | 34 | 16 | 33 |
2013 | 42 | 16 | 36 |
2014 | 42 | 19 | 36 |
2014 | 34 | 12 | 37 |
2014 | 42 | 19 | 37 |
Then create a table that includes R^2 values from regression.
INDEPENDENT VARIABLES ARE: EN1 AND ENV2
DEPENDENT VARIABLE IS ROA
Indpndnt(/Dpndnt | 2013 | 2014 |
---|---|---|
2012 | R^2 | R^2 |
2013 | R^2 | R^2 |
This is what I wrote, it is working somehow but the problem is I could not create such a table which shows each iterations's R^2 value, I just get final r square.
for(i in 2012:2017)
{
env1 <- ndf$EmissionsScore[ndf$Year==i]
env2 <- ndf$EnvironmentalInnovationScore[ndf$Year==i]
for(j in (i+1):2018)
{
Roa <-ndf$ROATotalAssets_Percent[ndf$Year==j]
db1= as.data.frame(cbind(Roa, env1, env2))
model <- lm (Roa ~ env1+env2, data=db1)
a<- summary(model)$r.squared
}
}
can someone help me with this?