1

I am having a problem setting up a panel data model (Fixed Effects) in R.

Currently I am running the following code:

fe1 <- summary(lm(qnorm(y) ~ factor(Bank) -1  + factor(Country)*x ,data=PDwideHPI))

Each Bank has 6 observations per country. I would expect that the summary output would provide me with a bank-specific intercept and secondly, a country specific coefficient for x. However, the R console returns bank-specific AND country-specific intercepts.

Thus I receive estimates for: Factor(Bank)1 Factor(Bank)2 Factor(Bank)3 Factor(Bank)4 Factor(Country)1 Factor(Country)2 x Factor(Country)1:x Factor(Country)2:x

whereas I expect the following: Factor(Bank)1 Factor(Bank)2 Factor(Bank)3 Factor(Bank)4 x Factor(Country)1:x Factor(Country)2:x

How do I solve this?

smci
  • 32,567
  • 20
  • 113
  • 146
Dave van Brecht
  • 514
  • 4
  • 16
  • 1
    Making your example [reproducible](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) would go a long way towards making it easier to help you. If you include sample data, it's easier to see what's going on. Perhaps you want `factor(Country):x` rather than `factor(Country)*x` in your formula. The former includes the non-interaction terms as well. – MrFlick Dec 22 '14 at 21:16
  • Yes will do the next time! Your solution works perfectly by the way, that was what I was looking for. Thank you very much! – Dave van Brecht Dec 22 '14 at 21:24
  • To make your code clearer and more legible, convert `Bank` and `Country` to factors when/immediately after you read them in. e.g. use `as.factor()` or `read.csv(... colClasses)`. Then your formula terms will simply be called `Bank`, `Country` without the `Factor(...)` – smci Aug 23 '19 at 08:47

1 Answers1

1

With the default R formula syntax the * not only includes the interaction terms, but also includes the individual terms. If you just want the interaction term, then you the : operator. So you in your case, you want

fe1 <- summary(lm(qnorm(y) ~ factor(Bank) -1  + factor(Country):x ,data=PDwideHPI))
MrFlick
  • 195,160
  • 17
  • 277
  • 295