I am trying to perform a logistic regression with the lm()
function in R.
My model is:
lm(xrd ~ VariableA*Post, data = DatasetXRD)
this is a difference-in-differences model, the R code is based on Oscar Torres-Reyna's Differences-in-Differences (using R).
Some general info regarding my data:
I have applied pseudo adoption in my model (in the Post
variable). So I state that some companies will apply a certain rule after a year even though they do not apply it. However VariableA
will remain 0 (no application of the rule) for these companies. This will result into a value of 1 for companies that do apply it, and a value of 0 for companies that do not apply it (in that specific year, it could be that they will apply it in a later year).
VariableA
and Post are both dummy variables (value= 0 or 1).
The third row of text in my lm
table is showing NA
s.
Coefficients: (1 not defined because of singularities)
Estimate Std. Error t value Pr(>|t|)
(Intercept) 43286 4865 8.897 <2e-16 ***
VariableA 4900 6362 0.770 0.441
Post -4904 6849 -0.716 0.474
VariableA:Post NA NA NA NA
As shown in the table, this is because of singularities. After a google search I have found that this is because of collinearity.
I have run the cor()
function trying to see if this would lead to a perfect correlation, since that would prove that I have collinearity issues, but I don't find the results convincing.
cor(Dataset$VariableA, Dataset$Post)
This leads to the following output: 0.5890362. Correlation is not 1, so that does not mean that my independent variables are not perfectly collinear (in my own words: they do not perfectly explain each other?)
I have also ran:
alias(didreg, complete = TRUE, partial = FALSE,
partial.pattern = FALSE)
I have read in a previous question that was similar that this will show collinearity, however I will admit that I do not fully understand how to interpret the output of the table below.
Model :
xrd ~ VariableA * Post
Complete :
(Intercept) VariableA Post
VariableA:Post 0 1 0
Why I am having collinearity problems?
glm()
rather thanlm()
if you really want logistic regression. For the stats part, collinearity just means that one variable can be written as a linear combination of others:z
might not be perfectly correlated withx
ory
, but you have collinearity if you can finda
andb
so thatz
is perfectly correlated withax + by
(or similarly with more than 2 in the linear combination). $\endgroup$