r - regression analysis (by year and firm) -


sorry, i'm awkward in english , r. hope understand words.

my data set follows.

year, week,       a017670,   a030200,  a032640,   market,  ind.20  2000, 2000-01,       0.02,    -0.001,    0.005,    0.007,   0.004,  2000, 2000-02  ...  2000, 2000-52  2001, 2001-01  ...  2014, 2014-52 

i want extract adjusted r-squared , sse regression models.

and want write (save) adjusted r-squared sse.

my models follows:

lm(a017670~market+ind.20, subset=(year=2000))   lm(a017670~market+ind.20, subset=(year=2001))   ...   lm(a017670~market+ind.20, subset=(year=2014))    lm(a030200~market+ind.20, subset=(year=2000))   lm(a030200~market+ind.20, subset=(year=2001))   ...  lm(a030200~market+ind.20, subset=(year=2014))    lm(a032640~market+ind.20, subset=(year=2000))   lm(a032640~market+ind.20, subset=(year=2001))   ...  lm(a032640~market+ind.20, subset=(year=2014))  

i need adjusted r-squared , sse each model.

my data 15 years data of 700 companies(a017670, a030200, a032640, ...........)

so, have run 10,500 times regression.

it boring.

also, ind.20 means industrial yield. industrial average 30 branches.(ind20, ind21, ind22, .............ind49)

thank you.

create combinations of companies , years:

models <- setnames(   expand.grid(     names(df1)[grep("^a",names(df1))],      unique(df1$year), stringsasfactors = f),    c("company", "year")) 

call lm on every combination:

do.call( rbind,    lapply( seq_len(nrow(models)), fun = function(i) {     formula1 <- sprintf("%s ~ market + ind.20", models$company[i])     fit1 <- lm( formula = formula1, data = df1[ df1$year == models$year[i], ]  )     sfit <- summary(fit1)     data.frame(        year = models$year[i],       company = models$company[i],       adjrsq = sfit$adj.r.squared,        sse = deviance(fit1) )   }) ) 

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -