Karl Wig
Karl Wig

Reputation: 65

Dummy variable regression, remove dummy intercept keeping only interaction terms

I try to run a regression with a dummy variable that takes on the value 0 before 2009 and 1 from 2009, to see the impact of the financial crisis.

I do this by adding an extra column called "dummy" with the values as above and then add the dummy variable to the regression. However, I am not interested in a "dummy intercept" but only dummy interaction terms. Still the following regression yields a dummy intercept term, something that I do not explicitly include. Can you help me understand how to exclude it from the regression?

library(lme4)
library(dplyr)
#TEST##
merged_income_test <- merged_income %>%
  mutate(dummy = case_when(
    year > 2008 ~ 1,
    year < 2009 ~ 0
  ))

regression_merged_income_test <- 
  lmList(income_rate ~ interest_rate + lag1 + lag2 +
           dummy * (interest_rate + lag1 + lag2) | firm, 
         merged_income_test, 
         pool = FALSE )

regression_merged_income_test_results <- coef(regression_merged_income_test)

colnames(regression_merged_income_test_results)

[1] "(Intercept)"   "interest_rate"  "lag1"  "lag2" "dummy" "interest_rate:dummy"
[7] "lag1:dummy"      "lag2:dummy"  

Any suggestions on how to remove the intercept "dummy"?

Upvotes: 1

Views: 602

Answers (1)

doubled
doubled

Reputation: 349

Most lm or glm objects understand * in a formula to mean full interaction. So when you add it there, lmList understands dummy*(a + b) as you asking for the following covariates: dummy,a,b,dummy:a,dummy:b. Instead, create a variable defined as newvar = dummy*(a+b), and pass that into the regression. So actually the addition of lag1,lag2 and interest_rate in your lmList is redundant because you're asking for them with *. To illustrate the difference:

require(lme4)
require(data.table)
df = data.table("income_rate" = rnorm(500), 
                "dummy" = rbinom(500, size = 1,prob = .5),
                "interest_rate" = rnorm(500),
                "firm" = rbinom(500, size =1 ,prob =.3),
                "rand" = rbinom(500, size =1 , prob = .2))

df[, new_var := interest_rate*dummy]

lmList(income_rate ~ interest_rate*dummy | firm, df)

Call: lmList(formula = income_rate ~ interest_rate * dummy | firm,      data = df) 
Coefficients:
  (Intercept) interest_rate      dummy interest_rate:dummy
0  0.06110581  -0.005786927 -0.0873395         -0.06646967
1 -0.09507628   0.219900191  0.1439778         -0.20570454


lmList(income_rate ~ new_var | firm, df)
Call: lmList(formula = income_rate ~ new_var | firm, data = df) 
Coefficients:
  (Intercept)     new_var
0  0.01645925 -0.07697772
1 -0.01323612  0.02462004

So should be easy to create the variables you really want to include, and pass them on to lmList.

Upvotes: 1

Related Questions