Reputation: 37
I have data of various companies' financial information organized by company ticker. I'd like to regress one of the columns' values against the others while keeping the company constant. Is there an easy way to write this out in lm()
notation?
I've tried using:
reg <- lmList(lead2.dDA ~ paudit1 + abs.d.GINDEX + logcapx + logmkvalt +
logmkvalt2|pp, data=reg.df)
where pp
is a vector of company names, but this returns coefficients as though I regressed all the data at once (and did not separate by company name).
Upvotes: 0
Views: 882
Reputation: 650
A convenient and apparently little-known syntax for estimating separate regression coefficients by group in lm()
involves using the nesting operator, /
. In this case it would look like:
reg <- lm(lead2.dDA ~ 0 + pp/(paudit1 + abs.d.GINDEX + logcapx +
logmkvalt + logmkvalt2), data=reg.df)
Make sure that pp
is a factor and not a numeric. Also notice that the overall intercept must be suppressed for this to work; in the new formulation, we have a different "intercept" for each group.
A couple comments:
lmList()
, it should be noted that with lm()
we estimate only a single residual variance across all the groups, whereas lmList()
would estimate separate residual variances for each group.lmList()
syntax that you gave looks like it should have worked. Since you say it didn't, this leads me to expect that really the problem is something else (although it's hard to tell what without a reproducible example), and so it seems likely that the solution I posted will fail for you as well, for the same unknown reasons. If you want more detailed guidance, please provide more information; help us help you.Upvotes: 2